如何使用节点将具有替代语法的 markdown 解析为 HTML?

How to parse markdown with alternative syntax into HTML with node?

我是这样用markdown的

const markdown = require("markdown-it")("default", {
    html: true,
    linkify: true,
    typographer: true
});
const htmlText = markdown.render(textFileContent);

在我做

之前它工作正常
#Big title

##Title

#Small title

包装成 <p> 而不是 <h1> <h2> 。请注意,这适用于 Github。等等

但这行得通

Big title
---------

Title
=======

无法更改降价。用户希望它像在 GitHub 和 Whosebug 中那样被解析。

像所有遵循 CommonMark spec 的实现一样,markdown-it 需要 ATX-style header 指示符和标题文本之间的 space。

这应该有效:

# Big title

## Title

# Small title

我相信这也使源代码更易于阅读,即 one of Markdown's fundamental goals:

The overriding design goal for Markdown’s formatting syntax is to make it as readable as possible. The idea is that a Markdown-formatted document should be publishable as-is, as plain text, without looking like it’s been marked up with tags or formatting instructions.

但是,如果您希望在没有 space 的情况下支持 header,您可以使用 markdown-it-lazy-headers plugin:

markdown-it-lazy-headers is a plugin for markdown-it that relaxes the syntax of ATX headers so that you don't have to follow the opening sequence of # characters by a space.