Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...