不知道如何为(打印的)页面执行此操作(我自己正在寻找),但是对于按部分的脚注,您不能将输入文档分成之前的部分 你把它们传递给 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>
根据需要进行调整。