【发布时间】:2023-03-21 23:15:02
【问题描述】:
我正在为 pandoc 编写一个 Lua 过滤器,它将词汇表函数添加到 Markdown 文件的 HTML 输出。目标是在文档中每次出现的首字母缩写词或键定义中添加鼠标悬停文本。
我希望能够在列表中包含首字母缩略词(用标点符号包围),但不能包含字母(例如,CO 不会在诸如钴之类的单词中突出显示)。
我的 MWE 在这个计数上失败了,因为 Pandoc AST 中的字符串包含相邻的标点符号(例如 Str "CO/DBP/SBP," 或 Str "CO,",Space,Str "SBP,")。
-- # MWE
-- Parse glossary file (summarised here for brevity)
local glossary = {CO = "Cardiac Output", DBP = "Diastolic Blood Pressure", SBP = "Systolic Blood Pressure"}
-- Substitute glossary term for span with a mouseover link
function Str(elem)
for key, value in next, glossary do
if elem.text == key then
return pandoc.Span (key, {title = value, class = "glossary"})
end
end
end
我玩过string.sub 和string.find,但没有得到任何可行的东西,主要是因为我不确定如何返回新的 Span 和 Str(减去它的新 Span )。任何帮助将不胜感激!
我的测试降价包含:
# Acronyms: SBP, DBP & CO
Spaced acronyms: CO and SBP and DBP.
In a comma-separated list: CO, SBP, DBP; with backslashes; CO/DBP/SBP, and in bullet points:
* CO
* SBP
* DBP
【问题讨论】: