summaryrefslogtreecommitdiff
path: root/tex/context/base/lxml-aux.lua
diff options
context:
space:
mode:
authorContext Git Mirror Bot <phg42.2a@gmail.com>2014-11-10 11:15:04 +0100
committerContext Git Mirror Bot <phg42.2a@gmail.com>2014-11-10 11:15:04 +0100
commitf853930e63e059af883ee86b9fe5549cfaa75d43 (patch)
tree7d872b6fa23e09b19e4df2966b8c1c218b4a7908 /tex/context/base/lxml-aux.lua
parent19cbb867e30cd14ade5a9057965fdd76314e0cdb (diff)
downloadcontext-f853930e63e059af883ee86b9fe5549cfaa75d43.tar.gz
2014-11-10 10:53:00
Diffstat (limited to 'tex/context/base/lxml-aux.lua')
-rw-r--r--tex/context/base/lxml-aux.lua23
1 files changed, 10 insertions, 13 deletions
diff --git a/tex/context/base/lxml-aux.lua b/tex/context/base/lxml-aux.lua
index a26d7c2ea..96f89d544 100644
--- a/tex/context/base/lxml-aux.lua
+++ b/tex/context/base/lxml-aux.lua
@@ -463,9 +463,16 @@ function xml.inclusions(e,sorted)
end
end
+local stripper = lpeg.patterns.stripper
+local fullstripper = lpeg.patterns.fullstripper
+local collapser = lpeg.patterns.collapser
+
+local lpegmatch = lpeg.match
+
local function stripelement(e,nolines,anywhere)
local edt = e.dt
if edt then
+ local strip = nolines and fullstripper or stripper
if anywhere then
local t, n = { }, 0
for e=1,#edt do
@@ -474,11 +481,7 @@ local function stripelement(e,nolines,anywhere)
n = n + 1
t[n] = str
elseif str ~= "" then
- -- todo: lpeg for each case
- if nolines then
- str = gsub(str,"%s+"," ")
- end
- str = gsub(str,"^%s*(.-)%s*$","%1")
+ str = lpegmatch(strip,str)
if str ~= "" then
n = n + 1
t[n] = str
@@ -497,10 +500,7 @@ local function stripelement(e,nolines,anywhere)
elseif str == "" then
remove(edt,1)
else
- if nolines then
- str = gsub(str,"%s+"," ")
- end
- str = gsub(str,"^%s+","")
+ str = lpegmatch(strip,str)
if str == "" then
remove(edt,1)
else
@@ -517,10 +517,7 @@ local function stripelement(e,nolines,anywhere)
elseif str == "" then
remove(edt)
else
- if nolines then
- str = gsub(str,"%s+"," ")
- end
- str = gsub(str,"%s+$","")
+ str = lpegmatch(strip,str)
if str == "" then
remove(edt)
else