Socket
Socket
Sign inDemoInstall

md-hierarchical-parser

Package Overview
Dependencies
4
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    md-hierarchical-parser

parser which generates parsed hierarchical structure of markdown


Version published
Weekly downloads
2
decreased by-66.67%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Markdown Hierarchical Parser

MDAST well describes the syntax and structure of markdown, but it has a single problem - there are no hierarchical relations between headings. It is obvious the h2 following h1 is the children of h1, but MDAST treats them as the same heading and just gives depth info as an attribute.

This parser parses markdown and generates JSON structure with hierarchical info. The parser is implemented based on streamich/md-mdast.

Install

npm i md-hierarchical-parser

Example

let mdParser = require('md-hierarchical-parser')
await mdParser.run("path/to/markdown.md", true, true)

Description

run(path, isHierarchy = true, isString=false)

Reads markdown file in the path and generates json object representing the structure.

  • path: denotes the path to the markdown
  • isHierarchy: iftrue, returns JSON with hierarchy structure. Else, return vanilla MDAST. Default value=true
  • isString: if false, returns JSON object. Else, returns stringified value. Default value=false

Example

.md file:

## Header 2

paragraph 1

### Header 3

paragraph 2

#### Header 4

- first
- second
- third

paragraph 3

##### Header 5

`print("hello world")`

## Header 2

will be converted to JSON which follows below structure:

    ├── heading
    │   ├── paragraph
    │   ├── heading
    │   │   ├── paragraph
    │   │   ├── heading
    │   │   │   ├── list
    │   │   │   ├── paragraph
    │   │   │   ├── heading
    │   │   │   │   ├── code
    ├── heading
    

Keywords

FAQs

Last updated on 14 Aug 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc