# markdown-it-named-headers

> Headers have name attributes for markdown-it.

Latest version **0.0.4** (published 2015-11-29) · Unlicense license · 0 weekly downloads

## Install

```sh
npm install markdown-it-named-headers
pnpm add markdown-it-named-headers
yarn add markdown-it-named-headers
bun add markdown-it-named-headers
```

## 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.0.4 |
| Published | 2015-11-29 |
| First published | 2015-03-26 |
| Weekly downloads | 0 |
| License | Unlicense |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 13 |
| Author | Jason Brackins |
| Maintainers | leff |
| Keywords | markdown-it-plugin |

## Links

- npm: https://www.npmjs.com/package/markdown-it-named-headers
- Repository: https://github.com/leff/markdown-it-named-headers
- Issues: https://github.com/leff/markdown-it-named-headers/issues
- npm.io page: https://npm.io/package/markdown-it-named-headers

## Dependencies (1)

- [string](https://npm.io/package/string.md) ^3.0.1

## Alternatives

- [@mdxeditor/editor](https://npm.io/package/@mdxeditor/editor.md) — 962.4K weekly downloads
- [mmdb-lib](https://npm.io/package/mmdb-lib.md) — 680.9K weekly downloads
- [playcanvas](https://npm.io/package/playcanvas.md) — 36.2K weekly downloads
- [@glw907/cairn-cms](https://npm.io/package/@glw907/cairn-cms.md) — 967 weekly downloads
- [markdown-to-confluence](https://npm.io/package/markdown-to-confluence.md) — 103 weekly downloads

## Recent versions

- 0.0.4 (latest) — 2015-11-29
- 0.0.3 — 2015-03-29
- 0.0.2 — 2015-03-26

## README

# Markdown-it Named Headers

A plugin for [markdown-it](https://github.com/markdown-it/markdown-it). Makes header elments have identifer attributes.

```
# Example Header   -->   <h1 id="example-header">Example</h1>
```

By default, it uses [string.js](http://stringjs.com/)'s [slugify](http://stringjs.com/#methods/slugify) to translate header text into a url safe name. You can override this. See _Options_.

Cribbed heavily from https://github.com/valeriangalliat/markdown-it-anchor

## Install

```
npm install --save-dev markdown-it-named-headers
```

## Usage

Use with plain old node:

```js
var md   = require('markdown-it'),
    mdnh = require('markdown-it-named-headers');

md.use(mdnh, options);
```

Use as part of a Gulp workflow: (Note: You don't need to require named-headers in your gulpfile. gulp-markdown-it takes care of that for you).

```js
var gulp = require('gulp'),
    md = require('gulp-markdown-it');
gulp.task('md', [], function() {
    return gulp.src( '**/*.md' )
        .pipe(md({
            plugins: ['markdown-it-named-headers']
        }))
        .pipe(gulp.dest('dist'));
});
```


### Options


#### Slugify

```js
{
   slugify: my_slug_function
}
```

If string.js's slugify doesn't fit your needs, you can simply pass in your own slugify function. Basically, the API is: accept any string, return a string suitable for a name attribute. Example:

```js
function slugify(input_string) {
    var output_string = my_transform_logic(input_string);
    return output_string;
}
```

Since we use IDs, we should avoid duplicating them. A second parameter is passed. It is an empty object that will persist across a single call to render. In other words, you can use it to maintain a hash of used_headers per page.

The default slugify method looks something like this:

```js
function slugify(input_string, used_headers) {
  var slug = string(input_string).slugify().toString();
  if( used_headers[slug] ) {
    used_headers[slug]++;
    slug += used_headers[slug];
  } else {
    used_headers[slug] += '-' + 1;
  }
  return slug;
}
```

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