diff options
author | Robert Alessi <alessi@robertalessi.net> | 2019-05-07 15:18:28 +0200 |
---|---|---|
committer | Robert Alessi <alessi@robertalessi.net> | 2019-05-07 15:18:28 +0200 |
commit | 3c7f90b3b3ba2bfb9fd7dc0ccd67f6a0584c00b4 (patch) | |
tree | 445d24d2c241de6a971c31e9babdbb11d208d980 /ekdosis.dtx | |
parent | 7aa2b0c21de0f45a4e350893077d706ad678d25b (diff) | |
download | ekdosis-3c7f90b3b3ba2bfb9fd7dc0ccd67f6a0584c00b4.tar.gz |
new function versetotei(). added star option to \EnvtoTEI{} that instructs ekdosis to close <p> if it is open
Diffstat (limited to 'ekdosis.dtx')
-rw-r--r-- | ekdosis.dtx | 62 |
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) | |||
673 | local aftercmd = lpeg.Cs(lpeg.S("*[{,.?;:'`\"") + dblbkslash) | 680 | local aftercmd = lpeg.Cs(lpeg.S("*[{,.?;:'`\"") + dblbkslash) |
674 | local cmdargs = lpeg.Cs(spce^-1 * bsqbracketsii * bcbracesii * bsqbrackets^-1) | 681 | local cmdargs = lpeg.Cs(spce^-1 * bsqbracketsii * bcbracesii * bsqbrackets^-1) |
675 | local lemrdg = lpeg.Cs(lpeg.Cs("lem") + lpeg.Cs("rdg")) | 682 | local lemrdg = lpeg.Cs(lpeg.Cs("lem") + lpeg.Cs("rdg")) |
683 | local lnbrk = lpeg.Cs("\\\\") | ||
684 | local poemline = lpeg.Cs(lnbrk * lpeg.S(">")^-1 * bsqbrackets^-1) | ||
685 | local endpoem = lpeg.Cs(lnbrk * lpeg.S("*!") * bsqbrackets^-1) | ||
676 | 686 | ||
677 | -- Booleans | 687 | -- Booleans |
678 | local tei_p_open = false | 688 | local tei_p_open = false |
@@ -694,6 +704,15 @@ listWit = {} | |||
694 | idsRend = {} | 704 | idsRend = {} |
695 | shorthands = {} | 705 | shorthands = {} |
696 | 706 | ||
707 | local 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 | ||
714 | end | ||
715 | |||
697 | local function isintable(table, value) | 716 | local 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 | ||
869 | local envtotags = { | 888 | local 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 | ||
895 | local close_p = { | ||
896 | "p", | ||
897 | "lg" | ||
898 | } | ||
899 | |||
875 | function ekdosis.newcmdtotag(cmd, tag, attr) | 900 | function 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 |
888 | end | 913 | end |
889 | 914 | ||
890 | function ekdosis.newenvtotag(env, tag, attr) | 915 | function 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 |
903 | end | 931 | end |
@@ -931,10 +959,31 @@ local function lem_rdg_totei(str) | |||
931 | return str | 959 | return str |
932 | end | 960 | end |
933 | 961 | ||
962 | local 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 | ||
967 | end | ||
968 | |||
969 | -- better use lpeg: look into this later | ||
970 | local 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 | ||
980 | end | ||
981 | |||
934 | local function envtotei(str) | 982 | local 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 |