summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/lxml-ini.mkiv
diff options
context:
space:
mode:
authorTaco Hoekwater <taco@elvenkind.com>2010-05-24 14:05:02 +0000
committerTaco Hoekwater <taco@elvenkind.com>2010-05-24 14:05:02 +0000
commit57ea7dad48fbf2541c04e434c31bde655ada3ac4 (patch)
tree1f8b43bc7cb92939271e1f5bec610710be69097f /Master/texmf-dist/tex/context/base/lxml-ini.mkiv
parent6ee41e1f1822657f7f23231ec56c0272de3855e3 (diff)
here is context 2010.05.24 13:05
git-svn-id: svn://tug.org/texlive/trunk@18445 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context/base/lxml-ini.mkiv')
-rw-r--r--Master/texmf-dist/tex/context/base/lxml-ini.mkiv360
1 files changed, 183 insertions, 177 deletions
diff --git a/Master/texmf-dist/tex/context/base/lxml-ini.mkiv b/Master/texmf-dist/tex/context/base/lxml-ini.mkiv
index 34a14f9d9f5..0f04d048808 100644
--- a/Master/texmf-dist/tex/context/base/lxml-ini.mkiv
+++ b/Master/texmf-dist/tex/context/base/lxml-ini.mkiv
@@ -11,36 +11,47 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
+%D Todo: auto apply setups (manage at lua end)
+
\writestatus{loading}{ConTeXt XML Support / Initialization}
-\registerctxluafile{lxml-tab}{1.001}
-\registerctxluafile{lxml-pth}{1.001}
-\registerctxluafile{lxml-ent}{1.001}
-\registerctxluafile{lxml-mis}{1.001}
-\registerctxluafile{lxml-ini}{1.001}
+%registerctxluafile{lxml-tab}{1.001} % loader
+%registerctxluafile{lxml-lpt}{1.001} % parser
+%registerctxluafile{lxml-xml}{1.001} % xml finalizers
+%registerctxluafile{lxml-aux}{1.001} % extras using parser
+%registerctxluafile{lxml-mis}{1.001} % extras independent of parser
+\registerctxluafile{lxml-ent}{1.001} % entity hacks
+\registerctxluafile{lxml-tex}{1.001} % tex finalizers
+\registerctxluafile{lxml-dir}{1.001} % ctx hacks
\unprotect
+\def\c!entities{entities} % to be internationalized
+
\def\xmlmain #1{\ctxlua{lxml.main("#1")}}
+\def\xmlmatch #1{\ctxlua{lxml.match("#1")}}
\def\xmlall #1#2{\ctxlua{lxml.all("#1","#2")}}
-\def\xmlatt #1#2{\ctxlua{lxml.attribute("#1","/","#2")}}
-\def\xmlattdef #1#2#3{\ctxlua{lxml.attribute("#1","/","#2","#3")}}
+\def\xmlatt #1#2{\ctxlua{lxml.att("#1","#2")}}
+\def\xmlattdef #1#2#3{\ctxlua{lxml.att("#1","#2","#3")}}
+\def\xmlchainatt #1#2{\ctxlua{lxml.chainattribute("#1","/","#2")}}
+\def\xmlchainattdef #1#2#3{\ctxlua{lxml.chainattribute("#1","/","#2","#3")}}
\def\xmlattribute #1#2#3{\ctxlua{lxml.attribute("#1","#2","#3")}}
\def\xmlattributedef #1#2#3#4{\ctxlua{lxml.attribute("#1","#2","#3","#4")}}
\def\xmlcommand #1#2#3{\ctxlua{lxml.command("#1","#2","#3")}}
\def\xmlconcat #1#2#3{\ctxlua{lxml.concat("#1","#2",[[\detokenize{#3}]])}}
\def\xmlconcatrange#1#2#3#4#5{\ctxlua{lxml.concatrange("#1","#2","#3","#4",[[\detokenize{#5}]])}}
\def\xmlcount #1#2{\ctxlua{lxml.count("#1","#2")}}
-\def\xmldelete #1#2{\ctxlua{xml.delete(lxml.id("#1"),"#2")}}
+\def\xmldelete #1#2{\ctxlua{lxml.delete("#1","#2")}}
\def\xmldirectives #1{\ctxlua{lxml.directives.setup("#1")}}
\def\xmldirectivesbefore #1{\ctxlua{lxml.directives.before("#1")}}
\def\xmldirectivesafter #1{\ctxlua{lxml.directives.after("#1")}}
\def\xmlfilter #1#2{\ctxlua{lxml.filter("#1",\!!bs#2\!!es)}}
+\def\xmlfilterlist #1#2{\ctxlua{lxml.filterlist("#1",\!!bs#2\!!es)}}
+\def\xmlfunction #1#2{\ctxlua{lxml["function"]("#1",\!!bs#2\!!es)}}
\def\xmlfirst #1#2{\ctxlua{lxml.first("#1","#2")}}
\def\xmlflush #1{\ctxlua{lxml.flush("#1")}}
-% \def\xmlcontent #1{\ctxlua{lxml.content("#1")}}
-% \def\xmlstrip #1{\ctxlua{lxml.strip("#1")}}
-% \def\xmlflushstripped #1{\ctxlua{lxml.strip("#1",true)}}
+%def\xmlcontent #1{\ctxlua{lxml.content("#1")}}
+%def\xmlflushstripped #1{\ctxlua{lxml.strip("#1",true)}}
\def\xmldirect #1{\ctxlua{lxml.direct("#1")}} % in loops, not dt but root
\def\xmlidx #1#2#3{\ctxlua{lxml.idx("#1","#2",\number#3)}}
\def\xmlinclude #1#2#3{\ctxlua{lxml.include("#1","#2","#3",true)}}
@@ -48,18 +59,14 @@
\def\xmlinfo #1{\hbox{\ttxx[\ctxlua{lxml.info("#1")}]}}
\def\xmlshow #1{\startpacked\ttx\xmlverbatim{#1}\stoppacked}
\def\xmllast #1#2{\ctxlua{lxml.last("#1","#2")}}
-\def\xmlload #1#2{\ctxlua{lxml.load("#1","#2")}}
-\def\xmlloadbuffer #1#2{\ctxlua{lxml.loadbuffer("#1","#2")}}
-\def\xmlloaddata #1#2{\ctxlua{lxml.loaddata("#1",\!!bs#2\!!es)}}
-\def\xmlloadregistered #1#2{\ctxlua{lxml.loadregistered("#1")}}
-\def\xmlloaddirectives #1{\ctxlua{lxml.directives.load("#1")}}
\def\xmlname #1{\ctxlua{lxml.name("#1")}}
\def\xmlnamespace #1{\ctxlua{lxml.namespace("#1")}}
\def\xmlnonspace #1#2{\ctxlua{lxml.nonspace("#1","#2")}}
\def\xmlraw #1#2{\ctxlua{lxml.raw("#1","#2")}}
+\def\xmlcontext #1#2{\ctxlua{lxml.context("#1","#2")}}
+\def\xmlflushcontext #1{\ctxlua{lxml.context("#1")}}
\def\xmlsnippet #1#2{\ctxlua{lxml.snippet("#1",#2)}}
\def\xmlelement #1#2{\ctxlua{lxml.element("#1",#2)}}
-\def\xmlnofelements #1{\ctxlua{lxml.nofelements("#1")}}
\def\xmlregisterns #1#2{\ctxlua{xml.registerns("#1","#2")}} % document
\def\xmlremapname #1#2#3#4{\ctxlua{xml.remapname(lxml.id("#1"),"#2","#3","#4")}} % element
\def\xmlremapnamespace #1#2#3{\ctxlua{xml.rename_space(lxml.id("#1"),"#2","#3")}} % document
@@ -67,17 +74,23 @@
\def\xmlsetfunction #1#2#3{\ctxlua{lxml.setaction("#1","#2",#3)}}
\def\xmlsetsetup #1#2#3{\ctxlua{lxml.setsetup("#1","#2","#3")}}
\def\xmlstrip #1#2{\ctxlua{lxml.strip("#1","#2")}}
-\def\xmlstripped #1#2{\ctxlua{lxml.stripped("#1","#2")}}
\def\xmlstripnolines #1#2{\ctxlua{lxml.strip("#1","#2",true)}}
+\def\xmlstripanywhere #1#2{\ctxlua{lxml.strip("#1","#2",true,true)}}
+\def\xmlstripped #1#2{\ctxlua{lxml.stripped("#1","#2")}}
\def\xmlstrippednolines #1#2{\ctxlua{lxml.stripped("#1","#2",true)}}
\def\xmltag #1{\ctxlua{lxml.tag("#1")}}
\def\xmltext #1#2{\ctxlua{lxml.text("#1","#2")}}
-\def\xmltags #1#2{\ctxlua{lxml.tags("#1","#2")}}
-\def\xmlutfize #1{\ctxlua{lxml.utfize("#1")}}
\def\xmlverbatim #1{\ctxlua{lxml.verbatim("#1")}}
\def\xmldisplayverbatim #1{\ctxlua{lxml.displayverbatim("#1")}}
\def\xmlinlineverbatim #1{\ctxlua{lxml.inlineverbatim("#1")}}
+\def\xmlload #1#2{\ctxlua{lxml.load("#1","#2","\@@xmentities","\@@xmcompress")}}
+\def\xmlloadbuffer #1#2{\ctxlua{lxml.loadbuffer("#1","#2","\@@xmentities","\@@xmcompress")}}
+\def\xmlloaddata #1#2{\ctxlua{lxml.loaddata("#1",\!!bs#2\!!es,"\@@xmentities","\@@xmcompress")}}
+\def\xmlloadregistered #1#2{\ctxlua{lxml.loadregistered("#1","\@@xmentities","\@@xmcompress")}}
+\def\xmlloaddirectives #1{\ctxlua{lxml.directives.load("any:///#1")}}
+\def\xmlpos #1{\ctxlua{lxml.pos("#1")}}
+
%def\xmldoifelse #1#2{\ctxlua{cs.testcase(xml.found(lxml.id("#1"),"#2",false))}}
%def\xmldoifelsetext #1#2{\ctxlua{cs.testcase(xml.found(lxml.id("#1"),"#2",true ))}}
@@ -88,17 +101,15 @@
% todo: \xmldoifelseattribute
-\def\xmldoif #1#2{\ctxlua{lxml.doif("#1","#2")}}
-\def\xmldoifnot #1#2{\ctxlua{lxml.doifnot("#1","#2")}}
-\def\xmldoifelse #1#2{\ctxlua{lxml.doifelse("#1","#2")}}
-\def\xmldoiftext #1#2{\ctxlua{lxml.doiftext("#1","#2")}}
-\def\xmldoifnottext #1#2{\ctxlua{lxml.doifnottext("#1","#2")}}
-\def\xmldoifelsetext #1#2{\ctxlua{lxml.doifelsetext("#1","#2")}}
-\def\xmldoifelseempty #1#2{\ctxlua{lxml.doifelseempty("#1","#2")}} % #2, "*" or "" == self not yet implemented
-\def\xmldoifelseselfempty #1{\ctxlua{lxml.doifelseempty("#1")}}
+\def\xmldoif #1#2{\ctxlua{lxml.doif (\!!bs#1\!!es,\!!bs#2\!!es)}}
+\def\xmldoifnot #1#2{\ctxlua{lxml.doifnot (\!!bs#1\!!es,\!!bs#2\!!es)}}
+\def\xmldoifelse #1#2{\ctxlua{lxml.doifelse (\!!bs#1\!!es,\!!bs#2\!!es)}}
+\def\xmldoiftext #1#2{\ctxlua{lxml.doiftext (\!!bs#1\!!es,\!!bs#2\!!es)}}
+\def\xmldoifnottext #1#2{\ctxlua{lxml.doifnottext (\!!bs#1\!!es,\!!bs#2\!!es)}}
+\def\xmldoifelsetext #1#2{\ctxlua{lxml.doifelsetext(\!!bs#1\!!es,\!!bs#2\!!es)}}
-\def\xmldefaulttotext #1{\ifcase\xmlprocessingmode\or\or \ctxlua{lxml.set_command_to_text("#1")}\fi}
-\def\xmldefaulttonone #1{\ifcase\xmlprocessingmode\or\or\or\ctxlua{lxml.set_command_to_none("#1")}\fi}
+%def\xmldoifelseempty #1#2{\ctxlua{lxml.doifelseempty("#1","#2")}} % #2, "*" or "" == self not yet implemented
+%def\xmldoifelseselfempty #1{\ctxlua{lxml.doifelseempty("#1")}}
% \startxmlsetups xml:include
% \xmlinclude{main}{include}{filename|href}
@@ -106,15 +117,17 @@
%
% \xmlprependsetup{xml:include}
-\let\xmlgrab\xmlsetsetup
+\let\xmlgrab\xmlsetsetup % obsolete
+\let\xmlself\s!unknown % obsolete
+
+\def\xmlsetup#1#2{\setupwithargument{#2}{#1}}
-\def\xmlsetup#1#2% % we pass the reference so that we have access to the frozen number
- {\def\xmlself{#1}% % by using #1 inside a setup; maybe self becomes obsolete
- \setupwithargument{#2}{#1}}
+\let\xmls\xmlsetup
+\let\xmlw\setupwithargument
\newtoks \registeredxmlsetups
-% todo: 1:xml:whatever alwas before 3:xml:something
+% todo: 1:xml:whatever always before 3:xml:something
\def\xmlprependsetup #1{\ctxlua{lxml.installsetup(1,"*","#1")}}
\def\xmlappendsetup #1{\ctxlua{lxml.installsetup(2,"*","#1")}}
@@ -129,7 +142,7 @@
\def\xmlremovesetup #1{\ctxlua{lxml.removesetup("*","#1")}}
\def\xmlremovedocumentsetup #1#2{\ctxlua{lxml.removesetup("#1","#2")}}
-\def\xmlflushdocumentsetups #1{\ctxlua{lxml.flushsetups("*","#1")}}
+\def\xmlflushdocumentsetups #1#2{\ctxlua{lxml.flushsetups("#1","*","#2")}} % #1 == id where to apply * and #2
\def\xmlresetdocumentsetups #1{\ctxlua{lxml.resetsetups("#1")}}
\let\xmlregistersetup \xmlappendsetup
@@ -143,58 +156,59 @@
\xmldefaulttotext\xmldocument % after include
\xmlstoptiming}
-\def\xmlregistereddocumentsetups#1%
+\def\xmlregistereddocumentsetups#1#2% id setups
{\xmlstarttiming
% todo: test for duplicates !
- \xmlflushdocumentsetups{#1}%
+ \xmlflushdocumentsetups{#1}{#2}%
\xmldefaulttotext{#1}% after include
\xmlstoptiming}
\def\xmlstarttiming{\ctxlua{statistics.starttiming(lxml)}}
\def\xmlstoptiming {\ctxlua{statistics.stoptiming (lxml)}}
-\def\doxmlprocess#1#2#3#4%
+\def\doxmlprocess#1#2#3#4#5% flag \loader id name what initializersetup
{\begingroup
- \edef\xmldocument{#2}% #2 can be \xmldocument and set as such
- #1{#2}{#3}%
- \ifcase\xmlprocessingmode
- \enableXML
- \else
- \setcatcodetable\notcatcodes
- \fi
- \doifelsenothing{#4}
- {\directsetup{xml:process}}
- {\directsetup{#4}}%
+ \edef\xmldocument{#3}% #2 can be \xmldocument and set as such
+ %xmlpushdocument{#3}%
+ #2{#3}{#4}%
+ \setcatcodetable\notcatcodes
+ \doifelsenothing{#5}
+ {\xmlsetup{#3}{xml:process}}
+ {\xmlsetup{#3}{#5}}%
+ %xmlpopdocument
\endgroup}
-\def\xmlprocessfile {\doxmlprocess\xmlload}
-\def\xmlprocessdata {\doxmlprocess\xmlloaddata}
-\def\xmlprocessbuffer {\doxmlprocess\xmlloadbuffer}
-\def\xmlprocessregistered{\doxmlprocess\xmlloadregistered}
+\def\xmlprocessfile {\doxmlprocess\plusone \xmlload}
+\def\xmlprocessdata {\doxmlprocess\zerocount\xmlloaddata}
+\def\xmlprocessbuffer {\doxmlprocess\zerocount\xmlloadbuffer}
+\def\xmlprocessregistered{\doxmlprocess\zerocount\xmlloadregistered}
\let\xmlprocess \xmlprocessfile
+\startxmlsetups xml:flush
+ \xmlflush{#1}
+\stopxmlsetups
+
+\startxmlsetups xml:process
+ \xmlregistereddocumentsetups{#1}{#1}
+ \xmlmain{#1}
+\stopxmlsetups
+
+\def\xmlloadonly#1#2#3%
+ {\xmlload{#1}{#2}%
+ \xmlregistereddocumentsetups{#1}{#3}}
+
% beware: \xmlmain takes the real root, so also processing
% instructions preceding the root element; well, in some
% sense that is the root
-\startsetups xml:process
- \xmlregistereddocumentsetups\xmldocument
- \xmlmain\xmldocument
-\stopsetups
-
-\long\def\xmlloop#1#2#3%
- {\def\xmli##1##2{\xmlidx{#1}{#2/##1}{##2}}%
- \dorecurse{\xmlcount{#1}{#2}}{#3}}
-
\long\def\xmlconnect#1#2#3% inefficient
{\scratchcounter\xmlcount{#1}{#2}\relax
\ifcase\scratchcounter \or
- \xmlall{#1}{#2}%
+ \xmlall{#1}{#2}%
\else
- \dorecurse \scratchcounter {
- \ifnum\recurselevel>\plusone#3\fi
- \xmlidx{#1}{#2}{\recurselevel}
- }
+ \dorecurse \scratchcounter
+ {\ifnum\recurselevel>\plusone#3\fi
+ \xmlidx{#1}{#2}\recurselevel}%
\fi}
\def\xmlcdataobeyedline {\obeyedline}
@@ -208,10 +222,10 @@
% \xmlsetfunction{main}{verbatim}{lxml.displayverbatim}
% \xmlsetfunction{main}{verb} {lxml.inlineverbatim}
-% \def\startxmldisplayverbatim[#1]{}
-% \def\stopxmldisplayverbatim {}
-% \def\startxmlinlineverbatim [#1]{}
-% \def\stopxmlinlineverbatim {}
+% \unexpanded\def\startxmldisplayverbatim[#1]{}
+% \unexpanded\def\stopxmldisplayverbatim {}
+% \unexpanded\def\startxmlinlineverbatim [#1]{}
+% \unexpanded\def\stopxmlinlineverbatim {}
% we use an xml: namespace so one has to define a suitable verbatim, say
%
@@ -219,35 +233,35 @@
%
% this is experimental!
-\def\startxmldisplayverbatim[#1]%
+\unexpanded\def\startxmldisplayverbatim[#1]%
{\startpacked % \begingroup
\let\currenttypingclass\??tp
\edef\currenttyping{xml:#1}%
- \def\stopxmldisplayverbatim
+ \unexpanded\def\stopxmldisplayverbatim
{\endofverbatimlines
\stoppacked} % \endgroup
- \mkinitializeverbatim
+ \doinitializeverbatim
\beginofverbatimlines}
-\def\startxmlinlineverbatim[#1]%
+\unexpanded\def\startxmlinlineverbatim[#1]%
{\begingroup
\let\currenttypingclass\??ty
\edef\currenttyping{xml:#1}%
\let\stopxmldisplayverbatim\endgroup
- \mkinitializeverbatim}
+ \doinitializeverbatim}
% will move but is developed for xml
\newtoks \collectingtoks
-\def\startcollect#1\stopcollect
+\unexpanded\def\startcollect#1\stopcollect
{\collectingtoks\@EA{\the\collectingtoks#1}}
-\def\startexpandedcollect#1\stopexpandedcollect
- {\expanded{\collectingtoks{\the\collectingtoks#1}}}
+\unexpanded\def\startexpandedcollect#1\stopexpandedcollect
+ {\normalexpanded{\collectingtoks{\the\collectingtoks#1}}}
-\def\startcollecting{\collectingtoks\emptytoks}
-\def\stopcollecting {\the\collectingtoks}
+\unexpanded\def\startcollecting{\collectingtoks\emptytoks}
+\unexpanded\def\stopcollecting {\the\collectingtoks}
\def\inlinemessage #1{\dontleavehmode{\tttf#1}}
\def\displaymessage#1{\blank\inlinemessage{#1}\blank}
@@ -263,98 +277,43 @@
% setting up xml:
%
-% \setupxml[\c!method=mkii] % mixed mkiv and mkii
-% \setupxml[\c!method=mkiv,\c!default=] % mkiv only
-% \setupxml[\c!method=mkiv,\c!default=\v!none] % mkiv only, undefined -> hidden
-% \setupxml[\c!method=mkiv,\c!default=\v!text] % mkiv only, undefined -> text
+% \setupxml[\c!default=] % mkiv only == text
+% \setupxml[\c!default=\v!none] % mkiv only, undefined -> hidden
+% \setupxml[\c!default=\v!text] % mkiv only, undefined -> text
% \def\xmlctxdirective#1#2#3{\doif{#1}{clue}{\doif{#2}{page}}{\page[#3]}}
-\chardef\xmlprocessingmode=0 % 0=mixed, 1=mkivonly, 2=mkivonly-default-text, 3=mkivonly-default-none
-
-% \setupxml[method=mkiv,strip=yes,entities=yes,default=text]
+\chardef\xmlprocessingmode=0 % 0=unset, 1=text, 2=hidden
\newtoks\everysetupxml
-\def\setupxml[#1]{\getparameters[\??xm][#1]\the\everysetupxml}
-
-\def\c!entities{entities} % to be internationalized
-\def\s!mkiv {mkiv}
-\def\s!mkii {mkii}
-
-% entities
-
-\newif\ifautoXMLentities
-
-\def\xmlkeepentities{\ctxlua{lxml.reset_entityhandler()}}
-\def\xmlmkiientities{\ctxlua{lxml.set_mkii_entityhandler()}\autoXMLentitiestrue}
-\def\xmlmkiventities{\ctxlua{lxml.set_mkiv_entityhandler()}}
-
-\let\xmlresolveentities\xmlmkiventities % will become \xmlmkiventities
+\unexpanded\def\setupxml[#1]{\getparameters[\??xm][#1]\the\everysetupxml}
-\letvalue{\??xm:1:\s!mkii }\zerocount
-\letvalue{\??xm:1:\s!mkiv }\plusone
-\letvalue{\??xm:2:\v!none }\plusone
-\letvalue{\??xm:2:\v!text }\plustwo
-\letvalue{\??xm:2:\v!hidden}\plusthree
+\letvalue{\??xm:\s!default:\v!normal}\zerocount
+\letvalue{\??xm:\s!default:\v!none }\zerocount
+\letvalue{\??xm:\s!default:\v!text }\plusone
+\letvalue{\??xm:\s!default:\v!hidden}\plustwo
-\letvalue{\??xm:ii:\v!yes }\xmlresolveentities
-\letvalue{\??xm:ii:\v!no }\xmlkeepentities
-\letvalue{\??xm:ii:\s!mkii}\xmlmkiientities
-\letvalue{\??xm:ii:\s!mkiv}\xmlmkiventities
-
-\letvalue{\??xm:iv:\v!yes }\xmlresolveentities
-\letvalue{\??xm:iv:\v!no }\xmlkeepentities
-\letvalue{\??xm:iv:\s!mkii}\xmlmkiventities
-\letvalue{\??xm:iv:\s!mkiv}\xmlmkiventities
+\def\xmldefaulttotext#1%
+ {\ifcase\xmlprocessingmode
+ % unset
+ \or
+ \ctxlua{lxml.set_command_to_text("#1")}% 1
+ \or
+ \ctxlua{lxml.set_command_to_none("#1")}% 2
+ \else
+ % unset
+ \fi}
\appendtoks
- \chardef\xmlprocessingmode\executeifdefined{\??xm:1:\@@xmmethod}\zerocount
- \ifcase\xmlprocessingmode
- % mkii, permits both methods
- \executeifdefined{\??xm:ii:\@@xmentities}\xmlkeepentities
- \or
- % mkiv, mkiv exclusively
- \chardef\xmlprocessingmode\executeifdefined{\??xm:2:\@@xmdefault}\plusone
- \executeifdefined{\??xm:iv:\@@xmentities}\xmlresolveentities
- \else
- % unset
- \fi
- \ifcase\xmlprocessingmode
- \ctxlua{characters.setmkiientities()}%
- \else
- \ctxlua{characters.setmkiventities()}%
- \fi
- \doifelse\@@xmcompress\v!yes % this key may change, maybe compress=yes|no
- {\ctxlua{xml.strip_cm_and_dt=true}}
- {\ctxlua{xml.strip_cm_and_dt=false}}%
+ \chardef\xmlprocessingmode\executeifdefined{\??xm:\s!default:\@@xmdefault}\plusone
\to \everysetupxml
\def\xmlinitialize{\the\everysetupxml}
-\newcount\charactersactiveoffset \charactersactiveoffset="10000
-
-\startextendcatcodetable\ctxcatcodes
- \catcode\numexpr\charactersactiveoffset+`<\relax=13
- \catcode\numexpr\charactersactiveoffset+`&\relax=13
- \catcode\numexpr\charactersactiveoffset+`>\relax=13
-\stopextendcatcodetable
-\startextendcatcodetable\xmlcatcodes
- \catcode\numexpr\charactersactiveoffset+`<\relax=13
- \catcode\numexpr\charactersactiveoffset+`&\relax=13
- \catcode\numexpr\charactersactiveoffset+`>\relax=13
-\stopextendcatcodetable
-
-\ctxlua { % entities are remembered in the format
- characters.remapentity("<",characters.active_offset + utf.byte("<"))
- characters.remapentity("&",characters.active_offset + utf.byte("&"))
- characters.remapentity(">",characters.active_offset + utf.byte(">"))
-}
-
\setupxml
- [\c!method=mkii, % mixed mode
- \c!default=\v!hidden, % ignore elements that are not defined
+ [\c!default=, % flush all
\c!compress=\v!no, % strip comment
\c!entities=\v!yes] % replace entities
@@ -376,33 +335,80 @@
%
% mkii: [\processXMLbuffer]\quad mkiv: [\xmlprocessbuffer{main}{}{}]
-% some mkii commands, but mkiv-ified
-
-\def\xmlmapvalue#1#2#3{\setvalue{\??xm:v:#1:#2}{#3}} % keep #3 to grab spaces
-\def\xmlvalue #1#2#3{\executeifdefined{\??xm:v:#1:#2}{#3}}
+\def\xmlmapvalue #1#2#3{\setvalue{\??xm:v:#1:#2}{#3}} % keep #3 to grab spaces
+\def\xmlvalue #1#2#3{\executeifdefined{\??xm:v:#1:#2}{#3}}
+%def\xmlvalue #1#2{\ifcsname\??xm:v:#1:#2\endcsname\csname\??xm:v:#1:#2\expandafter\expandafter\gobbleoneargument\expandafter\endcsname\else\expandafter\firstofoneargument\fi}
+\def\xmldoifelsevalue #1#2{\ifcsname\??xm:v:#1:#2\endcsname\expandafter\firstoftwoarguments\else\expandafter\secondoftwoarguments\fi}
\let\xmlmapval\xmlmapvalue
\let\xmlval \xmlvalue
-% brrrr, give this at the top of a style that needs to stub mkiv loading
+%D Experimental:
+
+\def\xmlgetindex #1{\ctxlua{lxml.getindex("\xmldocument","#1")}}
+\def\xmlrawindex #1{\ctxlua{lxml.rawindex("#1")}}
+\def\xmlwithindex #1#2{\ctxlua{lxml.withindex("\xmldocument","#1","#2")}}
+\def\xmlreference #1#2{\string\xmlwithindex{#1}{#2}}
+
+%D Entities:
+
+\chardef\xmlautoentities=1 % 0=off, 1=upper, 2=upper,lower
+
+\let\isolatedentity\firstofoneargument
+
+\def\xmlsetentity#1#2{\ctxlua{xml.register_entity('#1',\!!bs\detokenize{#2}\!!es)}}
+\def\xmltexentity#1#2{\ctxlua{xml.register_entity('#1',\!!bs\detokenize{\isolatedentity{#2}}\!!es)}}
-\def\remapXMLtoMKIV
- {\ifx\xmldocument\undefined\def\xmldocument{main}\fi
- \def\processXMLfile ##1{\xmlprocessfile \xmldocument{##1}{}}%
- \def\processXMLfilegrouped ##1{\xmlprocessfile \xmldocument{##1}{}}% maybe still grouped?
- \def\processXMLbuffer {\dosingleempty\doprocessXMLbuffer}%
- \def\doprocessXMLbuffer [##1]{\xmlprocessbuffer\xmldocument{##1}{}}%
- \def\XMLdata ##1{\xmlprocessdata \xmldocument{##1}{}}%
- \def\startXMLdata##1\stopXMLdata{\xmlprocessdata \xmldocument{##1}{}}}
+% \xmlsetentity{tex}{\TEX{}} % {} needed
-\let\normalprocessXMLfilegrouped\processXMLfilegrouped
+\unexpanded\def\xmle
+ {\ifcase\xmlautoentities
+ \expandafter\xmle@none
+ \or
+ \expandafter\xmle@upper
+ \or
+ \expandafter\xmle@upperlower
+ \else
+ \expandafter\xmle@none
+ \fi}
+
+\def\xmle@none#1#2% safe
+ {#1}
-\def\processXMLfileMKIV % one-shot, will become obsolete, personal hack
- {\dosingleempty\doprocessXMLfileMKIV}
+\def\xmle@upper#1#2% can be abbreviation
+ {\ifcsname#2\endcsname
+ \csname#2\expandafter\endcsname
+ \else
+ #1%
+ \fi}
-\def\doprocessXMLfileMKIV[#1]%
- {\def\processXMLfilegrouped##1%
- {\let\processXMLfilegrouped\normalprocessXMLfilegrouped
- \doifelsenothing{#1}{\xmlprocess{main}{##1}{}}{\xmlprocess{#1}{##1}{}}}}
+\def\xmle@upperlower#1#2% can be anything, so unsafe
+ {\ifcsname#2\endcsname
+ \csname#2\expandafter\endcsname
+ \else\ifcsname#1\endcsname
+ \csname#1\expandafter\expandafter\expandafter\endcsname
+ \else
+ #1%
+ \fi\fi}
\protect \endinput
+
+% \newcount\charactersactiveoffset \charactersactiveoffset="10000
+%
+% \startextendcatcodetable\ctxcatcodes
+% \catcode\numexpr\charactersactiveoffset+`<\relax=13
+% \catcode\numexpr\charactersactiveoffset+`&\relax=13
+% \catcode\numexpr\charactersactiveoffset+`>\relax=13
+% \stopextendcatcodetable
+%
+% \startextendcatcodetable\xmlcatcodes % not needed
+% \catcode\numexpr\charactersactiveoffset+`<\relax=13
+% \catcode\numexpr\charactersactiveoffset+`&\relax=13
+% \catcode\numexpr\charactersactiveoffset+`>\relax=13
+% \stopextendcatcodetable
+%
+% \ctxlua { % entities are remembered in the format
+% characters.remapentity("<",characters.active_offset + utf.byte("<"))
+% characters.remapentity("&",characters.active_offset + utf.byte("&"))
+% characters.remapentity(">",characters.active_offset + utf.byte(">"))
+% }