From e7ccb49757db20324d9264cb4b20d9e531d8dee9 Mon Sep 17 00:00:00 2001 From: Robert Alessi Date: Sun, 3 May 2020 09:20:25 +0200 Subject: new function get_attr_value() --- ekdosis.dtx | 68 +++++++++++++++++++------------------------------------------ 1 file changed, 21 insertions(+), 47 deletions(-) diff --git a/ekdosis.dtx b/ekdosis.dtx index 8354459..6e0bf42 100644 --- a/ekdosis.dtx +++ b/ekdosis.dtx @@ -1557,6 +1557,19 @@ function ekdosis.newenvtotag(env, tag, attr, closep) return true end +-- Get values of attributes +local function get_attr_value(str, attr) + local attrval = string.match(str, "%f[%w]"..attr.."%s?%=%s?%b{}") + or string.match(str, "%f[%w]"..attr.."%s?%=%s?.-%,") + or "" + attrval = string.gsub(attrval, attr.."%s?%=%s?(%b{})", function(bbraces) + bbraces = string.sub(bbraces, 2, -2) + return string.format("%s", bbraces) + end) + attrval = string.gsub(attrval, attr.."%s?%=%s?(.-)%s?%,", "%1") + return attrval +end + local function xml_entities(str) str = string.gsub(str, "%<", "<") str = string.gsub(str, "%>", ">") @@ -1949,17 +1962,6 @@ function ekdosis.setekddivsfalse() ekddivs = false end ---[[ - teitype = string.match(opt, "%f[%w]type%s?%=%s?%b{}") - or string.match(opt, "%f[%w]type%s?%=%s?%w+%f[%W]") - or "" - teitype = string.gsub(teitype, "type%s?%=%s?(%b{})", function(bbraces) - bbraces = string.sub(bbraces, 2, -2) - return string.format("%s", bbraces) - end) - teitype = string.gsub(teitype, "(type%s?%=%s?)(%w+%f[%W])", "%2") ---]] - local function ekddivs_totei(str) str = gsub(str, dblbkslash * lpeg.Cs("ekddiv") * spce^-1 * bcbraces, function(bkslash, cmd, space, arg) @@ -1968,43 +1970,15 @@ local function ekddivs_totei(str) arg = string.sub(arg, 2, -2) arg = arg.."," -- - teitype = string.match(arg, "%f[%w]type%s?%=%s?%b{}") - or string.match(arg, "%f[%w]type%s?%=%s?[%w%s]+%,") - or "" - teitype = string.gsub(teitype, "type%s?%=%s?(%b{})", function(bbraces) - bbraces = string.sub(bbraces, 2, -2) - return string.format("%s", bbraces) - end) - teitype = string.gsub(teitype, "(type%s?%=%s?)([%w%s]+)(%,)", "%2") - -- - tein = string.match(arg, "%f[%w]n%s?%=%s?%b{}") - or string.match(arg, "%f[%w]n%s?%=%s?[%w%s]+%,") - or "" - tein = string.gsub(tein, "n%s?%=%s?(%b{})", function(bbraces) - bbraces = string.sub(bbraces, 2, -2) - return string.format("%s", bbraces) - end) - tein = string.gsub(tein, "(n%s?%=%s?)([%w%s]+)(%,)", "%2") - -- - teihead = string.match(arg, "%f[%w]head%s?%=%s?%b{}") - or string.match(arg, "%f[%w]head%s?%=%s?[%w%s]+%,") - or "" - teihead = string.gsub(teihead, "head%s?%=%s?(%b{})", function(bbraces) - bbraces = string.sub(bbraces, 2, -2) - return string.format("%s", bbraces) - end) - teihead = string.gsub(teihead, "(head%s?%=%s?)([%w%s]+)(%,)", "%2") - -- - teidepth = string.match(arg, "%f[%w]depth%s?%=%s?%b{}") - or string.match(arg, "%f[%w]depth%s?%=%s?[%w%s]+%,") - or "" - teidepth = string.gsub(teidepth, "depth%s?%=%s?(%b{})", function(bbraces) - bbraces = string.sub(bbraces, 2, -2) - return string.format("%s", bbraces) - end) - teidepth = string.gsub(teidepth, "(depth%s?%=%s?)([%w%s]+)(%,)", "%2") + teitype = get_attr_value(arg, "type") + tein = get_attr_value(arg, "n") + teihead = get_attr_value(arg, "head") + teidepth = get_attr_value(arg, "depth") -- - return string.format("\\par
%s", + if teitype ~= "" then teitype = " type=\""..teitype.."\"" else end + if tein ~= "" then tein = " n=\""..tein.."\"" else end + if teidepth ~= "" then teidepth = " depth=\""..teidepth.."\"" else end + return string.format("\\par %s", teitype, tein, teidepth, teihead) else return "" -- cgit v1.2.3