用于解析内部链接的 pandoc 命令行参数
pandoc command line parameters for resolving internal links
我的问题类似于this post,但不相同。当使用几个 interlinked 时,我无法为 maintaining/resolving 跨文档 link 找出正确的 pandoc 命令行参数 HTML 个文件作为输入。
假设我有两个文件,chapter1.xhtml 和 chapter2.xhtml 位于 /home/user/Documents 文件夹中,内容如下:
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<h3>Chapter 1</h3>
<p><a href="/home/user/Documents/chapter2.xhtml">Next chapter</a><br /></p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</body>
</html>
其中包含一个link到下一个文件。
和
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<h3>Chapter 2</h3>
<p><a href="/home/user/Documents/chapter1.xhtml">Previous chapter</a><br /></p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</body>
</html>
里面包含一个link到上一个文件。
我使用了以下命令行参数:
$ pandoc -s --toc --verbose -o /home/user/Documents/output.markdown /home/user/Documents/chapter1.xhtml /home/user/Documents/chapter2.xhtml
我得到了以下输出:
---
---
- [Chapter 1](#chapter-1)
- [Chapter 2](#chapter-2)
### Chapter 1
[Next chapter](/home/user/Documents/chapter2.xhtml)\
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
### Chapter 2
[Previous chapter](/home/user/Documents/chapter1.xhtml)\
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
当我将select docx 或latex/pdf 作为输出格式时,也会出现此问题。我也尝试使用相对 links,但没有任何效果。
解析跨文档 link 的正确参数是什么?
tl;dr 即我不想要包含原始路径的 link 引用;我希望他们指向新的输出文档。
问题是您的链接包含绝对路径 (/home/user/Documents/chapter1.xhtml
) 而不是相对路径 (chapter1.xhtml
)。我无法想象 ePUB 文件包含绝对路径,如果包含绝对路径,文件中的链接将只能在您的计算机上正常工作。所以解决方案必须在将它们提供给 pandoc 之前修复这些 ePUB 文件。
请注意,从 pandoc 从 markdown 到 epub 再回到 html 的往返工作按预期进行:
$ pandoc -o foo.epub
# foo
adfs
# bar
go [to foo](#foo)
$ unzip foo.epub
$ cat ch002.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta name="generator" content="pandoc" />
<title>bar</title>
<link rel="stylesheet" type="text/css" href="stylesheet.css" />
</head>
<body>
<div id="bar" class="section level1">
<h1>bar</h1>
<p>go <a href="ch001.xhtml#foo">to foo</a></p>
</div>
</body>
</html>
$ pandoc foo.epub
<p><span id="ch001.xhtml"></span></p>
<div id="ch001.xhtml#foo" class="section level1">
<h1>foo</h1>
<p>adfs</p>
</div>
<p><span id="ch002.xhtml"></span></p>
<div id="ch002.xhtml#bar" class="section level1">
<h1>bar</h1>
<p>go <a href="#ch001.xhtml#foo">to foo</a></p>
</div>
P.S.
使用两个输入文档,例如:
pandoc -o output.md chapter1.xhtml chapter2.xhtml
作为 pandoc README 状态工作:
If multiple input files are given, pandoc will concatenate them all (with blank lines between them) before parsing.
所以对于由 pandoc 完成的解析,它将其视为一个文档...所以难怪跨文件链接不起作用。
我的问题类似于this post,但不相同。当使用几个 interlinked 时,我无法为 maintaining/resolving 跨文档 link 找出正确的 pandoc 命令行参数 HTML 个文件作为输入。
假设我有两个文件,chapter1.xhtml 和 chapter2.xhtml 位于 /home/user/Documents 文件夹中,内容如下:
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<h3>Chapter 1</h3>
<p><a href="/home/user/Documents/chapter2.xhtml">Next chapter</a><br /></p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</body>
</html>
其中包含一个link到下一个文件。
和
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<h3>Chapter 2</h3>
<p><a href="/home/user/Documents/chapter1.xhtml">Previous chapter</a><br /></p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</body>
</html>
里面包含一个link到上一个文件。
我使用了以下命令行参数:
$ pandoc -s --toc --verbose -o /home/user/Documents/output.markdown /home/user/Documents/chapter1.xhtml /home/user/Documents/chapter2.xhtml
我得到了以下输出:
---
---
- [Chapter 1](#chapter-1)
- [Chapter 2](#chapter-2)
### Chapter 1
[Next chapter](/home/user/Documents/chapter2.xhtml)\
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
### Chapter 2
[Previous chapter](/home/user/Documents/chapter1.xhtml)\
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
当我将select docx 或latex/pdf 作为输出格式时,也会出现此问题。我也尝试使用相对 links,但没有任何效果。
解析跨文档 link 的正确参数是什么?
tl;dr 即我不想要包含原始路径的 link 引用;我希望他们指向新的输出文档。
问题是您的链接包含绝对路径 (/home/user/Documents/chapter1.xhtml
) 而不是相对路径 (chapter1.xhtml
)。我无法想象 ePUB 文件包含绝对路径,如果包含绝对路径,文件中的链接将只能在您的计算机上正常工作。所以解决方案必须在将它们提供给 pandoc 之前修复这些 ePUB 文件。
请注意,从 pandoc 从 markdown 到 epub 再回到 html 的往返工作按预期进行:
$ pandoc -o foo.epub
# foo
adfs
# bar
go [to foo](#foo)
$ unzip foo.epub
$ cat ch002.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta name="generator" content="pandoc" />
<title>bar</title>
<link rel="stylesheet" type="text/css" href="stylesheet.css" />
</head>
<body>
<div id="bar" class="section level1">
<h1>bar</h1>
<p>go <a href="ch001.xhtml#foo">to foo</a></p>
</div>
</body>
</html>
$ pandoc foo.epub
<p><span id="ch001.xhtml"></span></p>
<div id="ch001.xhtml#foo" class="section level1">
<h1>foo</h1>
<p>adfs</p>
</div>
<p><span id="ch002.xhtml"></span></p>
<div id="ch002.xhtml#bar" class="section level1">
<h1>bar</h1>
<p>go <a href="#ch001.xhtml#foo">to foo</a></p>
</div>
P.S.
使用两个输入文档,例如:
pandoc -o output.md chapter1.xhtml chapter2.xhtml
作为 pandoc README 状态工作:
If multiple input files are given, pandoc will concatenate them all (with blank lines between them) before parsing.
所以对于由 pandoc 完成的解析,它将其视为一个文档...所以难怪跨文件链接不起作用。