diff options
-rw-r--r-- | ekdosis.dtx | 96 |
1 files changed, 92 insertions, 4 deletions
diff --git a/ekdosis.dtx b/ekdosis.dtx index 41025b5..a30f801 100644 --- a/ekdosis.dtx +++ b/ekdosis.dtx | |||
@@ -1080,7 +1080,7 @@ Running "make install" installs the files in the local TeX tree. | |||
1080 | \EkdosisOff | 1080 | \EkdosisOff |
1081 | % \EkdosisColStop | 1081 | % \EkdosisColStop |
1082 | \endrunninglinenumbers% | 1082 | \endrunninglinenumbers% |
1083 | \iftei@export\luadirect{ekdosis.exporttei(\luastringN{\par#1\par})}\else\fi} | 1083 | \iftei@export\luadirect{ekdosis.exporttei(\luastringN{\par #1\par })}\else\fi} |
1084 | % \end{macrocode} | 1084 | % \end{macrocode} |
1085 | % Alignment:--- | 1085 | % Alignment:--- |
1086 | % \begin{macrocode} | 1086 | % \begin{macrocode} |
@@ -1990,8 +1990,13 @@ local function ekddivs_totei(str) | |||
1990 | -- | 1990 | -- |
1991 | if teitype ~= "" then teitype = " type=\""..teitype.."\"" else end | 1991 | if teitype ~= "" then teitype = " type=\""..teitype.."\"" else end |
1992 | if tein ~= "" then tein = " n=\""..tein.."\"" else end | 1992 | if tein ~= "" then tein = " n=\""..tein.."\"" else end |
1993 | if teidepth ~= "" then teidepth = " depth=\""..teidepth.."\"" else end | 1993 | if teidepth ~= "" |
1994 | return string.format("<div%s%s%s/><head>%s</head>", | 1994 | then |
1995 | teidepth = " depth=\""..teidepth.."\"" | ||
1996 | else | ||
1997 | teidepth = " depth=\"1\"" | ||
1998 | end | ||
1999 | return string.format("\\p@rb <div%s%s%s><head>%s</head>\\p@ra ", | ||
1995 | teitype, tein, teidepth, teihead) | 2000 | teitype, tein, teidepth, teihead) |
1996 | else | 2001 | else |
1997 | return "" | 2002 | return "" |
@@ -2019,6 +2024,58 @@ end | |||
2019 | 2024 | ||
2020 | local used_ndivs = {} | 2025 | local used_ndivs = {} |
2021 | 2026 | ||
2027 | local function close_ekddivs_at_end(str) | ||
2028 | local isdiv = false | ||
2029 | if string.find(str, "</div>$") | ||
2030 | then | ||
2031 | isdiv = true | ||
2032 | str = string.gsub(str, "(.*)(</div>)$", "%1") | ||
2033 | else | ||
2034 | end | ||
2035 | -- collect used depth numbers | ||
2036 | for i in string.gmatch(str, "<div .-depth%=\"%d\".->") | ||
2037 | do | ||
2038 | i = string.match(i, "depth=\"%d\"") | ||
2039 | i = string.match(i, "%d") | ||
2040 | if isintable(used_ndivs, i) | ||
2041 | then | ||
2042 | else | ||
2043 | table.insert(used_ndivs, {a = i} ) | ||
2044 | end | ||
2045 | end | ||
2046 | if next(used_ndivs) ~= nil | ||
2047 | then | ||
2048 | table.sort(used_ndivs, function(a ,b) return(#a.a > #b.a) end) | ||
2049 | else | ||
2050 | end | ||
2051 | local firstdiv = string.match(str, "<div .-depth%=\"%d\".->") or "" | ||
2052 | firstdiv = string.match(firstdiv, "depth%=\"%d\"") or "" | ||
2053 | firstdiv = string.match(firstdiv, "%d") or "" | ||
2054 | local lastdiv = string.match(string.reverse(str), ">.-\"%d\"%=htped.- vid<") or "" | ||
2055 | lastdiv = string.match(lastdiv, "\"%d\"%=htped") or "" | ||
2056 | lastdiv = string.match(lastdiv, "%d") or "" | ||
2057 | local firstdivindex = get_a_index(firstdiv, used_ndivs) | ||
2058 | local lastdivindex = get_a_index(lastdiv, used_ndivs) | ||
2059 | firstdivindex = tonumber(firstdivindex) | ||
2060 | lastdivindex = tonumber(lastdivindex) | ||
2061 | local closedivs = "" | ||
2062 | if isintable(used_ndivs, firstdiv) | ||
2063 | then | ||
2064 | while lastdivindex >= firstdivindex | ||
2065 | do | ||
2066 | closedivs = closedivs.."</div>" | ||
2067 | lastdivindex = lastdivindex - 1 | ||
2068 | end | ||
2069 | end | ||
2070 | -- str = string.gsub(str, "(<div)([1-6])(.->)", "%1%3") | ||
2071 | if isdiv | ||
2072 | then | ||
2073 | return str..closedivs.."</div>" | ||
2074 | else | ||
2075 | return str..closedivs | ||
2076 | end | ||
2077 | end | ||
2078 | |||
2022 | local function close_ndivs_at_end(str) | 2079 | local function close_ndivs_at_end(str) |
2023 | local isdiv = false | 2080 | local isdiv = false |
2024 | if string.find(str, "</div>$") | 2081 | if string.find(str, "</div>$") |
@@ -2068,8 +2125,37 @@ local function close_ndivs_at_end(str) | |||
2068 | end | 2125 | end |
2069 | end | 2126 | end |
2070 | 2127 | ||
2128 | local function close_ekddivs_in_between(str) | ||
2129 | for ndivi = 1, 7 | ||
2130 | do | ||
2131 | str = string.gsub(str, "(<div .-depth%=\")("..ndivi..")(\".->)(.-)(<div .-depth%=\")(%d)(\".->)", | ||
2132 | function(bdivi, ndivi, edivi, between, bdivii, ndivii, edivii) | ||
2133 | local firstdiv = ndivi | ||
2134 | local lastdiv = ndivii | ||
2135 | local firstdivindex = get_a_index(firstdiv, used_ndivs) | ||
2136 | local lastdivindex = get_a_index(lastdiv, used_ndivs) | ||
2137 | firstdivindex = tonumber(firstdivindex) | ||
2138 | lastdivindex = tonumber(lastdivindex) | ||
2139 | local closedivs = "" | ||
2140 | if firstdivindex >= lastdivindex | ||
2141 | then | ||
2142 | while firstdivindex >= lastdivindex | ||
2143 | do | ||
2144 | closedivs = closedivs.."</div>" | ||
2145 | firstdivindex = firstdivindex - 1 | ||
2146 | end | ||
2147 | end | ||
2148 | return string.format("%s%s%s%s%s%s%s%s", | ||
2149 | bdivi, ndivi, edivi, between, closedivs, bdivii, ndivii, edivii) | ||
2150 | end) | ||
2151 | end | ||
2152 | str = string.gsub(str, "(<div.-)(%sdepth%=\"%d\")(.->)", "%1%3") | ||
2153 | used_ndivs = {} | ||
2154 | return str | ||
2155 | end | ||
2156 | |||
2071 | local function close_ndivs_in_between(str) | 2157 | local function close_ndivs_in_between(str) |
2072 | for ndivi = 0, 9 | 2158 | for ndivi = 0, 6 |
2073 | do | 2159 | do |
2074 | str = string.gsub(str, "(<div)("..ndivi..")(.->)(.-)(<div)([1-6])(.->)", | 2160 | str = string.gsub(str, "(<div)("..ndivi..")(.->)(.-)(<div)([1-6])(.->)", |
2075 | function(bdivi, ndivi, edivi, between, bdivii, ndivii, edivii) | 2161 | function(bdivi, ndivi, edivi, between, bdivii, ndivii, edivii) |
@@ -2114,6 +2200,8 @@ local function textotei(str) | |||
2114 | -- str = checkpars(str) | 2200 | -- str = checkpars(str) |
2115 | if ekddivs | 2201 | if ekddivs |
2116 | then | 2202 | then |
2203 | str = close_ekddivs_at_end(str) | ||
2204 | str = close_ekddivs_in_between(str) | ||
2117 | else | 2205 | else |
2118 | str = close_ndivs_at_end(str) | 2206 | str = close_ndivs_at_end(str) |
2119 | str = close_ndivs_in_between(str) | 2207 | str = close_ndivs_in_between(str) |