简体   繁体   中英

Pandoc Lua: how to add class to a Para

I am getting the error: attempt to index a nil value (field 'attributes') when trying to add a class to a Para element.

The documentation https://pandoc.org/lua-filters.html#pandoc.para seems to suggest that para (and BulletList) only have a content part but no attributes part. So how to add a class to these elements?

Filter:

 Para = function (el) 
    el.attributes['class']='lead'
    return el
 end

Sample:


# this is the title
Lead text for this section

Expected result:

<p class="lead">Lead text for this section</p>

Unfortunately, the document model used by pandoc supports attributes only on a limited set of elements at the moment. See issue #684 in pandoc's issue tracker.

So the only viable method is to "manually" generate the HTML in the filter:

function Para (para)
  return pandoc.Plain(
    {pandoc.RawInline('html', '<p class="lead">')} ..
    para.content ..
    {pandoc.RawInline('html', '</p>')}
  )
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM