我开始在Markdown中使用内联脚注:
Some text^[an aside here]. More text.
Run Code Online (Sandbox Code Playgroud)
当我使用pandoc导出到HTML时,它们出现在整个文档的末尾,但在PDF中它们出现在页面的末尾.我更喜欢它们在页面的末尾,我想知道是否有办法在HTML中以这种方式获取它们?
我意识到页面末尾会因HTML而变得复杂; 对于我来说,结尾部分也会起作用.实际上,将它们放在PDF的部分末尾而不是页面的末尾也可能有用.(我已尝试将其---作为分节符,但脚注仍然在文档末尾.)
(我也试过制作pdf,然后pdf2html,哪种工作但是真的很难看.Pandoc似乎不支持pdf到html,我得到"无法解码字节'\ xd0'......")
(这不是重复:在Pandoc Markdown输出中生成内联而不是列表样式的脚注? 这个问题是关于从另一种格式转换为 markdown格式时脚注的处理方式.)
不知道如何对(打印的)页面执行此操作(我自己正在寻找),但是对于按部分的脚注,您不能在将输入文档传递给pandoc之前将其分成各个部分吗?然后重新组装零件?
\n\n例如,假设您的 Markdown 文件如下所示(myfile.md):
\n\nSome text with a footnote.^[First note.]\n----\nSome more text with a footnote.^[Second note.]\n----\nAnd a third passage.^[Third note.]\nRun Code Online (Sandbox Code Playgroud)\n\n然后您可以使用例如以下 PHP 脚本(尽管我确信有一百万种方法可以做到这一点),即pandoc-sections.php.
<?php\n\n$input_file = $argv[1];\n\nif (!file_exists($input_file)) {\n exit(\'File not found.\');\n}\n\n$chunks = preg_split(\'/\\n-----*\\n/\',file_get_contents($input_file));\n\nfor ($i=0; $i<count($chunks); $i++) {\n $chunk = $chunks[$i];\n $idprefix = "section" . ($i+1);\n\n $descriptorspec = array(\n 0 => array("pipe", "r"), // stdin\n 1 => array("pipe", "w"), // stdout \n 2 => array("pipe", "w") // stderr\n );\n\n $pandoc_process = proc_open(\'pandoc --id-prefix=\' . \n $idprefix, $descriptorspec, $pipes);\n\n if (is_resource($pandoc_process)) {\n fwrite($pipes[0], $chunk);\n fclose($pipes[0]);\n echo stream_get_contents($pipes[1]);\n fclose($pipes[1]);\n fclose($pipes[2]);\n proc_close($pandoc_process);\n }\n\n} \n\n?>\nRun Code Online (Sandbox Code Playgroud)\n\n然后运行
\n\nphp pandoc-sections.php myfile.md
你得到:
\n\n<p>Some text with a footnote.<a href="#section1fn1" class="footnote-ref" id="section1fnref1"><sup>1</sup></a></p>\n<section class="footnotes">\n<hr />\n<ol>\n<li id="section1fn1"><p>First note.<a href="#section1section1fnref1" class="footnote-back">\xe2\x86\xa9</a></p></li>\n</ol>\n</section>\n<p>Some more text with a footnote.<a href="#section2fn1" class="footnote-ref" id="section2fnref1"><sup>1</sup></a></p>\n<section class="footnotes">\n<hr />\n<ol>\n<li id="section2fn1"><p>Second note.<a href="#section2section2fnref1" class="footnote-back">\xe2\x86\xa9</a></p></li>\n</ol>\n</section>\n<p>And a third passage.<a href="#section3fn1" class="footnote-ref" id="section3fnref1"><sup>1</sup></a></p>\n<section class="footnotes">\n<hr />\n<ol>\n<li id="section3fn1"><p>Third note.<a href="#section3section3fnref1" class="footnote-back">\xe2\x86\xa9</a></p></li>\n</ol>\n</section>\nRun Code Online (Sandbox Code Playgroud)\n\n根据需要进行调整。
\n| 归档时间: |
|
| 查看次数: |
4033 次 |
| 最近记录: |