diff options
author | Mojca Miklavec <mojca.miklavec@gmail.com> | 2012-06-08 12:19:55 +0000 |
---|---|---|
committer | Mojca Miklavec <mojca.miklavec@gmail.com> | 2012-06-08 12:19:55 +0000 |
commit | 7d4d7bd57d826a9576318a3e8f1db50188764566 (patch) | |
tree | 2336337a3561087d91ffefa47a4366d3a4cac3a2 /Master/texmf-dist/tex/context/base/lxml-aux.lua | |
parent | 4809fa94a8d42936d46320477ce193190987f4d4 (diff) |
ConTeXt 2012.05.30 11:26
git-svn-id: svn://tug.org/texlive/trunk@26861 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context/base/lxml-aux.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/lxml-aux.lua | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/Master/texmf-dist/tex/context/base/lxml-aux.lua b/Master/texmf-dist/tex/context/base/lxml-aux.lua index 09411bfc0d5..be12659ba10 100644 --- a/Master/texmf-dist/tex/context/base/lxml-aux.lua +++ b/Master/texmf-dist/tex/context/base/lxml-aux.lua @@ -22,7 +22,7 @@ local xmlfilter = xml.filter local type, setmetatable, getmetatable = type, setmetatable, getmetatable local insert, remove, fastcopy, concat = table.insert, table.remove, table.fastcopy, table.concat -local gmatch, gsub, format = string.gmatch, string.gsub, string.format +local gmatch, gsub, format, find, strip = string.gmatch, string.gsub, string.format, string.find, string.strip local utfbyte = utf.byte local function report(what,pattern,c,e) @@ -721,3 +721,48 @@ function xml.setcdata(e,str) -- also setcomment dt = { str }, } } end + +-- maybe helpers like this will move to an autoloader + +function xml.separate(x,pattern) + local collected = xmlapplylpath(x,pattern) + if collected then + for c=1,#collected do + local e = collected[c] + local d = e.dt + if d == x then + report_xml("warning: xml.separate changes root") + x = d + end + local t, n = { "\n" }, 1 + local i, nd = 1, #d + while i <= nd do + while i <= nd do + local di = d[i] + if type(di) == "string" then + if di == "\n" or find(di,"^%s+$") then -- first test is speedup + i = i + 1 + else + d[i] = strip(di) + break + end + else + break + end + end + if i > nd then + break + end + t[n+1] = "\n" + t[n+2] = d[i] + t[n+3] = "\n" + n = n + 3 + i = i + 1 + end + t[n+1] = "\n" + setmetatable(t,getmetatable(d)) + e.dt = t + end + end + return x +end |