# markdown-to-ast

> Parse Markdown to AST with location info.

Latest version **6.0.3** (published 2018-01-12) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install markdown-to-ast
pnpm add markdown-to-ast
yarn add markdown-to-ast
bun add markdown-to-ast
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 6.0.3 |
| Published | 2018-01-12 |
| First published | 2015-01-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3181 |
| Author | azu |
| Maintainers | azu |

## Links

- npm: https://www.npmjs.com/package/markdown-to-ast
- Repository: https://github.com/textlint/textlint
- Homepage: https://github.com/textlint/textlint/tree/master/packages/markdown-to-ast/
- Issues: https://github.com/textlint/textlint/issues
- npm.io page: https://npm.io/package/markdown-to-ast

## Dependencies (5)

- [debug](https://npm.io/package/debug.md) ^2.1.3
- [remark](https://npm.io/package/remark.md) ^7.0.1
- [traverse](https://npm.io/package/traverse.md) ^0.6.6
- [structured-source](https://npm.io/package/structured-source.md) ^3.0.2
- [@textlint/ast-node-types](https://npm.io/package/@textlint/ast-node-types.md) ^4.0.0

## Recent versions

- 6.0.3 (latest) — 2018-01-12
- 6.0.0-next.0 (next) — 2017-12-15
- 4.1.0-alpha.6a53d00c (canary) — 2017-10-24
- 6.0.2 — 2017-12-31
- 6.0.1 — 2017-12-25
- 6.0.0 — 2017-12-18
- 5.0.0 — 2017-10-28
- 5.0.0-beta.0 — 2017-10-27
- 4.0.0 — 2017-05-06
- 3.4.0 — 2016-06-14
- 3.2.3 — 2016-02-18
- 3.2.1 — 2015-12-29
- 3.2.0 — 2015-12-29
- 3.1.1 — 2015-10-29
- 3.0.7 — 2015-08-22
- … 14 more at https://npm.io/package/markdown-to-ast/versions

## README

# markdown-to-ast

Parse Markdown to AST with location info.

This library is not parser itself, it dependent on [wooorm/remark](https://github.com/wooorm/remark).

> Markdown -> remark -> markdown-to-ast -> `TxtNode`s

The AST consists of `TxtNode`s.
A `TxtNode` of the AST has following properties:

- `loc` - Nodes have line and column-based location info.
- `range` - Nodes have an index-based location range (array).
- `raw` - Node have a `raw` text.
- `value` - Node have a `value` of text.

The interface are defined in [textlint/txtnode.md](https://github.com/textlint/textlint/blob/master/docs/txtnode.md "textlint/txtnode.md at master · textlint/textlint")

This library is a part of [textlint/textlint](https://github.com/textlint/textlint "textlint/textlint").

**If you need to markdown parser, please use [wooorm/remark](https://github.com/wooorm/remark) directly.**

## DEMO

[![screenshot](http://monosnap.com/image/0fqi1UF7yOv89nxJPaDWtvyqERaM49.png)](http://textlint.github.io/markdown-to-ast/example/)

[Online Parsing Demo](http://textlint.github.io/markdown-to-ast/example/) provide markdown to AST on-the-fly.

## Installation

```
npm install markdown-to-ast
```

## Usage

```sh
var parse = require("markdown-to-ast").parse;
var markdown = "It's a *text*";
var AST = parse(markdown);
/*
{
    "type": "Document",
    "children": [
        {
            "type": "Paragraph",
            "children": [
                {
                    "type": "Str",
                    "value": "It's a ",
                    "loc": {
                        "start": {
                            "line": 1,
                            "column": 0
                        },
                        "end": {
                            "line": 1,
                            "column": 7
                        }
                    },
                    "range": [
                        0,
                        7
                    ],
                    "raw": "It's a "
                },
                {
                    "type": "Emphasis",
                    "children": [
                        {
                            "type": "Str",
                            "value": "text",
                            "loc": {
                                "start": {
                                    "line": 1,
                                    "column": 8
                                },
                                "end": {
                                    "line": 1,
                                    "column": 12
                                }
                            },
                            "range": [
                                8,
                                12
                            ],
                            "raw": "text"
                        }
                    ],
                    "loc": {
                        "start": {
                            "line": 1,
                            "column": 7
                        },
                        "end": {
                            "line": 1,
                            "column": 13
                        }
                    },
                    "range": [
                        7,
                        13
                    ],
                    "raw": "*text*"
                }
            ],
            "loc": {
                "start": {
                    "line": 1,
                    "column": 0
                },
                "end": {
                    "line": 1,
                    "column": 13
                }
            },
            "range": [
                0,
                13
            ],
            "raw": "It's a *text*"
        }
    ],
    "loc": {
        "start": {
            "line": 1,
            "column": 0
        },
        "end": {
            "line": 1,
            "column": 13
        }
    },
    "range": [
        0,
        13
    ],
    "raw": "It's a *text*"
}
*/
```

If you want to know real use-case, please see [textlint/textlint](https://github.com/textlint/textlint "textlint/textlint").

## Tests

```
npm test
```

### Create fixtures

See [tools/](tools/) directory.

## Contributing

1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request :D

## License

MIT

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