diff options
author | Robert Alessi <alessi@robertalessi.net> | 2020-04-18 00:47:32 +0200 |
---|---|---|
committer | Robert Alessi <alessi@robertalessi.net> | 2020-04-18 00:47:32 +0200 |
commit | 5a2b496bee2c50ba6f8a6cc83cc78de4ea6d44b1 (patch) | |
tree | 33f71875bbc9fd6823c0bbf0972ef6e8b85d0149 | |
parent | b038d096e3f1fa2d40cb29831a3c931c107d8c02 (diff) | |
download | ekdosis-5a2b496bee2c50ba6f8a6cc83cc78de4ea6d44b1.tar.gz |
improved partotei() and added checkpars()
-rw-r--r-- | ekdosis.dtx | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/ekdosis.dtx b/ekdosis.dtx index 9bc6304..fa7c9d5 100644 --- a/ekdosis.dtx +++ b/ekdosis.dtx | |||
@@ -1069,7 +1069,7 @@ Running "make install" installs the files in the local TeX tree. | |||
1069 | \EkdosisOff | 1069 | \EkdosisOff |
1070 | % \EkdosisColStop | 1070 | % \EkdosisColStop |
1071 | \endrunninglinenumbers% | 1071 | \endrunninglinenumbers% |
1072 | \iftei@export\luadirect{ekdosis.exporttei(\luastringN{#1})}\else\fi} | 1072 | \iftei@export\luadirect{ekdosis.exporttei(\luastringN{\par#1\par})}\else\fi} |
1073 | % \end{macrocode} | 1073 | % \end{macrocode} |
1074 | % Alignment:--- | 1074 | % Alignment:--- |
1075 | % \begin{macrocode} | 1075 | % \begin{macrocode} |
@@ -1637,16 +1637,16 @@ local function envtotei(str) | |||
1637 | * lpeg.Cs(envtotags[i].a) * lpeg.P("}") | 1637 | * lpeg.Cs(envtotags[i].a) * lpeg.P("}") |
1638 | * bsqbracketsii * bcbracesii * spcenc^-1, | 1638 | * bsqbracketsii * bcbracesii * spcenc^-1, |
1639 | "</p>\n<"..envtotags[i].b..envtotags[i].c..">") | 1639 | "</p>\n<"..envtotags[i].b..envtotags[i].c..">") |
1640 | str = gsub(str, spcenc^-1 * lpeg.P("\\end") * spcenc^-1 * lpeg.P("{") | ||
1641 | * lpeg.Cs(envtotags[i].a) * lpeg.P("}") * spcenc^-1 * lpeg.P("\\par"), | ||
1642 | "</"..envtotags[i].b..">\n<p>") | ||
1640 | str = gsub(str, lpeg.P("\\begin") * spcenc^-1 * lpeg.P("{") | 1643 | str = gsub(str, lpeg.P("\\begin") * spcenc^-1 * lpeg.P("{") |
1641 | * lpeg.Cs(envtotags[i].a) * lpeg.P("}") | 1644 | * lpeg.Cs(envtotags[i].a) * lpeg.P("}") |
1642 | * bsqbracketsii * bcbracesii * spcenc^-1, | 1645 | * bsqbracketsii * bcbracesii * spcenc^-1, |
1643 | "<"..envtotags[i].b..envtotags[i].c..">") | 1646 | "<"..envtotags[i].b..envtotags[i].c..">") |
1644 | str = gsub(str, spcenc^-1 * lpeg.P("\\end") * spcenc^-1 * lpeg.P("{") | 1647 | str = gsub(str, spcenc^-1 * lpeg.P("\\end") * spcenc^-1 * lpeg.P("{") |
1645 | * lpeg.Cs(envtotags[i].a) * lpeg.P("}" * spcenc^-1 * lpeg.P("\\par")), | ||
1646 | "</"..envtotags[i].b..">\n<p>") | ||
1647 | str = gsub(str, spcenc^-1 * lpeg.P("\\end") * spcenc^-1 * lpeg.P("{") | ||
1648 | * lpeg.Cs(envtotags[i].a) * lpeg.P("}"), | 1648 | * lpeg.Cs(envtotags[i].a) * lpeg.P("}"), |
1649 | "</"..envtotags[i].b..">") | 1649 | "</"..envtotags[i].b..">\n<p>") |
1650 | else | 1650 | else |
1651 | str = gsub(str, lpeg.P("\\begin") * spcenc^-1 * lpeg.P("{") | 1651 | str = gsub(str, lpeg.P("\\begin") * spcenc^-1 * lpeg.P("{") |
1652 | * lpeg.Cs(envtotags[i].a) * lpeg.P("}") | 1652 | * lpeg.Cs(envtotags[i].a) * lpeg.P("}") |
@@ -1741,6 +1741,28 @@ local function partotei(str) | |||
1741 | return str | 1741 | return str |
1742 | end | 1742 | end |
1743 | 1743 | ||
1744 | local function checkpars(str) | ||
1745 | for i = 1,#envtotags | ||
1746 | do | ||
1747 | if isfound(close_p, envtotags[i].b) | ||
1748 | then | ||
1749 | str = string.gsub(str, "(%<p[%>%s])(.-<"..envtotags[i].b.."[%>%s])", function(par, substr_tag) | ||
1750 | substr_tag = checkpars(substr_tag) | ||
1751 | substr = string.gsub(substr_tag, "(.-)(<"..envtotags[i].b.."[%>%s])", "%1") | ||
1752 | tag = string.gsub(substr_tag, "(.-)(<"..envtotags[i].b.."[%>%s])", "%2") | ||
1753 | if string.find(substr, "<%/p[%>%s]") | ||
1754 | then | ||
1755 | return string.format("%s%s%s", par, substr, tag) | ||
1756 | else | ||
1757 | return string.format("%s%s</p>%s", par, substr, tag) | ||
1758 | end | ||
1759 | end) | ||
1760 | else | ||
1761 | end | ||
1762 | end | ||
1763 | return str | ||
1764 | end | ||
1765 | |||
1744 | local function textotei(str) | 1766 | local function textotei(str) |
1745 | str = xml_entities(str) | 1767 | str = xml_entities(str) |
1746 | str = texpatttotei(str) | 1768 | str = texpatttotei(str) |
@@ -1758,6 +1780,7 @@ local function textotei(str) | |||
1758 | str = envtotei(str) | 1780 | str = envtotei(str) |
1759 | str = cmdtotei(str) | 1781 | str = cmdtotei(str) |
1760 | str = partotei(str) | 1782 | str = partotei(str) |
1783 | str = checkpars(str) | ||
1761 | return str | 1784 | return str |
1762 | end | 1785 | end |
1763 | 1786 | ||
@@ -1856,8 +1879,9 @@ local tidy = nil | |||
1856 | local function cleanup_tei() | 1879 | local function cleanup_tei() |
1857 | local f = assert(io.open(teifilename.."_tmp.xml", "r")) | 1880 | local f = assert(io.open(teifilename.."_tmp.xml", "r")) |
1858 | t = f:read("*a") | 1881 | t = f:read("*a") |
1859 | t = string.gsub(t, "%<p%>%</p%>\n", "") | 1882 | t = string.gsub(t, "%<p%>%s?%</p%>", "") |
1860 | t = string.gsub(t, "^\n", "") | 1883 | t = string.gsub(t, "^\n", "") |
1884 | f:close() | ||
1861 | local fw = assert(io.open(teifilename.."_tmp.xml", "w")) | 1885 | local fw = assert(io.open(teifilename.."_tmp.xml", "w")) |
1862 | fw:write(t) | 1886 | fw:write(t) |
1863 | fw:close() | 1887 | fw:close() |
@@ -2061,7 +2085,7 @@ function ekdosis.mkenv() | |||
2061 | .."\\end{nthcolumn}" | 2085 | .."\\end{nthcolumn}" |
2062 | .."\\csname iftei@export\\endcsname\\luadirect{ekdosis.storecoldata(" | 2086 | .."\\csname iftei@export\\endcsname\\luadirect{ekdosis.storecoldata(" |
2063 | .. aligned_texts[i].column | 2087 | .. aligned_texts[i].column |
2064 | ..", \\luastringN{#1})}\\fi" | 2088 | ..", \\luastringN{\\par#1\\par})}\\fi" |
2065 | .."}") | 2089 | .."}") |
2066 | table.insert(environments, "\\NewDocumentEnvironment{".. aligned_texts[i].text.."*}{+b}" | 2090 | table.insert(environments, "\\NewDocumentEnvironment{".. aligned_texts[i].text.."*}{+b}" |
2067 | .."{\\begin{nthcolumn*}{".. aligned_texts[i].column.."}[]" | 2091 | .."{\\begin{nthcolumn*}{".. aligned_texts[i].column.."}[]" |
@@ -2073,7 +2097,7 @@ function ekdosis.mkenv() | |||
2073 | .."\\end{nthcolumn*}" | 2097 | .."\\end{nthcolumn*}" |
2074 | .."\\csname iftei@export\\endcsname\\luadirect{ekdosis.storecoldata(" | 2098 | .."\\csname iftei@export\\endcsname\\luadirect{ekdosis.storecoldata(" |
2075 | .. aligned_texts[i].column | 2099 | .. aligned_texts[i].column |
2076 | ..", \\luastringN{#1})}\\fi" | 2100 | ..", \\luastringN{\\par#1\\par})}\\fi" |
2077 | .."}") | 2101 | .."}") |
2078 | else | 2102 | else |
2079 | table.insert(environments, "\\NewDocumentEnvironment{".. aligned_texts[i].text.."}{+b}" | 2103 | table.insert(environments, "\\NewDocumentEnvironment{".. aligned_texts[i].text.."}{+b}" |
@@ -2083,7 +2107,7 @@ function ekdosis.mkenv() | |||
2083 | .."}{\\end{nthcolumn}" | 2107 | .."}{\\end{nthcolumn}" |
2084 | .."\\csname iftei@export\\endcsname\\luadirect{ekdosis.storecoldata(" | 2108 | .."\\csname iftei@export\\endcsname\\luadirect{ekdosis.storecoldata(" |
2085 | .. aligned_texts[i].column | 2109 | .. aligned_texts[i].column |
2086 | ..", \\luastringN{#1})}\\fi" | 2110 | ..", \\luastringN{\\par#1\\par})}\\fi" |
2087 | .."}") | 2111 | .."}") |
2088 | table.insert(environments, "\\NewDocumentEnvironment{".. aligned_texts[i].text.."*}{+b}" | 2112 | table.insert(environments, "\\NewDocumentEnvironment{".. aligned_texts[i].text.."*}{+b}" |
2089 | .."{\\begin{nthcolumn*}{"..aligned_texts[i].column.."}[]" | 2113 | .."{\\begin{nthcolumn*}{"..aligned_texts[i].column.."}[]" |
@@ -2093,7 +2117,7 @@ function ekdosis.mkenv() | |||
2093 | .."\\end{nthcolumn*}" | 2117 | .."\\end{nthcolumn*}" |
2094 | .."\\csname iftei@export\\endcsname\\luadirect{ekdosis.storecoldata(" | 2118 | .."\\csname iftei@export\\endcsname\\luadirect{ekdosis.storecoldata(" |
2095 | .. aligned_texts[i].column | 2119 | .. aligned_texts[i].column |
2096 | ..", \\luastringN{#1})}\\fi" | 2120 | ..", \\luastringN{\\par#1\\par})}\\fi" |
2097 | .."}") | 2121 | .."}") |
2098 | end | 2122 | end |
2099 | end | 2123 | end |