页面底部或 HTML 部分有 pandoc 脚注吗?

问题描述 投票:0回答:2

我开始在 Markdown 中使用内联脚注:

Some text^[an aside here]. More text.

当我使用 pandoc 导出为 HTML 时,它们出现在整个文档的末尾,但在 PDF 中它们出现在页面的末尾。我更喜欢将它们放在页面末尾,我想知道是否有办法在 HTML 中以这种方式获取它们?

我意识到 HTML 会使页尾变得复杂;该部分的结尾对我来说也同样有效。事实上,将它们放在 PDF 中该部分的末尾,而不是页面的末尾,也可能很有用。 (我尝试将

---
作为分节符,但脚注仍然出现在文档的末尾。)

(我也尝试过制作pdf,然后

pdf2html
,这种方法可行,但对眼睛来说真的很困难。Pandoc似乎不支持pdf到html,我得到“无法解码字节'\xd0'”。 ..”)


(这不是以下内容的重复:在 Pandoc Markdown 输出中生成内联而不是列表式脚注? 这个问题是关于从另一种格式移动 markdown 格式时处理脚注的方式。)

markdown pandoc
2个回答
1
投票

不知道如何对(打印的)页面执行此操作(我自己正在寻找),但是对于按部分的脚注,你不能将输入文档分成几个部分在将它们传递给 pandoc 之前,然后重新组装零件?

例如假设你的 Markdown 文件如下所示(myfile.md):

Some text with a footnote.^[First note.] ---- Some more text with a footnote.^[Second note.] ---- And a third passage.^[Third note.]

然后您可以使用例如以下 PHP 脚本(尽管我确信有一百万种方法可以做到这一点),即

pandoc-sections.php

<?php $input_file = $argv[1]; if (!file_exists($input_file)) { exit('File not found.'); } $chunks = preg_split('/\n-----*\n/',file_get_contents($input_file)); for ($i=0; $i<count($chunks); $i++) { $chunk = $chunks[$i]; $idprefix = "section" . ($i+1); $descriptorspec = array( 0 => array("pipe", "r"), // stdin 1 => array("pipe", "w"), // stdout 2 => array("pipe", "w") // stderr ); $pandoc_process = proc_open('pandoc --id-prefix=' . $idprefix, $descriptorspec, $pipes); if (is_resource($pandoc_process)) { fwrite($pipes[0], $chunk); fclose($pipes[0]); echo stream_get_contents($pipes[1]); fclose($pipes[1]); fclose($pipes[2]); proc_close($pandoc_process); } } ?>

然后运行

php pandoc-sections.php myfile.md



你会得到:

<p>Some text with a footnote.<a href="#section1fn1" class="footnote-ref" id="section1fnref1"><sup>1</sup></a></p> <section class="footnotes"> <hr /> <ol> <li id="section1fn1"><p>First note.<a href="#section1section1fnref1" class="footnote-back">↩</a></p></li> </ol> </section> <p>Some more text with a footnote.<a href="#section2fn1" class="footnote-ref" id="section2fnref1"><sup>1</sup></a></p> <section class="footnotes"> <hr /> <ol> <li id="section2fn1"><p>Second note.<a href="#section2section2fnref1" class="footnote-back">↩</a></p></li> </ol> </section> <p>And a third passage.<a href="#section3fn1" class="footnote-ref" id="section3fnref1"><sup>1</sup></a></p> <section class="footnotes"> <hr /> <ol> <li id="section3fn1"><p>Third note.<a href="#section3section3fnref1" class="footnote-back">↩</a></p></li> </ol> </section>

根据需要进行调整。


0
投票
由于 PDF 输出是通过 LaTeX 进行的,因此您可以使用

endnotes 包来实现此目的。不必编写自己的 pandoc LaTeX 模板,而是在 Markdown 文档的开头编写

--- header-includes: | \includepackage{endnotes} \let\footnote=\endnote ---
在 Markdown 文档末尾您想要所有脚注的位置,添加 

\theendnotes

我还没有直接尝试过这个,但它适用于我的 LaTeX 自定义 pandoc 模板。

© www.soinside.com 2019 - 2024. All rights reserved.