【问题标题】:Creating table of contents with Markdown nested inside HTML使用嵌套在 HTML 中的 Markdown 创建目录
【发布时间】:2015-07-08 20:09:11
【问题描述】:

每当我在 HTML 标记中使用 markdown 时,它都不会使用目录选项生成。例如,

#Test

##Test2

Hello there!

#Test3

##Test4

<div>

#hello

</div>

输出:

<nav id="TOC">
<ul>
<li><a href="#test">Test</a><ul>
<li><a href="#test2">Test2</a></li>
</ul></li>
<li><a href="#test3">Test3</a><ul>
<li><a href="#test4">Test4</a></li>
</ul></li>
</ul>
</nav>
<h1 id="test">Test</h1>
<h2 id="test2">Test2</h2>
<p>Hello there!</p>
<h1 id="test3">Test3</h1>
<h2 id="test4">Test4</h2>
<div>
<h1>hello</h1>
</div>

我使用的命令行是:

pandoc -f markdown -t html5 --toc -s test.md

是否可以让目录包含嵌套在 HTML 中的 markdown?

【问题讨论】:

标签: html markdown pandoc


【解决方案1】:

因为我只是要解决同样的问题,所以我想我会分享它。

Pandoc 作者在this issue 中指定了这种行为背后的原因。

实际上,他还指定了解决方法。只需将&lt;div&gt; 替换为&lt;article&gt;。在你的情况下,它会变成:

#Test

##Test2

Hello there!

#Test3

##Test4

<article>

#hello

</article>

用你的命令行,它给了我

<nav id="TOC">
<ul>
<li><a href="#test">Test</a><ul>
<li><a href="#test2">Test2</a></li>
</ul></li>
<li><a href="#test3">Test3</a><ul>
<li><a href="#test4">Test4</a></li>
</ul></li>
<li><a href="#hello">hello</a></li>
</ul>
</nav>
<h1 id="test">Test</h1>
<h2 id="test2">Test2</h2>
<p>Hello there!</p>
<h1 id="test3">Test3</h1>
<h2 id="test4">Test4</h2>
<article>
<h1 id="hello">hello</h1>
</article>

【讨论】:

    猜你喜欢
    • 2011-09-28
    • 2015-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-10
    • 2012-06-13
    • 2012-02-29
    • 2014-03-04
    相关资源
    最近更新 更多