From 9ffbfd44c97186e74157f1d09d64d21816d1b2ad Mon Sep 17 00:00:00 2001 From: Robert Alessi Date: Sat, 30 Mar 2019 17:48:35 +0100 Subject: new table for storing all xml:ids --- ekdosis.dtx | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/ekdosis.dtx b/ekdosis.dtx index 91a5662..2245b8d 100644 --- a/ekdosis.dtx +++ b/ekdosis.dtx @@ -565,12 +565,24 @@ local aftercmd = lpeg.Cs(lpeg.S("*[{,.?;:'`\"") + dblbkslash) local cmdargs = lpeg.Cs(spce^-1 * bsqbracketsii * bcbracesii * bsqbrackets^-1) local lemrdg = lpeg.Cs(lpeg.Cs("lem") + lpeg.Cs("rdg")) +-- General +xmlids = {} + +local function xmlidfound(element) + for i = 1,#xmlids do + if xmlids[i].xmlid == element then + return true + end + end + return false +end + -- Witnesses listWit = {} -local function isintable(table, element) +local function isintable(table, value) for i = 1,#table do - if table[i].a == element then + if table[i].a == value then return true end end @@ -580,16 +592,17 @@ end local sorted_no = 0 function ekdosis.newwitness(id, siglum, description) - if isintable(listWit, id..",") + if xmlidfound(id) then tex.print([[\unexpanded{\PackageWarning{ekdosis}{"]] ..id.. - [[" already exists as a witness id. ]] + [[" already exists as a xml:id. ]] .. [[Please pick another id.}}]]) else sorted_no = sorted_no + 1 - id = id.."," + table.insert(xmlids, {xmlid = id}) + table.sort(xmlids, function(a ,b) return(#a.xmlid > #b.xmlid) end) table.insert(listWit, {a = id, b = siglum, c = description, d = sorted_no}) table.sort(listWit, function(a ,b) return(#a.a > #b.a) end) end @@ -602,15 +615,15 @@ function ekdosis.getsiglum(str, opt) ctrl = str if opt == "tei" then for i = 1,#listWit do - str = string.gsub(str, "(%f[%w])"..listWit[i].a, "%1#"..listWit[i].a) - ctrl = string.gsub(ctrl, listWit[i].a, "") + str = string.gsub(str, "(%f[%w])"..listWit[i].a.."(%,)", "%1#"..listWit[i].a.."%2") + ctrl = string.gsub(ctrl, listWit[i].a.."%,", "") end str = string.gsub(str, "%,(%s-)([%#])", " %2") str = string.gsub(str, "%,$", "") else for i = 1,#listWit do - str = string.gsub(str, listWit[i].a, listWit[i].b) - ctrl = string.gsub(ctrl, listWit[i].a, "") + str = string.gsub(str, listWit[i].a.."%,", listWit[i].b) + ctrl = string.gsub(ctrl, listWit[i].a.."%,", "") end end if string.find(ctrl, "[A-Za-z0-9]") @@ -648,7 +661,6 @@ function ekdosis.newcmdtotag(cmd, tag, attr) return true end - local function lem_rdg_totei(str) str = gsub(str, dblbkslash * lemrdg * spcenc^-1 * bsqbrackets * bcbraces, function(bkslash, cmd, opt, arg) -- cgit v1.2.3