From ff786c88dd442a9744f33fe36cf28fdd9be0368e Mon Sep 17 00:00:00 2001
From: Robert Alessi <alessi@robertalessi.net>
Date: Fri, 26 Apr 2019 17:23:47 +0200
Subject: new (experimental) function cleanup_tei()

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

(limited to 'ekdosis.dtx')

diff --git a/ekdosis.dtx b/ekdosis.dtx
index 2d4579c..056d13e 100644
--- a/ekdosis.dtx
+++ b/ekdosis.dtx
@@ -1115,6 +1115,17 @@ end
 
 local tidy = nil
 
+local function cleanup_tei()
+   local f = assert(io.open(teifilename.."_tmp.xml", "r"))
+   t = f:read("*a")
+   t = string.gsub(t, "%<p%>%</p%>\n", "")
+   t = string.gsub(t, "^\n", "")
+   local fw = assert(io.open(teifilename.."_tmp.xml", "w"))
+   fw:write(t)
+   fw:close()
+   return true
+end
+
 function ekdosis.closeteistream(opt)
    local f = io.open(teifilename.."_tmp.xml", "a+")
    f:write("\n", "</body>", "\n")
@@ -1136,6 +1147,7 @@ function ekdosis.closeteistream(opt)
    f:write("</text>", "\n")
    f:write("</TEI>", "\n")
    f:close()
+   cleanup_tei()
    os.remove(teifilename..".xml")
    os.rename(teifilename.."_tmp.xml", teifilename..".xml")
    if opt == "tidy" then
-- 
cgit v1.2.3

