Pandoc:从 Markdown 转换为 HTML 时将字体系列更改为 sans

2023-12-23

我成功地获得了一个漂亮的格式化文本,我可以使用以下方法将其粘贴到任何地方:

cat myFile.md | pandoc -s -f markdown -t html | xclip -selection clipboard -t text/html

xclip https://github.com/astrand/xclip是 X 选择(剪贴板)的命令行界面。和... -t html -o myFile.html效果也很好。

我正在尝试更改字体系列,从默认的 Serif 字体系列更改为其他一些 Sans-serif 字体系列。我发现了很多 LaTex、PDF 和 DOC 的示例,但没有一个适用于这种情况。尝试了很多字体(从fc-list : family,即使安装后texlive-xetex包裹)。我能找到的最接近的答案是this one https://stackoverflow.com/q/37232597/4970442.

我试图在 CLI 上使用某些参数,试图避免类似的事情--css source/styles.css.

在 Ubuntu 18.04 上使用 pandoc 1.19.2.4。

Some --variable我试过:

-V fontfamily:arev
-V fontfamily:Ubuntu
-V fontfamilyoptions:sfdefault
-V "mainfont:DejaVuSans"
-V mainfont="DejaVu Sans Serif"
-V "sansfont:DejaVuSans"

Edit 1:

基于mb21 的回答 https://stackoverflow.com/a/63298129/4970442,自 Pandoc 1.12.x 起(source https://tex.stackexchange.com/a/139205/188590)可以为 Pandoc 添加提供更多元数据YAML 块代码 https://pandoc.org/MANUAL.html#extension-yaml_metadata_block.

在较新的 Pandoc 版本上,我还添加了一个标题键以避免“[警告]此文档格式需要非空元素。”。

---
title: My File
header-includes: |
  <style>
    body {
      font-family: "Liberation Sans";
    }
  </style>
---

我仍然没有看到从 Markdown 而不是 LaTeX,以及使用 HTML 而不是 PDF 之间的根本区别。


Update:这在 pandoc 2.11 中是可能的。有关详细信息,请参阅MANUAL https://pandoc.org/MANUAL.html#variables-for-html,但例如:

---
mainfont: sans-serif
---

my markdown

如果您的字体名称包含空格,则在用反斜杠转义的引号中指定名称:

---
mainfont: \"Sanskrit 2020\"
---

旧答案:您提到的字体变量仅适用于 LaTeX/PDF 输出。要设置 HTML 样式,您需要 CSS。例如,您可以将其放入 Markdown 文件中:

---
header-includes: |
  <style>
    body {
      font-family: sans-serif;
    }
  </style>
---

my markdown

或者您可以:

  • use --css
  • 复制default styles.html https://github.com/jgm/pandoc/blob/master/data/templates/styles.html partial https://pandoc.org/MANUAL.html#partials in ~/.pandoc/templates/styles.html并修改它。 (如果目录不存在,您可以直接创建它们。)
  • use a template https://pandoc.org/MANUAL.html#templates like this one https://github.com/jgm/pandoc/pull/6601/files...

另外:pandoc 1.19 很古老,请参阅https://pandoc.org/installing.html https://pandoc.org/installing.html

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Pandoc:从 Markdown 转换为 HTML 时将字体系列更改为 sans 的相关文章

随机推荐