Loading md_to_docx_converter/md_to_html_2.lua +52 −42 Original line number Diff line number Diff line Loading @@ -60,7 +60,9 @@ function Substitute(el, word) -- logfile:flush() if elem.t == "Str" and elem.text:lower():find(word) and not elem.text:find("+++") then --check the next strings to see if we need to link it local wordStartIndex = elem.text:lower():find(word) local precedentChar = elem.text:sub(wordStartIndex - 1, wordStartIndex - 1) local startIndex, endIndex, number = elem.text:gsub("‑", "-"):find(pattern) --check if number is in the same Str elem if not precedentChar:match("~") then if number then --create link first_character = number:sub(1, 1) newContent:insert(pandoc.Link(elem.text:sub(1, endIndex), "clause-" .. first_character .. ".html#" .. number)) Loading Loading @@ -110,6 +112,7 @@ function Substitute(el, word) end end end end --append the other elements normally newContent:insert(elem) ::continue:: Loading @@ -130,6 +133,13 @@ function MultipleClauses(el) if elem.t == "Str" then --this may be the start of a list of multiple clauses if elem.text:lower():find("clauses") then local wordStartIndex = elem.text:lower():find("clauses") local precedentChar = elem.text:sub(wordStartIndex - 1, wordStartIndex - 1) if precedentChar:match("~") then --this is a negated clauses, do nothing newContent:insert(elem) goto continue end clausesFound = true -- Replace plain "clauses" text with a span containing it local clausesSpan = pandoc.Span({pandoc.Str(elem.text)}) Loading md_to_docx_converter/md_to_html_3.lua +46 −5 Original line number Diff line number Diff line Loading @@ -118,10 +118,43 @@ function CustomTagsToLinks(el, prefix) return el end function RemoveLeadingTilde(el) local new_content = pandoc.List() local children = el.content local words = {"clause", "table", "figure", "annex"} for _, child in ipairs(children) do if child.t == "Str" then local text = child.text for _, word in ipairs(words) do local pattern = "~" .. word local start_index, end_index = text:lower():find(pattern) if start_index then if start_index > 1 then new_content:insert(pandoc.Str(text:sub(1, start_index - 1))) end local remaining_text = text:sub(end_index + 1) new_content:insert(pandoc.Str(word .. remaining_text)) goto continue end end new_content:insert(child) else new_content:insert(child) end ::continue:: end -- Replace the original content with the new one el.content = new_content return el end function Para(el) el = CustomTagsToLinks(el, "Table") el = CustomTagsToLinks(el, "Figure") el = CustomTagsToLinks(el, "Clause") el = RemoveLeadingTilde(el) return el end Loading @@ -129,6 +162,7 @@ function Div(el) el = CustomTagsToLinks(el, "Table") el = CustomTagsToLinks(el, "Figure") el = CustomTagsToLinks(el, "Clause") el = RemoveLeadingTilde(el) return el end Loading @@ -136,6 +170,7 @@ function Plain(el) el = CustomTagsToLinks(el, "Table") el = CustomTagsToLinks(el, "Figure") el = CustomTagsToLinks(el, "Clause") el = RemoveLeadingTilde(el) return el end Loading @@ -143,18 +178,22 @@ function Strong(el) el = CustomTagsToLinks(el, "Table") el = CustomTagsToLinks(el, "Figure") el = CustomTagsToLinks(el, "Clause") return el end -- function Emph(el) function Emph(el) -- el = CustomTagsToLinks(el, "Table") -- el = CustomTagsToLinks(el, "Figure") -- el = CustomTagsToLinks(el, "Clause") -- end el = RemoveLeadingTilde(el) return el end function Underline(el) el = CustomTagsToLinks(el, "Table") el = CustomTagsToLinks(el, "Figure") el = CustomTagsToLinks(el, "Clause") el = RemoveLeadingTilde(el) return el end Loading @@ -162,4 +201,6 @@ function Span(el) el = CustomTagsToLinks(el, "Table") el = CustomTagsToLinks(el, "Figure") el = CustomTagsToLinks(el, "Clause") el = RemoveLeadingTilde(el) return el end No newline at end of file Loading
md_to_docx_converter/md_to_html_2.lua +52 −42 Original line number Diff line number Diff line Loading @@ -60,7 +60,9 @@ function Substitute(el, word) -- logfile:flush() if elem.t == "Str" and elem.text:lower():find(word) and not elem.text:find("+++") then --check the next strings to see if we need to link it local wordStartIndex = elem.text:lower():find(word) local precedentChar = elem.text:sub(wordStartIndex - 1, wordStartIndex - 1) local startIndex, endIndex, number = elem.text:gsub("‑", "-"):find(pattern) --check if number is in the same Str elem if not precedentChar:match("~") then if number then --create link first_character = number:sub(1, 1) newContent:insert(pandoc.Link(elem.text:sub(1, endIndex), "clause-" .. first_character .. ".html#" .. number)) Loading Loading @@ -110,6 +112,7 @@ function Substitute(el, word) end end end end --append the other elements normally newContent:insert(elem) ::continue:: Loading @@ -130,6 +133,13 @@ function MultipleClauses(el) if elem.t == "Str" then --this may be the start of a list of multiple clauses if elem.text:lower():find("clauses") then local wordStartIndex = elem.text:lower():find("clauses") local precedentChar = elem.text:sub(wordStartIndex - 1, wordStartIndex - 1) if precedentChar:match("~") then --this is a negated clauses, do nothing newContent:insert(elem) goto continue end clausesFound = true -- Replace plain "clauses" text with a span containing it local clausesSpan = pandoc.Span({pandoc.Str(elem.text)}) Loading
md_to_docx_converter/md_to_html_3.lua +46 −5 Original line number Diff line number Diff line Loading @@ -118,10 +118,43 @@ function CustomTagsToLinks(el, prefix) return el end function RemoveLeadingTilde(el) local new_content = pandoc.List() local children = el.content local words = {"clause", "table", "figure", "annex"} for _, child in ipairs(children) do if child.t == "Str" then local text = child.text for _, word in ipairs(words) do local pattern = "~" .. word local start_index, end_index = text:lower():find(pattern) if start_index then if start_index > 1 then new_content:insert(pandoc.Str(text:sub(1, start_index - 1))) end local remaining_text = text:sub(end_index + 1) new_content:insert(pandoc.Str(word .. remaining_text)) goto continue end end new_content:insert(child) else new_content:insert(child) end ::continue:: end -- Replace the original content with the new one el.content = new_content return el end function Para(el) el = CustomTagsToLinks(el, "Table") el = CustomTagsToLinks(el, "Figure") el = CustomTagsToLinks(el, "Clause") el = RemoveLeadingTilde(el) return el end Loading @@ -129,6 +162,7 @@ function Div(el) el = CustomTagsToLinks(el, "Table") el = CustomTagsToLinks(el, "Figure") el = CustomTagsToLinks(el, "Clause") el = RemoveLeadingTilde(el) return el end Loading @@ -136,6 +170,7 @@ function Plain(el) el = CustomTagsToLinks(el, "Table") el = CustomTagsToLinks(el, "Figure") el = CustomTagsToLinks(el, "Clause") el = RemoveLeadingTilde(el) return el end Loading @@ -143,18 +178,22 @@ function Strong(el) el = CustomTagsToLinks(el, "Table") el = CustomTagsToLinks(el, "Figure") el = CustomTagsToLinks(el, "Clause") return el end -- function Emph(el) function Emph(el) -- el = CustomTagsToLinks(el, "Table") -- el = CustomTagsToLinks(el, "Figure") -- el = CustomTagsToLinks(el, "Clause") -- end el = RemoveLeadingTilde(el) return el end function Underline(el) el = CustomTagsToLinks(el, "Table") el = CustomTagsToLinks(el, "Figure") el = CustomTagsToLinks(el, "Clause") el = RemoveLeadingTilde(el) return el end Loading @@ -162,4 +201,6 @@ function Span(el) el = CustomTagsToLinks(el, "Table") el = CustomTagsToLinks(el, "Figure") el = CustomTagsToLinks(el, "Clause") el = RemoveLeadingTilde(el) return el end No newline at end of file