我正在使用Pandoc来编写网站的内容.如何在文档中包含元标记(特别是描述和关键字标记),而不更改传递给Pandoc的命令行参数?
我的意思是,我可以在文档文本中以某种方式包含元标记吗?我不想传递命令行选项,因为有几个不同的页面,有不同的关键字,我想从Emacs中发送到Pandoc,并且自定义每个页面都是个问题.
War*_*rbo 13
我发现在命令中添加--self-contained或-s选项pandoc允许在顶部的YAML中按文件定义标题内容.
例如:
$ cat foo.md
---
title: Foo
header-includes:
<meta name="keywords" content="Foo,Bar" />
<meta name="description" content="My description" />
---
# Bar #
Baz
$ pandoc -s -o foo.html foo.md
$ cat foo.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.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>Foo</title>
<style type="text/css">code{white-space: pre;}</style>
<meta name="keywords" content="Foo,Bar" /> <meta name="description" content="My description" />
</head>
<body>
<div id="header">
<h1 class="title">Foo</h1>
</div>
<h1 id="bar">Bar</h1>
<p>Baz</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
好的——所以 David Cain 建议的选项 1 似乎是一个相当简单的解决方案。我的实现有点丑陋,但有效:
首先,使用字段名称以下划线结尾的 YAML 标头来添加标头行。Pandoc 手册说这些标识符将被忽略。
---
head_: <meta name="description" content="x is super cool">
head_: <meta name="keywords" content="cool,cold,temperature,super things">
---
Run Code Online (Sandbox Code Playgroud)
让 Emacs 在当前缓冲区中搜索它并将该行保存到文件中。
---
head_: <meta name="description" content="x is super cool">
head_: <meta name="keywords" content="cool,cold,temperature,super things">
---
Run Code Online (Sandbox Code Playgroud)
(我的elisp能力不是很好,所以可能有更好的写法)
最后——pandoc -s -H head.html在 Emacs markdown 模式下用作 markdown 命令。
感谢 David Cain 提出了这个-H选项的建议!
编辑:作为奖励,我们可以在标题中包含任何内容,包括网站图标!
head_: <link rel="icon" type="image/x-icon" href="favicon.ico" />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4080 次 |
| 最近记录: |