[英]add metadata field via pandoc lua filter
我正在处理降价文件,例如
---
title: "dummy title"
highlight: "c"
highlighted: 'highlighted'
---
body text
进入高度自定义的乳胶模板中,其中“ c”作为较大的tex宏的一部分被突出显示。 最后一个步骤是拒绝我:这里不必指定虚拟元数据“突出显示”,但是我找不到在下面的lua过滤器中生成它的方法:
text = require 'text'
newstring = '\\textit{a,b,c,d}'
function meta_vars (m)
-- m.highlighted = 'highlighted' -- not working
highlight = m.highlight
return m
end
function replace (elem)
if elem.text == 'highlighted' then
newstring = newstring:gsub(pandoc.utils.stringify(highlight),
'{\\bfseries '..pandoc.utils.stringify(highlight)..'}')
return pandoc.RawInline("latex", newstring)
else
return elem
end
end
return {{Meta = meta_vars}, {Str = replace}}
使用以下自定义模板
\documentclass[12pt]{article}
\begin{document}
\title{$title$ -- $highlighted$}
\maketitle
$body$
\end{document}
运行此示例的命令是
pandoc +RTS -K512m -RTS test.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output test.tex --template _tpl.tex --lua-filter=filter.lua
生产,如广告所示
如何摆脱YAML标头中的虚拟highlighted
标签?
我在这里不太了解您在使用乳胶宏的确切含义,但是问题的症结似乎在于添加新的元数据元素。 你已经有注释掉线--not working
似乎为我工作的罚款。 您可能需要显式设置类型
m.highlighted=pandoc.MetaString('highlighted')
但我认为这不会改变任何事情。
我还注意到,在撰写本文时,只要highlighted
显示的单词出现在文本中,就会修改newstring变量。 用两行highlighted
的新字符串将等于\\textit{a,b,{\\bfseries {\\bfseries c}},d}
。
也许您可以删除乳胶宏内容来重述您的问题,而只关注您希望过滤器执行的操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.