Spaces:
Running
Running
| -------------------------------------------------------------------------- -- | |
| -- Does work searches for Hello and replaces it with foundyou | |
| -- function Para(elem) | |
| -- for i, item in ipairs(elem.content) do | |
| -- if item.text == "Hello" then | |
| -- elem.content[i].text = "foundyou" | |
| -- end | |
| -- end | |
| -- return elem | |
| -- end | |
| -- ------------------------- read the header content ------------------------ -- | |
| -- Define the filter function | |
| local function headerfilter(elem) | |
| if elem.t == 'Header' then | |
| local text = pandoc.utils.stringify(elem.content) | |
| io.write('\27[32mCurrent header:', text ,'\n--------\27[0m\n') | |
| end | |
| return elem | |
| end | |
| -- Define the filter function | |
| local function glsfilter_1(elem) | |
| if elem.t == 'Para' then | |
| -- local text = pandoc.utils.stringify(elem) | |
| local text = elem.text | |
| local pattern = '\\gls' | |
| local match = text:match(pattern) | |
| if match then | |
| print("\27[32mMatch found:", match, '\27[0m\n') | |
| print(text, '\n--------\n') | |
| local link = pandoc.Link(match, '#' .. match) | |
| -- return pandoc.Para{link} | |
| return "replaced" | |
| else | |
| print("\27[31mNo match found\27[0m\n") | |
| print(text, '\n--------\n') | |
| end | |
| end | |
| return elem | |
| end | |
| gls_Dict = { | |
| ode = {"<b>O</b>rdinary <b>D</b>ifferential <b>E</b>quation", | |
| "ODE"}, | |
| cnm = { "<b>C</b>luster-based <b>N</b>etwork <b>M</b>odeling", | |
| "CNM"}, | |
| cnmc = {"<b>c</b>ontrol-oriented <b>C</b>luster-based <b>N</b>etwork <b>M</b>odeling", | |
| "CNMc"}, | |
| cmm = { "<b>C</b>luster <b>M</b>arkov-based <b>M</b>odeling", | |
| "CMM"}, | |
| cfd = {"<b>C</b>omputational <b>F</b>luid <b>D</b>ynamics", | |
| "CFD"}, | |
| rans = {"<b>R</b>eynolds <b>A</b>veraged <b>N</b>avier <b>S</b>tockes", | |
| "RANS"}, | |
| dlr = {"German Aerospace Center", | |
| "DLR"}, | |
| gpu = {"<b>G</b>raphics <b>P</b>rocessing <b>U</b>nit", | |
| "GPU"}, | |
| cpu = {"<b>C</b>omputer <b>P</b>rocessing <b>U</b>nit", | |
| "CPU"}, | |
| sdic = {"<b>S</b>ensitive <b>D</b>ependence on <b>I</b>nitial <b>C</b>onditions", | |
| "SDIC"}, | |
| nmf = {"<b>N</b>on-negative <b>M</b>atrix <b>F</b>actorization", | |
| "NMF"}, | |
| svd = {"<b>S</b>ingular <b>V</b>alue <b>D</b>ecomposition", | |
| "SVD"}, | |
| rf = {"<b>R</b>andom <b>F</b>orest", | |
| "RF"}, | |
| cpd = {"<b>C</b>luster <b>P</b>robability <b>D</b>istribution", | |
| "CPD"}, | |
| cpevol = {"<b>C</b>entroid <b>P</b>osition <b>E</b>volution", | |
| "CPE"}, | |
| dtw = {"<b>D</b>ynamical <b>T</b>ime <b>W</b>arping", | |
| "DTW"}, | |
| knn = {"<b>KN</b>earest <b>N</b>eighbor", | |
| "KNN"}, | |
| } | |
| -- -------------------------------------------------------------------------- -- | |
| local function headerfilter(elem) | |
| if elem.t == 'Header' then | |
| local text = pandoc.utils.stringify(elem.content) | |
| io.write('\27[32mCurrent header:', text ,'\n--------\27[0m\n') | |
| end | |
| return elem | |
| end | |
| -- Define the filter function | |
| local function glsfilter(elem) | |
| if elem.t == 'Para' then | |
| local has_match = false | |
| -- Traverse the element tree and replace matched elements | |
| local new_content = {} | |
| for _, item in ipairs(elem.content) do | |
| -- -------------------------------- gls ------------------------------- -- | |
| if item.t == 'RawInline' then | |
| local gls_Pat = '\\gls{(%w+)}' | |
| local gls_First_Pat = '\\glsfirst{(%w+)}' | |
| local gls_Pl_Pat = '\\glspl{(%w+)}' | |
| local text = item.text | |
| -- will only show the latex \command{} content | |
| -- print("current line is: ", text) | |
| -- was tested with: | |
| -- jav test: \gls{rans} \gls{gpu} \gls{rans} \gls{cfd} \gls{cfd} | |
| -- it does replace each occurence correcly | |
| local gls_Match = string.match(text,gls_Pat) | |
| local gls_First_Match = string.match(text,gls_First_Pat) | |
| local gls_Pl_Match = string.match(text,gls_Pl_Pat) | |
| if gls_Match then | |
| has_match = true | |
| long_Term = gls_Dict[gls_Match][1] | |
| bold_Abbrev = gls_Dict[gls_Match][2] | |
| -- to make sure that the code is understood as valid html code it must be converted to RawInline with the html input | |
| html_String = pandoc.RawInline('html',long_Term) | |
| span_Var = pandoc.Span(html_String, | |
| {class = 'gls_Content'}) | |
| -- print("span_Var: ",span_Var) | |
| -- see: https://pandoc.org/lua-filters.html#pandoc.link | |
| local link = pandoc.Link( | |
| {bold_Abbrev,span_Var}, | |
| '../0_Deco/3_Used_Abbrev.qmd'..'#' .. gls_Match, | |
| nil, | |
| -- add id and class | |
| {id = gls_Match.. "gls", class = 'gls'}) | |
| table.insert(new_content, link) | |
| end | |
| -- ------------------------ gls_First_Match ----------------------- -- | |
| if gls_First_Match then | |
| has_match = true | |
| -- to make sure that the code is understood as valid html code it must be converted to RawInline with the html input | |
| long_Term = gls_Dict[gls_First_Match][1] | |
| bold_Abbrev = gls_Dict[gls_First_Match][2] | |
| -- to make sure that the code is understood as valid html code it must be converted to RawInline with the html input | |
| html_String = pandoc.RawInline('html',long_Term.. " (".. bold_Abbrev .. ")") | |
| local link = pandoc.Link( | |
| html_String , | |
| '../0_Deco/3_Used_Abbrev.qmd'..'#' .. gls_First_Match, | |
| nil, | |
| -- add id and class | |
| {id = gls_First_Match.. "gls", class = 'gls'}) | |
| table.insert(new_content, link) | |
| end | |
| -- ------------------------- gls_Pl_Match ------------------------- -- | |
| if gls_Pl_Match then | |
| has_match = true | |
| long_Term = gls_Dict[gls_Pl_Match][1] | |
| bold_Abbrev = gls_Dict[gls_Pl_Match][2] | |
| -- to make sure that the code is understood as valid html code it must be converted to RawInline with the html input | |
| html_String = pandoc.RawInline('html',long_Term .. "s") | |
| span_Var = pandoc.Span(html_String, | |
| {class = 'gls_Content'}) | |
| -- see: https://pandoc.org/lua-filters.html#pandoc.link | |
| local link = pandoc.Link( | |
| {bold_Abbrev .. "s",span_Var}, | |
| '../0_Deco/3_Used_Abbrev.qmd'..'#' .. gls_Pl_Match, | |
| nil, | |
| -- add id and class | |
| {id = gls_Pl_Match.. "gls", class = 'gls'}) | |
| table.insert(new_content, link) | |
| else | |
| -- Print non-matching text in red | |
| -- io.write('\27[31mNo match found: ' .. text .. '\27[0m\n') | |
| table.insert(new_content, item) | |
| end | |
| else | |
| table.insert(new_content, item) | |
| end | |
| end | |
| -- If no matches were found, return the original element | |
| if not has_match then | |
| -- print("No match found and return simply the regular element") | |
| return elem | |
| end | |
| return pandoc.Para(new_content) | |
| end | |
| return elem | |
| end | |
| -- Export the filter function as a table | |
| return { | |
| {Header = headerfilter}, | |
| {Para = glsfilter} | |
| } | |