aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Alessi <alessi@robertalessi.net>2019-05-07 15:18:28 +0200
committerRobert Alessi <alessi@robertalessi.net>2019-05-07 15:18:28 +0200
commit3c7f90b3b3ba2bfb9fd7dc0ccd67f6a0584c00b4 (patch)
tree445d24d2c241de6a971c31e9babdbb11d208d980
parent7aa2b0c21de0f45a4e350893077d706ad678d25b (diff)
downloadekdosis-3c7f90b3b3ba2bfb9fd7dc0ccd67f6a0584c00b4.tar.gz
new function versetotei(). added star option to \EnvtoTEI{} that instructs ekdosis to close <p> if it is open
-rw-r--r--ekdosis.dtx62
1 files changed, 56 insertions, 6 deletions
diff --git a/ekdosis.dtx b/ekdosis.dtx
index e612149..138b0a8 100644
--- a/ekdosis.dtx
+++ b/ekdosis.dtx
@@ -425,10 +425,17 @@ idno={}, msName={}, origDate={}][3]{%
425 \luastringN{#2}, 425 \luastringN{#2},
426 \luastringN{#3})} 426 \luastringN{#3})}
427} 427}
428\NewDocumentCommand{\EnvtoTEI}{m m m}{% 428\NewDocumentCommand{\EnvtoTEI}{s m m m}{%
429 \luadirect{ekdosis.newenvtotag(\luastringN{#1}, 429 \IfBooleanTF{#1}{%
430 \luastringN{#2}, 430 \luadirect{ekdosis.newenvtotag(\luastringN{#2},
431 \luastringN{#3})} 431 \luastringN{#3},
432 \luastringN{#4},
433 "yes")}
434 }{%
435 \luadirect{ekdosis.newenvtotag(\luastringN{#2},
436 \luastringN{#3},
437 \luastringN{#4})}
438 }
432} 439}
433% \end{macrocode} 440% \end{macrocode}
434% Set |TEI| file name 441% Set |TEI| file name
@@ -673,6 +680,9 @@ local rawcmd = lpeg.Cs(dblbkslash * ascii^1)
673local aftercmd = lpeg.Cs(lpeg.S("*[{,.?;:'`\"") + dblbkslash) 680local aftercmd = lpeg.Cs(lpeg.S("*[{,.?;:'`\"") + dblbkslash)
674local cmdargs = lpeg.Cs(spce^-1 * bsqbracketsii * bcbracesii * bsqbrackets^-1) 681local cmdargs = lpeg.Cs(spce^-1 * bsqbracketsii * bcbracesii * bsqbrackets^-1)
675local lemrdg = lpeg.Cs(lpeg.Cs("lem") + lpeg.Cs("rdg")) 682local lemrdg = lpeg.Cs(lpeg.Cs("lem") + lpeg.Cs("rdg"))
683local lnbrk = lpeg.Cs("\\\\")
684local poemline = lpeg.Cs(lnbrk * lpeg.S(">")^-1 * bsqbrackets^-1)
685local endpoem = lpeg.Cs(lnbrk * lpeg.S("*!") * bsqbrackets^-1)
676 686
677-- Booleans 687-- Booleans
678local tei_p_open = false 688local tei_p_open = false
@@ -694,6 +704,15 @@ listWit = {}
694idsRend = {} 704idsRend = {}
695shorthands = {} 705shorthands = {}
696 706
707local function isfound(table, value)
708 for i = 1,#table do
709 if table[i] == value then
710 return true
711 end
712 end
713 return false
714end
715
697local function isintable(table, value) 716local function isintable(table, value)
698 for i = 1,#table do 717 for i = 1,#table do
699 if table[i].a == value then 718 if table[i].a == value then
@@ -868,10 +887,16 @@ local cmdtotags = {
868 887
869local envtotags = { 888local envtotags = {
870 {a="center", b="p", c=" rend=\"centered\""}, 889 {a="center", b="p", c=" rend=\"centered\""},
890 {a="verse", b="lg", c=""},
871 {a="arab", b="p", 891 {a="arab", b="p",
872 c=" xml:lang=\"arb-Latn\" type=\"transliterated\" subtype=\"arabtex\""} 892 c=" xml:lang=\"arb-Latn\" type=\"transliterated\" subtype=\"arabtex\""}
873} 893}
874 894
895local close_p = {
896 "p",
897 "lg"
898}
899
875function ekdosis.newcmdtotag(cmd, tag, attr) 900function ekdosis.newcmdtotag(cmd, tag, attr)
876 if isintable(cmdtotags, cmd) 901 if isintable(cmdtotags, cmd)
877 then 902 then
@@ -887,7 +912,7 @@ function ekdosis.newcmdtotag(cmd, tag, attr)
887 return true 912 return true
888end 913end
889 914
890function ekdosis.newenvtotag(env, tag, attr) 915function ekdosis.newenvtotag(env, tag, attr, closep)
891 if isintable(envtotags, env) 916 if isintable(envtotags, env)
892 then 917 then
893 tex.print([[\unexpanded{\PackageWarning{ekdosis}{"]] 918 tex.print([[\unexpanded{\PackageWarning{ekdosis}{"]]
@@ -898,6 +923,9 @@ function ekdosis.newenvtotag(env, tag, attr)
898 else 923 else
899 table.insert(envtotags, {a = env, b = tag, c = " "..attr}) 924 table.insert(envtotags, {a = env, b = tag, c = " "..attr})
900 table.sort(envtotags, function(a ,b) return(#a.a > #b.a) end) 925 table.sort(envtotags, function(a ,b) return(#a.a > #b.a) end)
926 if closep == "yes" then
927 table.insert(close_p, tag)
928 else end
901 end 929 end
902 return true 930 return true
903end 931end
@@ -931,10 +959,31 @@ local function lem_rdg_totei(str)
931 return str 959 return str
932end 960end
933 961
962local function linestotei(str)
963 str = "\n<l>"..str
964 str = gsub(str, endpoem, "</l>\n")
965 str = gsub(str, poemline, "</l>\n<l>")
966 return str
967end
968
969-- better use lpeg: look into this later
970local function versetotei(str)
971 str = string.gsub(str, "(\\begin%s?%{verse%})(%b[])(.-)(\\end%s?%{verse%})", function(benv, opt, arg, eenv)
972 arg = linestotei(arg)
973 return string.format("%s%s%s%s", benv, opt, arg, eenv)
974 end)
975 str = string.gsub(str, "(\\begin%s?%{verse%})(.-)(\\end%s?%{verse%})", function(benv, arg, eenv)
976 arg = linestotei(arg)
977 return string.format("%s%s%s", benv, arg, eenv)
978 end)
979 return str
980end
981
934local function envtotei(str) 982local function envtotei(str)
935 for i = 1,#envtotags 983 for i = 1,#envtotags
936 do 984 do
937 if tei_p_open and envtotags[i].b == "p" 985 -- if tei_p_open and envtotags[i].b == "p" or envtotags[i].b == "lg"
986 if tei_p_open and isfound(close_p, envtotags[i].b)
938 then 987 then
939 str = gsub(str, lpeg.P("\\begin") * spcenc^-1 * lpeg.P("{") 988 str = gsub(str, lpeg.P("\\begin") * spcenc^-1 * lpeg.P("{")
940 * lpeg.Cs(envtotags[i].a) * lpeg.P("}") 989 * lpeg.Cs(envtotags[i].a) * lpeg.P("}")
@@ -1008,6 +1057,7 @@ local function textotei(str)
1008 tei_p_open = true 1057 tei_p_open = true
1009 end 1058 end
1010 str = lem_rdg_totei(str) 1059 str = lem_rdg_totei(str)
1060 str = versetotei(str)
1011 str = envtotei(str) 1061 str = envtotei(str)
1012 str = cmdtotei(str) 1062 str = cmdtotei(str)
1013 return str 1063 return str