Markdown to JS AST parser.
npm i happy-mark --save
cat README.md | happy-markFor full loop use (format detected automatically):
cat README.md | happy-mark | happy-markHappy Mark converts Markdown to JavaScript this way:
| Markdown | Becomes |
|---|---|
# Heading |
heading(1, 'Heading') |
Some text |
paragraph('Some text') |
**bold** |
paragraph(bold('bold')) |
- one\n- two |
ul(li('one'), li('two')) |
> quote |
blockquote(paragraph('quote')) |
 |
paragraph(image('alt', 'url')) |
[text](url) |
link('text', 'url') |
import {
convertMarkdownToJs,
convertJsToMarkdown,
} from 'happy-mark';
import {montag} from 'montag';
const source = montag`
# hello
Hello world
\`\`\`js
const a = 3;
\`\`\`
`;
const js = convertMarkdownToJs(source);
// returns
`
[
header(1, 'hello'),
paragraph('Hello world'),
codeblock('js', 'const a = 3;'),
];
`;
convertJsToMarkdown(js);
// returns
`
# hello
Hello world
\`\`\`js
const a = 3;
\`\`\`
`;MIT