使用 Pandoc 在 Markdown 中嵌入缩进 HTML
Embed indented HTML in Markdown with Pandoc
我的 Markdown 中嵌入了一些 HTML(table 中的项目符号列表)。有没有办法缩进我的 HTML 而不是 Pandoc 将其视为逐字代码块?
有点,但你必须更改 Pandoc 的默认值。
Markdown rules 明确禁止:
The only restrictions are that block-level HTML elements — e.g. <div>
, <table>
, <pre>
, <p>
, etc. — must be separated from surrounding content by blank lines, and the start and end tags of the block should not be indented with tabs or spaces.
但是,如果您注意到,上面引用的规则确实明确指出只有“块的开始和结束标记不应缩进”。缩进“开始和结束标签”内的内容没有限制。事实上,“开始和结束标签”之间的内容甚至没有作为 Markdown 处理,所以可以随意缩进。换句话说,这是完全可以接受的:
<table>
<thead>
<tr>
<th>A header</th>
</tr>
</thead>
</table>
除了它 doesn't work in Pandoc by default. As explained in Pandoc's documentation:
Standard Markdown allows you to include HTML “blocks”: blocks of HTML between balanced tags that are separated from the surrounding text with blank lines, and start and end at the left margin. Within these blocks, everything is interpreted as HTML, not Markdown; so (for example), *
does not signify emphasis.
Pandoc behaves this way when the markdown_strict
format is used; but by default, pandoc interprets material between HTML block tags as Markdown.
因此您需要使用 raw_html
扩展或 markdown_strict
输出格式。
对于“严格模式”使用:
pandoc --from markdown_strict
或者不使用严格模式但仍然得到你想要的 HTML 行为(禁用 markdown_in_html_blocks
扩展并启用 raw_html
扩展):
pandoc --from markdown-markdown_in_html_blocks+raw_html
我的 Markdown 中嵌入了一些 HTML(table 中的项目符号列表)。有没有办法缩进我的 HTML 而不是 Pandoc 将其视为逐字代码块?
有点,但你必须更改 Pandoc 的默认值。
Markdown rules 明确禁止:
The only restrictions are that block-level HTML elements — e.g.
<div>
,<table>
,<pre>
,<p>
, etc. — must be separated from surrounding content by blank lines, and the start and end tags of the block should not be indented with tabs or spaces.
但是,如果您注意到,上面引用的规则确实明确指出只有“块的开始和结束标记不应缩进”。缩进“开始和结束标签”内的内容没有限制。事实上,“开始和结束标签”之间的内容甚至没有作为 Markdown 处理,所以可以随意缩进。换句话说,这是完全可以接受的:
<table>
<thead>
<tr>
<th>A header</th>
</tr>
</thead>
</table>
除了它 doesn't work in Pandoc by default. As explained in Pandoc's documentation:
Standard Markdown allows you to include HTML “blocks”: blocks of HTML between balanced tags that are separated from the surrounding text with blank lines, and start and end at the left margin. Within these blocks, everything is interpreted as HTML, not Markdown; so (for example),
*
does not signify emphasis.Pandoc behaves this way when the
markdown_strict
format is used; but by default, pandoc interprets material between HTML block tags as Markdown.
因此您需要使用 raw_html
扩展或 markdown_strict
输出格式。
对于“严格模式”使用:
pandoc --from markdown_strict
或者不使用严格模式但仍然得到你想要的 HTML 行为(禁用 markdown_in_html_blocks
扩展并启用 raw_html
扩展):
pandoc --from markdown-markdown_in_html_blocks+raw_html