summaryrefslogtreecommitdiff
path: root/_extensions/js/ingress/ingress.lua
blob: 3c2c429adb3314279cce18ab4fb8f69e82503bdc (plain)
  1. -- Translate div class .lead to custo LaTeX environment \ingress{}
  2. local function escape_latex(str)
  3. local replacements = {
  4. ["\\"] = "\\textbackslash{}",
  5. ["{"] = "\\{",
  6. ["}"] = "\\}",
  7. ["$"] = "\\$",
  8. ["&"] = "\\&",
  9. ["#"] = "\\#",
  10. ["_"] = "\\_",
  11. ["%"] = "\\%",
  12. ["^"] = "\\textasciicircum{}",
  13. ["~"] = "\\textasciitilde{}"
  14. }
  15. return (str:gsub(".", function(c)
  16. return replacements[c] or c
  17. end))
  18. end
  19. function Div(el)
  20. if FORMAT:match 'latex' then
  21. if el.classes:includes('lead') then
  22. local content = pandoc.utils.stringify(el.content)
  23. local escaped_content = escape_latex(content)
  24. return pandoc.RawBlock('latex', '\\ingress{' .. escaped_content .. '}')
  25. end
  26. end
  27. end