Skip to content

Custom writers: which elements have default methods in pandoc.scaffolding.Writer? #9713

Answered by tarleb
bpj asked this question in Q&A
Discussion options

You must be logged in to vote

We were trying to replicate the behavior of classical custom writers, which would error whenever they encountered an unknown element. But I'm always interested to hear ideas for improvements.

Here's some code that provides default methods for elements:

Writer = pandoc.scaffolding.Writer

Writer.Inline.Space = pandoc.layout.space
Writer.Block.Figure = pandoc.layout.literal '[[Figure]]'

getmetatable(Writer.Inline).__index = function (t, k)
  return rawget(t, k)
    and rawget(t, k)
    or pandoc.utils.stringify
end
getmetatable(Writer.Block).__index = function (t, k)
  return rawget(t, key)
    and rawget(t, key)
    or function (elem)
      if pandoc.utils.type(elem.content) == 'Inlines' t…

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
1 reply
@bpj
Comment options

Comment options

You must be logged in to vote
3 replies
@bpj
Comment options

@tarleb
Comment options

@bpj
Comment options

Answer selected by bpj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants