0.0.1 • Published 5 years ago

@embers-pw/markdown v0.0.1

Weekly downloads
2
License
-
Repository
-
Last release
5 years ago

Markdown

A custom, incomplete, untested and extensible markdown parser

Installation

With npm:

npm install @embers-pw/markdown

With yarn:

yarn add @embers-pw/markdown

Usage

import {format} from "@embers-pw/markdown";

console.log("# Hello, *world!*");
// "<h1>Hello, <em>world!</em></h1>"

How it works

Markdown consists of a tokenizer and a parser for both block and inline rules.

Tokenzers scan the input text, if they find a pattern matching a token definition, they convert it into a Token. The result of a tokenizer run is an array of Tokens for the parser to consume. If there isn't a definition, it will default to a text token.

Parsers receive the Token stream and produce a tree of Nodes resembling an Ast based on the provided rules. If the rule is recursive, the parser will run recursively on the Node contents. If no rule matches, it will default to a text node.

Finally, the renderer will take an Ast and run a renderer function for each Node. The renderer functions receive a next function that can be use to recursively render the Node.

When running format the tokenizers and parsers are ran in the order:

  • Block Tokenizer
  • Block Parser
    • Inline tokenizer?*
    • Inline parser?*
  • Renderer

* Inline tokenizer and parser are ran if the block is recursive.

0.0.1

5 years ago

1.0.0

5 years ago