【问题标题】:Have pandoc footnotes at bottom of page or section in HTML?在 HTML 的页面或部分底部有 pandoc 脚注吗?
【发布时间】:2016-03-31 10:22:48
【问题描述】:

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

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

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

我意识到 HTML 会使页尾变得复杂;部分结束对我来说也同样有效。事实上,将它们放在 PDF 中的部分末尾而不是页面末尾也可能很有用。 (我尝试将--- 作为分节符,但脚注仍然出现在文档的末尾。)

(我也尝试过制作 pdf,然后是 pdf2html,这很有效,但真的很难看。Pandoc 似乎不支持 pdf 到 html,我得到“无法解码字节 '\xd0 ' ...")


(这不是重复的:Generate inline rather than list-style footnotes in Pandoc Markdown output? 这个问题是关于从另一种格式移动 降价格式时脚注的处理方式。)

【问题讨论】:

标签: markdown pandoc


【解决方案1】:

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

例如假设您的降价文件看起来像这样(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>

根据需要进行调整。

【讨论】:

  • 嘿,我刚刚暴露了一个错误,即当使用“--id-prefix”选项时 pandoc 如何处理反向链接。我会提交错误报告。他们修理东西的速度非常快。
猜你喜欢
  • 1970-01-01
  • 2013-07-03
  • 2013-06-07
  • 1970-01-01
  • 2012-07-29
  • 1970-01-01
相关资源
最近更新 更多