diff options
author | Robert Alessi <alessi@robertalessi.net> | 2019-04-10 16:52:21 +0200 |
---|---|---|
committer | Robert Alessi <alessi@robertalessi.net> | 2019-04-10 16:52:21 +0200 |
commit | 04c2290b7aab466cbcfbfdf4fb660f8aa0121883 (patch) | |
tree | e48613d63b6de3cfc78c089f4394e48be72e7d6d | |
parent | 57c929bb3bb62c9b8d83440f2cf349e7e058605e (diff) | |
download | ekdosis-04c2290b7aab466cbcfbfdf4fb660f8aa0121883.tar.gz |
moved xml entities to a function out of the recursion of textotei()
-rw-r--r-- | ekdosis.dtx | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/ekdosis.dtx b/ekdosis.dtx index deb5a4b..37fab9d 100644 --- a/ekdosis.dtx +++ b/ekdosis.dtx | |||
@@ -774,6 +774,12 @@ function ekdosis.newcmdtotag(cmd, tag, attr) | |||
774 | return true | 774 | return true |
775 | end | 775 | end |
776 | 776 | ||
777 | local function xml_entities(str) | ||
778 | str = string.gsub(str, "%<", "<") | ||
779 | str = string.gsub(str, "%>", ">") | ||
780 | return str | ||
781 | end | ||
782 | |||
777 | local function lem_rdg_totei(str) | 783 | local function lem_rdg_totei(str) |
778 | str = gsub(str, dblbkslash * lemrdg * spcenc^-1 * bsqbrackets * bcbraces * spcenc^-1, | 784 | str = gsub(str, dblbkslash * lemrdg * spcenc^-1 * bsqbrackets * bcbraces * spcenc^-1, |
779 | function(bkslash, cmd, opt, arg) | 785 | function(bkslash, cmd, opt, arg) |
@@ -790,11 +796,7 @@ local function lem_rdg_totei(str) | |||
790 | return str | 796 | return str |
791 | end | 797 | end |
792 | 798 | ||
793 | function ekdosis.textotei(str) | 799 | local function textotei(str) |
794 | str = string.gsub(str, "%s?\\par%s?", "</p>\n<p>") | ||
795 | str = string.gsub(str, "%<", "<") | ||
796 | str = string.gsub(str, "%>", ">") | ||
797 | str = lem_rdg_totei(str) | ||
798 | for i = 1,#cmdtotags | 800 | for i = 1,#cmdtotags |
799 | do | 801 | do |
800 | str = string.gsub(str, "(\\"..cmdtotags[i].a..")%s?%*?(%b{})", "%1[]%2") | 802 | str = string.gsub(str, "(\\"..cmdtotags[i].a..")%s?%*?(%b{})", "%1[]%2") |
@@ -806,7 +808,7 @@ function ekdosis.textotei(str) | |||
806 | braces = string.sub(braces, 2, -2) | 808 | braces = string.sub(braces, 2, -2) |
807 | return string.format("\"%s\"", braces) | 809 | return string.format("\"%s\"", braces) |
808 | end) | 810 | end) |
809 | body = ekdosis.textotei(body) | 811 | body = textotei(body) |
810 | -- return string.format("<"..cmdtotags[i].b..cmdtotags[i].c.." %s>%s</"..cmdtotags[i].b..">", arg, body) | 812 | -- return string.format("<"..cmdtotags[i].b..cmdtotags[i].c.." %s>%s</"..cmdtotags[i].b..">", arg, body) |
811 | return string.format("<"..cmdtotags[i].b..cmdtotags[i].c..">%s</"..cmdtotags[i].b..">", body) | 813 | return string.format("<"..cmdtotags[i].b..cmdtotags[i].c..">%s</"..cmdtotags[i].b..">", body) |
812 | end) | 814 | end) |
@@ -814,19 +816,27 @@ function ekdosis.textotei(str) | |||
814 | str = string.gsub(str, "\\(%a+)%s?%*?(%b[])(%b{})", | 816 | str = string.gsub(str, "\\(%a+)%s?%*?(%b[])(%b{})", |
815 | function(cmd, opt, body) | 817 | function(cmd, opt, body) |
816 | body = string.sub(body, 2, -2) | 818 | body = string.sub(body, 2, -2) |
817 | body = ekdosis.textotei(body) | 819 | body = textotei(body) |
818 | return string.format("<%s>%s</%s>", cmd, body, cmd) | 820 | return string.format("<%s>%s</%s>", cmd, body, cmd) |
819 | end) | 821 | end) |
820 | str = string.gsub(str, "\\(%a+)%s?%*?(%b{})", | 822 | str = string.gsub(str, "\\(%a+)%s?%*?(%b{})", |
821 | function(cmd, body) | 823 | function(cmd, body) |
822 | body = string.sub(body, 2, -2) | 824 | body = string.sub(body, 2, -2) |
823 | body = ekdosis.textotei(body) | 825 | body = textotei(body) |
824 | return string.format("<%s>%s</%s>", cmd, body, cmd) | 826 | return string.format("<%s>%s</%s>", cmd, body, cmd) |
825 | end) | 827 | end) |
826 | str = string.gsub(str, "(%s)(%>)", "%2") | 828 | str = string.gsub(str, "(%s)(%>)", "%2") |
827 | return str | 829 | return str |
828 | end | 830 | end |
829 | 831 | ||
832 | function ekdosis.textotei(str) | ||
833 | str = xml_entities(str) | ||
834 | str = string.gsub(str, "%s?\\par%s?", "</p>\n<p>") | ||
835 | str = lem_rdg_totei(str) | ||
836 | str = textotei(str) | ||
837 | return str | ||
838 | end | ||
839 | |||
830 | local teifilename = tex.jobname.."-tei" | 840 | local teifilename = tex.jobname.."-tei" |
831 | 841 | ||
832 | function ekdosis.setteifilename(str) | 842 | function ekdosis.setteifilename(str) |