# md-json-parser

> Markdown To JSON Parsing Library With Components Support.

Latest version **1.0.5-rc.2** (published 2023-11-13) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install md-json-parser
pnpm add md-json-parser
yarn add md-json-parser
bun add md-json-parser
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5-rc.2 |
| Published | 2023-11-13 |
| First published | 2022-07-20 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 6 |
| Unpacked size | 26.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Priyanshu Belwal |
| Maintainers | belwalpb |
| Keywords | markdown-parser, markdown-json-converter, md-parser, md-json-converter, markdown-parser-unified, markdown-parser-remark |

## Links

- npm: https://www.npmjs.com/package/md-json-parser
- Repository: https://github.com/belwalpb/md-json-parser
- Homepage: https://github.com/belwalpb/md-json-parser.git/#readme
- Issues: https://github.com/belwalpb/md-json-parser/issues
- npm.io page: https://npm.io/package/md-json-parser

## Dependencies (6)

- [unified](https://npm.io/package/unified.md) ^11.0.4
- [remark-gfm](https://npm.io/package/remark-gfm.md) ^3.0.1
- [remark-mdc](https://npm.io/package/remark-mdc.md) ^2.1.0
- [remark-emoji](https://npm.io/package/remark-emoji.md) ^4.0.1
- [remark-parse](https://npm.io/package/remark-parse.md) ^10.0.2
- [remark-squeeze-paragraphs](https://npm.io/package/remark-squeeze-paragraphs.md) ^6.0.0

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

- 1.0.5-rc.2 (latest) — 2023-11-13
- 1.0.5-rc.1 — 2023-11-13
- 1.0.4 — 2023-10-21
- 1.0.3 — 2023-10-21
- 1.0.2 — 2023-06-23
- 1.0.1 — 2022-07-20

## README

# md-json-parser

A markdown parsing library build on the top of [unified](https://www.npmjs.com/package/unified).

## Feature Highlights

*   [x] **Markdown to JSON Tree Conversion**
*   [x] **Fully Extentible (Using Remark Plugins)**
*   [x] **Frontmatter Support**
*   [x] **TODO: Table of Content (TOC) Support With Options**

## What is Markdown Parser?

The package is a Fully featured, extentible markdown to JSON Parser, using Syntax Trees. In the input, a markdown string can be given to it with optional plugins and extentions.

## Installation

This package is [ESM Only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c). It can be installed via NPM:
```sh
npm install md-json-parser
```

## Usage
The Package can be imported like:

### Markdown to JSON Parser:
```js
import { MdJsonParserService } from 'md-json-parser'

let markdown = `---
file: abc.txt
creationDate: 2022-02-12
---
  
# Heading-1
## Heading-2`

// Optionally you can pass the changed configuration via the constructor parameters.
const mdJsonParserService= new MdJsonParserService()

const {data, body} = mdJsonParserService.parseMarkdown(markdown)
```

<details>
<summary>Show Output:</summary>

```json
{
    "data": {
        "file": "abc.txt",
        "creationDate": "2022-02-12T00:00:00.000Z"
    },
    "body": {
        "type": "root",
        "children": [
            {
                "type": "heading",
                "depth": 1,
                "children": [
                    {
                        "type": "text",
                        "value": "Heading-1",
                        "position": {
                            "start": {
                                "line": 3,
                                "column": 3,
                                "offset": 8
                            },
                            "end": {
                                "line": 3,
                                "column": 12,
                                "offset": 17
                            }
                        }
                    }
                ],
                "position": {
                    "start": {
                        "line": 3,
                        "column": 1,
                        "offset": 6
                    },
                    "end": {
                        "line": 3,
                        "column": 12,
                        "offset": 17
                    }
                }
            },
            {
                "type": "heading",
                "depth": 2,
                "children": [
                    {
                        "type": "text",
                        "value": "Heading-2",
                        "position": {
                            "start": {
                                "line": 4,
                                "column": 4,
                                "offset": 22
                            },
                            "end": {
                                "line": 4,
                                "column": 13,
                                "offset": 31
                            }
                        }
                    }
                ],
                "position": {
                    "start": {
                        "line": 4,
                        "column": 1,
                        "offset": 19
                    },
                    "end": {
                        "line": 4,
                        "column": 13,
                        "offset": 31
                    }
                }
            }
        ],
        "position": {
            "start": {
                "line": 1,
                "column": 1,
                "offset": 0
            },
            "end": {
                "line": 4,
                "column": 13,
                "offset": 31
            }
        }
    }
}
```

</details>

### Markdown Options:
```js
{
    toc : {
        active: true // To Generate TOC or not for the provided markdown.
        depth: 2 // From h2 onwards, max tags which are supported.
        searchDepth: 3 // Max Depth In which It should search for TOC Items in JSON Tree.
    },
    remarkPlugins : [
        // Array of Remark Plugins For Customization. For More Info Refer: https://github.com/remarkjs/remark/blob/main/doc/plugins.md#create-plugins
    ]
}
```

## Upcoming/TODO Tasks:

*   [ ] **Removal of position property from nodes**
*   [ ] **TOC Support**
*   [ ] **Custom Component Types Addition**
*   [ ] **Other general optimization during node parsing**

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