From 33f82d0b5dd71e4a3bf69aee538bba8c86038e61 Mon Sep 17 00:00:00 2001
From: Robert Alessi <alessi@robertalessi.net>
Date: Sun, 7 Mar 2021 21:01:58 +0100
Subject: better handling of patterns in linestotei() and versetotei()

---
 ekdosis.dtx | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

(limited to 'ekdosis.dtx')

diff --git a/ekdosis.dtx b/ekdosis.dtx
index 36d6e8c..0badedd 100644
--- a/ekdosis.dtx
+++ b/ekdosis.dtx
@@ -3052,11 +3052,11 @@ texts=latin[xml:lang="la"]+\textcolor{red}{;}+
 % \DescribeOption{lang} |lang|$=$\meta{languagename}
 % \newfeature[v1.2]\label{ref:app-lang-opt}
 % \hfill\tcboxverb{Default: not set}\\
-% |lang=<languagename>| is used as described \vpageref{ref:app-lang}
-% when it is needed to apply in the apparatus criticus a language
-% different from the one that is selected in the edition
-% text. |languagename| can be any value accepted by \pkg{babel} or
-% \pkg{polyglossia}.
+% |lang=<languagename>| is used as described
+% \vpageref[above]{ref:app-lang} when it is needed to apply in the
+% apparatus criticus a language different from the one that is
+% selected in the edition text. |languagename| can be any value
+% accepted by \pkg{babel} or \pkg{polyglossia}.
 % 
 % As an example, an apparatus criticus with references to line numbers
 % printed in normal font, a colon as a separator between lemma texts
@@ -8050,8 +8050,8 @@ local app = lpeg.Cs("app")
 local lemrdg = lpeg.Cs(lpeg.Cs("lem") + lpeg.Cs("rdg"))
 local note = lpeg.Cs("note")
 local lnbrk = lpeg.Cs("\\\\")
-local poemline = lpeg.Cs(lnbrk * spcenc^-1 * lpeg.S("*!")^-1 * bsqbrackets^-1)
-local poemlineb = lpeg.Cs(lnbrk * spcenc^-1 * lpeg.P("&gt;") * bsqbrackets^-1)
+local poemline = lpeg.Cs(lnbrk * spcenc^-1 * lpeg.S("*!")^-1 * bsqbrackets^-1 * spcenc^-1)
+local poemlineb = lpeg.Cs(lnbrk * spcenc^-1 * lpeg.P("&gt;") * bsqbrackets^-1 * spcenc^-1)
 local endpoem = lpeg.Cs(lnbrk * lpeg.S("*!") * bsqbrackets^-1)
 local sections = lpeg.Cs(lpeg.P("book") + lpeg.P("part") + lpeg.P("chapter")
 			    + lpeg.P("section") + lpeg.P("subsection")
@@ -8651,7 +8651,7 @@ local function linestotei(str)
 --   str = string.gsub(str, "^%s?(.-)\\\\[%!%*]?%s?$", "\n<l>%1</l>\n")
    str = gsub(str, poemline * spcenc^-1 * -1, "</l>\n")
 --   str = gsub(str, endpoem, "</l>\n")
-   str = gsub(str, poemlineb, "\n<lb/>")
+   str = gsub(str, poemlineb, "<lb/> ")
    str = gsub(str, poemline, "</l>\n<l>")
 --   str = str.."</l>\n"
    return str
@@ -8660,18 +8660,22 @@ end
 -- better use lpeg: look into this later
 local function versetotei(str)
    str = string.gsub(str, "(\\begin%s?%{ekdverse%})(%b[])(.-)(\\end%s?%{ekdverse%})", function(benv, opt, arg, eenv)
+			arg = string.gsub(arg, "\\par%s?", "")
 			arg = linestotei(arg)
 			return string.format("%s%s%s%s", benv, opt, arg, eenv)
    end)
    str = string.gsub(str, "(\\begin%s?%{ekdverse%})(.-)(\\end%s?%{ekdverse%})", function(benv, arg, eenv)
+			arg = string.gsub(arg, "\\par%s?", "")
 			arg = linestotei(arg)
 			return string.format("%s%s%s", benv, arg, eenv)
    end)
    str = string.gsub(str, "(\\begin%s?%{verse%})(%b[])(.-)(\\end%s?%{verse%})", function(benv, opt, arg, eenv)
+			arg = string.gsub(arg, "\\par%s?", "")
 			arg = linestotei(arg)
 			return string.format("%s%s%s%s", benv, opt, arg, eenv)
    end)
    str = string.gsub(str, "(\\begin%s?%{verse%})(.-)(\\end%s?%{verse%})", function(benv, arg, eenv)
+			arg = string.gsub(arg, "\\par%s?", "")
 			arg = linestotei(arg)
 			return string.format("%s%s%s", benv, arg, eenv)
    end)
-- 
cgit v1.2.3

