gpt4 book ai didi

markdown - 我怎样才能让 Pandoc 保留我的引用链接?

转载 作者:行者123 更新时间:2023-12-05 06:27:32 25 4
gpt4 key购买 nike

我在 Visual Studio Code 中使用 Pandoc 格式扩展来格式化我的 markdown 文档。

我以类似于 Stack Overflow 的风格编写我的引用链接,如下所示:

This is a test file, created by Tim at [Tigra Astronomy][tigra].

This is another line.

[tigra]: http://tigra-astronomy.com "Tigra home page"

Pandoc 确实破坏了这些引用。我尝试了各种选项组合和命令行实验,例如:

pandoc .\input.md --from markdown --to markdown-shortcut_reference_links --reference-links --reference-location=document

该命令实际上产生了这个输出:

This is a test file, created by Tim at [Tigra Astronomy][].

This is another line.

[Tigra Astronomy]: http://tigra-astronomy.com "Tigra home page"

...非常接近,但仍不完全。那么有没有什么办法可以说服 Pandoc 只保留我的引用文献“按书面形式”?

最佳答案

So is there a way I can persuade Pandoc to just keep my references 'as written'?

简而言之,,因为 Pandoc 不保留该信息。

使用命令 pandoc --from markdown --to native 你可以让 Pandoc 输出 Abstract Syntax Tree (AST),这是 Pandoc 文档的内部原生表示。对于您的示例文档,AST 看起来像这样(另请参阅 online demo ):

[Para [Str "This",Space,Str "is",Space,Str "a",Space,Str "test",Space,Str "file,",Space,Str "created",Space,Str "by",Space,Str "Tim",Space,Str "at",Space,Link ("",[],[]) [Str "Tigra",Space,Str "Astronomy"] ("http://tigra-astronomy.com","Tigra home page"),Str "."]
,Para [Str "This",Space,Str "is",Space,Str "another",Space,Str "line."]]

如您所见,链接不会保留您指定的“名称”。因此,当 Pandoc 将 AST 转换回 Markdown 时,它不能使用你的“名字”,因为它不可用。最初我以为也许你可以使用 filtercustom writer包括您的引用名称,但这也不起作用,因为该名称根本不可用。

最后,这应该不足为奇。 Pandoc 不 promise 保留文档中包含的所有元数据。事实上,文档 warns :

Because pandoc’s intermediate representation of a document is less expressive than many of the formats it converts between, one should not expect perfect conversions between every format and every other. Pandoc attempts to preserve the structural elements of a document, but not formatting details such as margin size. And some document elements, such as complex tables, may not fit into pandoc’s simple document model. While conversions from pandoc’s Markdown to all formats aspire to be perfect, conversions from formats more expressive than pandoc’s Markdown can be expected to be lossy.

当然,引用名称是 Markdown 特定的功能。但是,Markdown 支持以多种方式表示链接,并且维护引用名称对于维护有效的 Markdown 文档不是必需的。因此,引用名称是 Pandoc 丢失的内容之一。

但如果只是输出相同的格式,为什么 Pandoc 需要运行 AST。因为这就是它的架构方式。查看API documentation有关这方面的更多信息。

关于markdown - 我怎样才能让 Pandoc 保留我的引用链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55174796/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com