Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

lua - Return the text string of el.content in pandoc filter

When using pandoc filter, I just want to get the text of el.content, but it return a Table!

The .md as follows(just for debug):

[It's so easy!]{color="red"}. Today is Monday.

I want to get the string It's so easy! be printed. So, I write the code:

function Span(el)
  color  = el.attributes['color']
  strTxt = el.content
  print(strTxt)
end

but it's not true! By using el.text also the same!

question from:https://stackoverflow.com/questions/65939347/return-the-text-string-of-el-content-in-pandoc-filter

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The module pandoc.utils contains a function stringify which will convert an element into a list:

function Span(el)
  print(pandoc.utils.stringify(el))
end

This will print It’s so easy! (note the effect of pandoc's smart handling of apostrophes: a closing curly quote has replaced the straight apostrophe ').

Consult the Lua filters docs for more info on how to use them.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...