From 2dffe397f9a027ae551037e6f1c0b27e2350bf08 Mon Sep 17 00:00:00 2001 From: Robert Alessi Date: Tue, 28 Apr 2020 16:51:04 +0200 Subject: handle inconsistently numbered divs --- ekdosis.dtx | 62 +++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 18 deletions(-) (limited to 'ekdosis.dtx') diff --git a/ekdosis.dtx b/ekdosis.dtx index 5ec9df1..e46a6d5 100644 --- a/ekdosis.dtx +++ b/ekdosis.dtx @@ -1843,7 +1843,9 @@ local function section_totei(str) return str end -local function close_divs_at_end(str) +local used_ndivs = {} + +local function close_ndivs_at_end(str) local isdiv = false if string.find(str, "$") then @@ -1851,17 +1853,36 @@ local function close_divs_at_end(str) str = string.gsub(str, "(.*)()$", "%1") else end - firstdiv = string.match(str, " #b.a) end) + else + end + local firstdiv = string.match(str, "= firstdiv + while lastdivindex >= firstdivindex do - closedivs = closedivs.."" - lastdiv = lastdiv - 1 + closedivs = closedivs.."" + lastdivindex = lastdivindex - 1 end end -- str = string.gsub(str, "()", "%1%3") @@ -1873,20 +1894,24 @@ local function close_divs_at_end(str) end end -local function close_divs_in_between(str) +local function close_ndivs_in_between(str) for ndivi = 0, 9 do str = string.gsub(str, "()(.-)()", function(bdivi, ndivi, edivi, between, bdivii, ndivii, edivii) - firstdiv = tonumber(ndivi) - lastdiv = tonumber(ndivii) + local firstdiv = ndivi + local lastdiv = ndivii + local firstdivindex = get_a_index(firstdiv, used_ndivs) + local lastdivindex = get_a_index(lastdiv, used_ndivs) + firstdivindex = tonumber(firstdivindex) + lastdivindex = tonumber(lastdivindex) local closedivs = "" - if firstdiv >= lastdiv + if firstdivindex >= lastdivindex then - while firstdiv >= lastdiv + while firstdivindex >= lastdivindex do - closedivs = closedivs.."" - firstdiv = firstdiv - 1 + closedivs = closedivs.."" + firstdivindex = firstdivindex - 1 end end return string.format("%s%s%s%s%s%s%s%s", @@ -1894,6 +1919,7 @@ local function close_divs_in_between(str) end) end + used_ndivs = {} return str end @@ -1911,8 +1937,8 @@ local function textotei(str) str = self_close_tags(str) str = partotei(str) str = checkpars(str) - str = close_divs_at_end(str) - str = close_divs_in_between(str) + str = close_ndivs_at_end(str) + str = close_ndivs_in_between(str) return str end -- cgit v1.2.3