使用Pandoc将缩进的HTML嵌入Markdown中 [英] Embed indented HTML in Markdown with Pandoc

查看:57
本文介绍了使用Pandoc将缩进的HTML嵌入Markdown中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Markdown(表中的项目符号列表)中嵌入了一些HTML.有没有一种方法可以缩进我的HTML,而无需Pandoc将其视为逐字代码块?

I have some embedded HTML in my Markdown (bulleted list within a table). Is there a way to indent my HTML without Pandoc treating it as a verbatim code block?

推荐答案

排序,但您必须更改Pandoc的默认值.

Sort of, but you have to change Pandoc's defaults.

Markdown 规则明确禁止这样做:

The Markdown rules expressly prohibit this:

唯一的限制是块级HTML元素-例如< div> < table> < pre> < p> 等.—必须与周围的内容用空行分隔,并且该块的开始和结束标签不应使用制表符或空格缩进.

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一样进行处理,因此请随时缩进.换句话说,这是完全可以接受的:

However, if you notice, the above quoted rule does specifically state that only "the start and end tags of the block should not be indented." There is no restriction from indenting the content inside the "the start and end tags". In fact, the content between ""the start and end tags" is not even processed as Markdown, so feel free to indent away. In other words, this is completely acceptable:

<table>
    <thead>
        <tr>
            <th>A header</th>
        </tr>
    </thead>
</table>

除了它文档中所述:

Except that it doesn't work in Pandoc by default. As explained in Pandoc's documentation:

标准Markdown允许您包括HTML块":平衡标记之间的HTML块,这些标记与周围的文本用空白行隔开,并在左边界处开始和结束.在这些块中,所有内容都解释为HTML,而不是Markdown.因此(例如), * 并不表示强调.

Pandoc会以这种方式运行;但是默认情况下,pandoc会将HTML块标记之间的内容解释为Markdown.

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 输出格式.

Therefore you either need to use the raw_html extension or the markdown_strict output format.

对于严格模式"使用:

pandoc --from markdown_strict

或者不使用严格模式,但仍然获得所需的HTML行为(禁用 markdown_in_html_blocks 扩展名并启用 raw_html 扩展名):

Or to not use strict mode but still get the HTML behavior you want (disable markdown_in_html_blocks extension and enable raw_html extension):

pandoc --from markdown-markdown_in_html_blocks+raw_html

这篇关于使用Pandoc将缩进的HTML嵌入Markdown中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆