# metalsmith-jquery

> A Metalsmith plugin to manipulate HTML via jQuery syntax

Latest version **0.2.2** (published 2016-07-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install metalsmith-jquery
pnpm add metalsmith-jquery
yarn add metalsmith-jquery
bun add metalsmith-jquery
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.2 |
| Published | 2016-07-05 |
| First published | 2015-04-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 13 |
| Author | Manheim |
| Maintainers | manheim |
| Keywords | metalsmith, jquery |

## Links

- npm: https://www.npmjs.com/package/metalsmith-jquery
- Repository: https://github.com/manheim/metalsmith-jquery
- Issues: https://github.com/manheim/metalsmith-jquery/issues
- npm.io page: https://npm.io/package/metalsmith-jquery

## Dependencies (3)

- [debug](https://npm.io/package/debug.md) ^2.1.3
- [cheerio](https://npm.io/package/cheerio.md) ^0.20.0
- [minimatch](https://npm.io/package/minimatch.md) ^3.0.0

## Alternatives

- [gamedig](https://npm.io/package/gamedig.md) — 29.3K weekly downloads
- [join-monster](https://npm.io/package/join-monster.md) — 12.8K weekly downloads
- [masked](https://npm.io/package/masked.md) — 5.5K weekly downloads
- [@comunica/actor-query-process-explain-logical](https://npm.io/package/@comunica/actor-query-process-explain-logical.md) — 4.7K weekly downloads
- [@veracity/vui](https://npm.io/package/@veracity/vui.md) — 4.6K weekly downloads

## Recent versions

- 0.2.2 (latest) — 2016-07-05
- 0.1.2 — 2016-01-13
- 0.0.2 — 2015-06-02
- 0.0.1 — 2015-04-23

## README

# metalsmith-jquery

[![Build Status](https://travis-ci.org/manheim/metalsmith-jquery.svg?branch=master)](https://travis-ci.org/manheim/metalsmith-jquery)
[![Code Climate](https://codeclimate.com/github/manheim/metalsmith-jquery/badges/gpa.svg)](https://codeclimate.com/github/manheim/metalsmith-jquery)
[![Dependency Status](https://www.versioneye.com/user/projects/5539230b1d2989f7ee000002/badge.svg?style=flat)](https://www.versioneye.com/user/projects/5539230b1d2989f7ee000002)

A [Metalsmith](https://github.com/segmentio/metalsmith) plugin to manipulate HTML via jQuery syntax.

## Features

Leverages [Cheerio](https://github.com/cheeriojs/cheerio) to support a logical subset of jQuery syntax, allowing you to manipulate the HTML generated from [metalsmith-markdown](https://github.com/segmentio/metalsmith-markdown) -- or any other plugin!


## Installation

    $ npm install metalsmith-jquery

## Usage

When your markdown is converted to HTML, it doesn't contain any CSS information.  Use this to add styles to your markdown-generated HTML:

```js
var jquery = require('metalsmith-jquery');

Metalsmith(__dirname)
    .use(markdown())
    .use(jquery(function($) {
        $('h2').addClass('welcome');
    }))
    .use(templates('handlebars'))
    .build(function(err) {
        if (err) throw err;
    });
```

For example, if you're using a Bootstrap template, you may want your Markdown-rendered tables to contain the Bootstrap table CSS classes:

```js
var jquery = require('metalsmith-jquery');

Metalsmith(__dirname)
    .use(markdown())
    .use(jquery(function($) {
        $('table').addClass('table table-bordered');
    }))
    .use(templates('handlebars'))
    .build(function(err) {
        if (err) throw err;
    });
```

If you don't want to process every file, you can include a pattern of files to process:

```js
var jquery = require('metalsmith-jquery');

Metalsmith(__dirname)
    .use(markdown())
    .use(jquery('**/*.html', function($) {
        $('table').addClass('table table-bordered');
    }))
    .use(templates('handlebars'))
    .build(function(err) {
        if (err) throw err;
    });
```

If you want to add specific options to how Cherio should manipulate the generated HTML

```js
var jquery = require('metalsmith-jquery');

Metalsmith(__dirname)
    .use(markdown())
    .use(jquery('**/*.html', function($, {decodeEntities: false}) {
        $('#content').append("<p>моя бабушка старая</p>"); // cyrillic characters wont be HTML-encoded
    }))
    .use(templates('handlebars'))
    .build(function(err) {
        if (err) throw err;
    });
```

Inside your callback, you can access the metalsmith-metadata, and metalsmith filename

```js
    .use(jquery(function($, filename, files, metalsmith) {
        var title = $('h1').first().text();
        if (title)
            files[filename].title = title;
    }))
```

You can also store the javascript in a separate file, which is especially useful if you're managing your Metalsmith configuration in a JSON file:

```json
{
    "plugins": {
        "metalsmith-markdown": {},
        "metalsmith-jquery": "fixit.js"
    }
}
```
... where "fixit.js" is a Javascript file in the node.js module format:

```js
module.exports = function($) {

    $('h2').addClass('welcome');
    $('table').addClass('table table-bordered');

}
```
... and the path is relative to the current working directory.

See the tests for more examples.

Where do we use this?  On our [developer portal](http://developer.manheim.com)!

---
_Source: https://npm.io/package/metalsmith-jquery · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
