summaryrefslogtreecommitdiff
path: root/_extensions/js/multicol-nohead/multicol-nohead.lua
blob: a5bba1b96fc210aa33818bd8ef07e071be96d311 (plain)
  1. -- Render content below header in three columns
  2. local multicol_begin = pandoc.RawBlock('latex', [[
  3. \begin{multicols}{3}\raggedcolumns
  4. ]])
  5. local multicol_end = pandoc.RawBlock('latex', [[
  6. \end{multicols}
  7. ]])
  8. -- TODO: include header level 2 and author paragraph above multicolumn
  9. function is_author(elem)
  10. return elem.t == Para and elem.content[1].text == "Forfatter:"
  11. end
  12. function Pandoc(doc)
  13. if FORMAT:match 'latex' then
  14. -- locate topmost-only elements where multicol state should change
  15. local multicol_now = false
  16. local multicol_places = {}
  17. for i, elem in ipairs(doc.blocks) do
  18. if elem.t == "Header" and elem.level == 1 then
  19. multicol_places[i] = multicol_now and "renew" or "begin"
  20. multicol_now = true
  21. elseif elem.t == "HorizontalRule" then
  22. if multicol_now then
  23. multicol_places[i] = "end"
  24. multicol_now = false
  25. end
  26. end
  27. end
  28. if multicol_now then
  29. multicol_places[#doc.blocks] = "end"
  30. end
  31. -- apply multicol, in reverse order since it shifts later indices
  32. for i = #doc.blocks, 1, -1 do
  33. local state = multicol_places[i]
  34. if state ~= nil then
  35. if state == "begin" then
  36. doc.blocks:insert(i + 1, multicol_begin)
  37. elseif state == "renew" then
  38. doc.blocks:insert(i + 1, multicol_begin)
  39. doc.blocks:insert(i, multicol_end)
  40. elseif state == "end" then
  41. doc.blocks:insert(i, multicol_end)
  42. end
  43. end
  44. end
  45. if #multicol_places >= 1 then
  46. return doc
  47. end
  48. end
  49. end