From ae1f50d5718a7079efdcf93810416591ddb4aa93 Mon Sep 17 00:00:00 2001
From: Robert Alessi <alessi@robertalessi.net>
Date: Sun, 3 May 2020 19:57:48 +0200
Subject: better linestotei()

---
 ekdosis.dtx | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

(limited to 'ekdosis.dtx')

diff --git a/ekdosis.dtx b/ekdosis.dtx
index b3f6d33..cbd6637 100644
--- a/ekdosis.dtx
+++ b/ekdosis.dtx
@@ -1708,11 +1708,12 @@ local function relocate_notes(str)
 end
 
 local function linestotei(str)
-   str = "\n<l>"..str
+--   str = "\n<l>"..str
+   str = string.gsub(str, "^%s?(.-)%s?$", "\n<l>%1</l>\n")
 --   str = gsub(str, endpoem, "</l>\n")
-   str = gsub(str, poemline * lpeg.P("&gt;"), "\n<lb/>")
-   str = gsub(str, poemline, "</l>\n<l>")
-   str = str.."</l>\n"
+   str = gsub(str, poemline * spcenc^-1 * lpeg.P("&gt;"), "\n<lb/>")
+   str = gsub(str, poemline * spcenc^-1, "</l>\n<l>")
+--   str = str.."</l>\n"
    return str
 end
 
@@ -1852,13 +1853,14 @@ local function cmdtotei(str)
 end
 
 local function partotei(str)
-   str = string.gsub(str, "\\par%s-", "<p>", 1)
-   str = string.gsub(str, "\\par%s-", "</p><p>")
-   str = string.gsub(str, "<p>%s-</p>", "")
-   str = string.gsub(str, "(%<p%>)%s-(%</div%>)$", "%2")
-   str = string.gsub(str, "(%<p%>)%s-$", "")
-   str = string.gsub(str, "(<p>)%s-(<div.->)", "%2%1")
-   str = string.gsub(str, "(%<p%>)%s-(<head>.-</head>)", "%2%1")
+   str = gsub(str, lpeg.P(lpeg.P("\\par") * spcenc^1)^1, "\\par ")
+   str = string.gsub(str, "%s?\\par%s?", "<p>", 1)
+   str = string.gsub(str, "%s?\\par%s?", "</p><p>")
+   str = string.gsub(str, "<p>%s?</p>", "")
+   str = string.gsub(str, "(%<p%>)%s?(%</div%>)$", "%2")
+   str = string.gsub(str, "(%<p%>)%s?$", "")
+   str = string.gsub(str, "(<p>)%s?(<div.->)", "%2%1")
+   str = string.gsub(str, "(%<p%>)%s?(<head>.-</head>)", "%2%1")
    return str
 end
 
-- 
cgit v1.2.3

