diff options
Diffstat (limited to '_extensions/js/multicol-nohead/multicol-nohead.lua')
-rw-r--r-- | _extensions/js/multicol-nohead/multicol-nohead.lua | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/_extensions/js/multicol-nohead/multicol-nohead.lua b/_extensions/js/multicol-nohead/multicol-nohead.lua index 4b753a4..f190db8 100644 --- a/_extensions/js/multicol-nohead/multicol-nohead.lua +++ b/_extensions/js/multicol-nohead/multicol-nohead.lua @@ -27,6 +27,25 @@ local function has_class(elem, class) return false end +local function is_columnar_header(elem) + return elem.t == "Header" and elem.level == 1 +end + +local function is_multicols_begin(elem) + return elem.t == "RawBlock" and elem.text == "\\begin{multicols}{3}\\raggedcolumns" +end + +local function is_multicols_end(elem) + return elem.t == "RawBlock" and elem.text == "\\end{multicols}" +end + +-- a standalone image with optional caption that has class .wide +-- TODO: detect pre-quarto-filter pattern too +local function is_wide(elem) + return ((elem.t == "Para" and has_class(elem.content[1], "wide")) + or (elem.t == "Figure" and has_class(elem.content[1].content[1], "wide"))) +end + -- TODO: detect pre-quarto-filter pattern too local function is_newpage_command(elem) return (elem.t == "RawBlock" and elem.text == "\\newpage{}") @@ -44,11 +63,6 @@ local function is_advertising(elem) return false end --- TODO: include header level 2 and author paragraph above multicolumn -function is_author(elem) - return elem.t == Para and elem.content[1].text == "Forfatter:" -end - -- wrap images with class .ad to span half or full page local function ad(elem) local amount = #elem.content @@ -98,9 +112,13 @@ function Pandoc(doc) local multicol_now = false local multicol_places = {} for i, elem in ipairs(doc.blocks) do - if elem.t == "Header" and elem.level == 1 then + if is_columnar_header(elem) then multicol_places[i] = multicol_now and "renew" or "begin" multicol_now = true + elseif is_wide(elem) then + if multicol_now then + multicol_places[i] = "renew" + end elseif is_advertising(elem) then doc.blocks[i] = ad(elem) if multicol_now then @@ -116,6 +134,10 @@ function Pandoc(doc) multicol_places[i] = "end" multicol_now = false end + elseif is_multicols_begin(elem) then + multicol_now = true + elseif is_multicols_end(elem) then + multicol_now = false end end if multicol_now then |