# markdown-it-title

> Extract title during markdown-it parsing.

Latest version **4.0.0** (published 2021-06-15) · Unlicense license · 0 weekly downloads

## Install

```sh
npm install markdown-it-title
pnpm add markdown-it-title
yarn add markdown-it-title
bun add markdown-it-title
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2021-06-15 |
| First published | 2015-03-17 |
| Weekly downloads | 0 |
| License | Unlicense |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 14 |
| Author | Valérian Galliat |
| Maintainers | valeriangalliat |
| Keywords | markdown-it-plugin |

## Links

- npm: https://www.npmjs.com/package/markdown-it-title
- Repository: https://github.com/valeriangalliat/markdown-it-title
- Issues: https://github.com/valeriangalliat/markdown-it-title/issues
- npm.io page: https://npm.io/package/markdown-it-title

## 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

- 4.0.0 (latest) — 2021-06-15
- 3.0.0 — 2020-03-29
- 2.0.0 — 2020-01-17
- 1.0.4 — 2015-08-13
- 1.0.3 — 2015-05-25
- 1.0.2 — 2015-03-17
- 1.0.1 — 2015-03-17
- 1.0.0 — 2015-03-17

## README

# markdown-it-title [![npm version](http://img.shields.io/npm/v/markdown-it-title.svg?style=flat-square)](https://www.npmjs.org/package/markdown-it-title)

> Extract title during [markdown-it] parsing.

[markdown-it]: https://github.com/markdown-it/markdown-it

## Overview

This plugin is useful if you want to write plain markdown files, e.g.
without YAML front matter, and want to extract the document title to
populate a HTML `<title>` tag, Open Graph and so on.

Additionally, markdown-it-title supports extracting the contents of the
first paragraphs if you want to use them as meta description, post
excerpt and so forth.

## Usage

```js
const opts = {
  level: 1,
  excerpt: 2
}

const md = require('markdown-it')()
  .use(require('markdown-it-title'), opts)

const env = {}

md.render(`# [Hello](#hello), *world*!

This is the **first** paragraph.

## Hi, I'm a title

Another one.

And another one.
`, env)

env.title === 'Hello, world!'
env.excerpt[0] === 'This is the first paragraph.'
env.excerpt[1] === 'Another one.'
```

The `opts` object can contain:

| Name      | Description                                                                                    | Default |
|-----------|------------------------------------------------------------------------------------------------|---------|
| `level`   | Heading level to look for the title. Use 0 to take whichever heading comes first.              | 1       |
| `excerpt` | Number of paragraphs to extract from the beginning of the document to be used as page excerpt. | 0       |

Setting `level` to 1 (the default) will extract the contents of the
first `<h1>` to `env.title`. If set to 0, markdown-it-title will take
the first heading it encounters.

Also, the first `excerpt` paragraphs will be extracted in the
`env.excerpt` array (not enabled by default).

Both title and excerpt text won't include any markup.

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