使用Markdown嵌套在HTML中创建目录表格

3
无论何时我在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?


http://blog.yoavram.com/citations-in-markdown-using-pandoc/ 中提到:只有在给定standalone选项或适当的模板时,Pandoc才会插入TOC。关于--standalone和模板的描述可在Pandoc用户指南→模板中找到。这对你有帮助吗? - xmojmr
1个回答

1

我刚刚不得不解决同样的问题,所以我想分享一下。

Pandoc的作者在这个问题中指出了这种行为背后的原因。

他还提供了解决方法。只需将<div>替换为<article>即可。在你的情况下,它应该变成:

#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>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接