summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/lxml-ini.mkiv
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/mkiv/lxml-ini.mkiv')
-rw-r--r--tex/context/base/mkiv/lxml-ini.mkiv261
1 files changed, 106 insertions, 155 deletions
diff --git a/tex/context/base/mkiv/lxml-ini.mkiv b/tex/context/base/mkiv/lxml-ini.mkiv
index 8860f62fe..3d3ef8733 100644
--- a/tex/context/base/mkiv/lxml-ini.mkiv
+++ b/tex/context/base/mkiv/lxml-ini.mkiv
@@ -26,84 +26,24 @@
\registerctxluafile{lxml-dir}{1.001} % ctx hacks
\registerctxluafile{lxml-ini}{1.001} % interface
-\unprotect % todo \!!bs \!!es where handy (slower)
+\unprotect
-% todo: { } mandate
-% avoid #
+% todo: { } mandate so that we can alias
+
+% undocumented:
\def\ctxlxml #1{\ctxlua{lxml.#1}}
-%def\xmlall #1#2{\clf_xmlall {#1}{#2}}
-%def\xmlatt #1#2{\clf_xmlatt {#1}{#2}}
-%def\xmlattdef #1#2#3{\clf_xmlattdef {#1}{#2}{#3}}
-%def\xmlattribute #1#2#3{\clf_xmlattribute {#1}{#2}{#3}}
-%def\xmlattributedef #1#2#3#4{\clf_xmlattributedef {#1}{#2}{#3}{#4}}
-%def\xmlchainatt #1#2{\clf_xmlchainatt {#1}{#2}}
-%def\xmlchainattdef #1#2#3{\clf_xmlchainattdef {#1}{#2}{#3}}
-%def\xmlrefatt #1#2{\clf_xmlrefatt {#1}{#2}}
-%def\xmlchecknamespace #1#2#3{\clf_xmlchecknamespace {#1}{#2}{#3}} % element
-%def\xmlcommand #1#2#3{\clf_xmlcommand {#1}{#2}{#3}}
+% for now indirect
+
\def\xmlconcat #1#2#3{\clf_xmlconcat {#1}{#2}{\detokenize{#3}}}
\def\xmlconcatrange #1#2#3#4#5{\clf_xmlconcatrange {#1}{#2}{#3}{#4}{\detokenize{#5}}}
-%def\xmlcontext #1#2{\clf_xmlcontext {#1}{#2}}
-%def\xmlcount #1#2{\clf_xmlcount {#1}{#2}}
-%def\xmldelete #1#2{\clf_xmldelete {#1}{#2}}
-%def\xmldirect #1{\clf_xmldirect {#1}} % in loops, not dt but root
-%def\xmldirectives #1{\clf_xmldirectives {#1}}
-%def\xmldirectivesafter #1{\clf_xmldirectivesafter {#1}}
-%def\xmldirectivesbefore #1{\clf_xmldirectivesbefore {#1}}
-%def\xmldisplayverbatim #1{\clf_xmldisplayverbatim {#1}}
-%def\xmlelement #1#2{\clf_xmlelement {#1}{#2}}
-%def\xmlfilter #1#2{\clf_xmlfilter {#1}{#2}}
-%def\xmlfilterlist #1#2{\clf_xmlfilterlist {#1}{#2}}
-%def\xmlfirst #1#2{\clf_xmlfirst {#1}{#2}}
-%def\xmlflush #1{\clf_xmlflush {#1}}
-%def\xmlflushcontext #1{\clf_xmlflushcontext {#1}}
-%def\xmlflushlinewise #1{\clf_xmlflushlinewise {#1}}
-%def\xmlflushspacewise #1{\clf_xmlflushspacewise {#1}}
-%def\xmlfunction #1#2{\clf_xmlfunction {#1}{#2}}
-%def\xmlinclude #1#2#3{\clf_xmlinclude {#1}{#2}{#3}}
-%def\xmlincludeoptions#1#2#3#4{\clf_xmlincludeoptions {#1}{#2}{#3}{#4}}
-%def\xmlinclusion #1{\clf_xmlinclusion {#1}}
-%def\xmlinclusions #1{\clf_xmlinclusions {#1}}
-%def\xmlbadinclusions #1{\clf_xmlbadinclusions {#1}}
-%def\xmlindex #1#2#3{\clf_xmlindex {#1}{#2}{#3}}
-%let\xmlposition \xmlindex
-%def\xmlinlineverbatim #1{\clf_xmlinlineverbatim {#1}}
-%def\xmllast #1#2{\clf_xmllast {#1}{#2}}
\def\xmlload #1#2{\clf_xmlload {#1}{#2}{\directxmlparameter\c!compress}}
\def\xmlloadbuffer #1#2{\clf_xmlloadbuffer {#1}{#2}{\directxmlparameter\c!compress}}
\def\xmlloaddata #1#2{\clf_xmlloaddata {#1}{#2}{\directxmlparameter\c!compress}}
-%def\xmlloaddirectives #1{\clf_xmlloaddirectives {#1}}
-%def\xmlloadregistered #1{\clf_xmlloadregistered {#1}}
-%def\xmlmain #1{\clf_xmlmain {#1}}
-%def\xmlmatch #1{\clf_xmlmatch {#1}}
-%def\xmlname #1{\clf_xmlname {#1}}
-%def\xmlnamespace #1{\clf_xmlnamespace {#1}}
-%def\xmlnonspace #1#2{\clf_xmlnonspace {#1}{#2}}
-%def\xmlpos #1{\clf_xmlpos {#1}}
-%def\xmlraw #1#2{\clf_xmlraw {#1}{#2}}
-%def\xmlregisterns #1#2{\clf_xmlregisterns {#1}{#2}} % document
-%def\xmlremapname #1#2#3#4{\clf_xmlremapname {#1}{#2}{#3}{#4}} % element
-%def\xmlremapnamespace #1#2#3{\clf_xmlremapnamespace {#1}{#2}{#3}} % document
-%def\xmlsave #1#2{\clf_xmlsave {#1}{#2}}
-%def\xmlsetfunction #1#2#3{\clf_xmlsetfunction {#1}{#2}{#3}}
-%def\xmlsetsetup #1#2#3{\clf_xmlsetsetup {#1}{#2}{#3}}
-%def\xmlsnippet #1#2{\clf_xmlsnippet {#1}{#2}}
-%def\xmlstrip #1#2{\clf_xmlstrip {#1}{#2}}
-%def\xmlstripanywhere #1#2{\clf_xmlstripanywhere {#1}{#2}}
-%def\xmlstripnolines #1#2{\clf_xmlstripnolines {#1}{#2}}
-%def\xmlstripped #1#2{\clf_xmlstripped {#1}{#2}}
-%def\xmlstrippednolines #1#2{\clf_xmlstrippednolines {#1}{#2}}
-%def\xmltag #1{\clf_xmltag {#1}}
-%def\xmltext #1#2{\clf_xmltext {#1}{#2}}
-%def\xmltobuffer #1#2#3{\clf_xmltobuffer {#1}{#2}{#3}} % id pattern name
-%def\xmltobufferverbose #1#2#3{\clf_xmltobufferverbose {#1}{#2}{#3}} % id pattern name
-%def\xmltofile #1#2#3{\clf_xmltofile {#1}{#2}{#3}} % id pattern filename
-%def\xmltoparameters #1{\clf_xmltoparameters {#1}}
-%def\xmlverbatim #1{\clf_xmlverbatim {#1}}
-
-% experiment:
+
+% aliased
+
\let\xmlall \clf_xmlall
\let\xmlatt \clf_xmlatt
\let\xmllastatt \clf_xmllastatt
@@ -115,8 +55,6 @@
\let\xmlrefatt \clf_xmlrefatt
\let\xmlchecknamespace \clf_xmlchecknamespace
\let\xmlcommand \clf_xmlcommand
-% \xmlconcat
-% \xmlconcatrange
\let\xmlcontext \clf_xmlcontext
\let\xmlcount \clf_xmlcount
\let\xmldelete \clf_xmldelete
@@ -143,11 +81,7 @@
\let\xmlposition \clf_xmlindex
\let\xmlinlineverbatim \clf_xmlinlineverbatim
\let\xmllast \clf_xmllast
-% \xmlload
-% \xmlloadbuffer
-% \xmlloaddata
\let\xmlloaddirectives \clf_xmlloaddirectives
-% \xmlloadregistered
\let\xmlmain \clf_xmlmain
\let\xmlmatch \clf_xmlmatch
\let\xmlname \clf_xmlname
@@ -159,7 +93,6 @@
\let\xmlremapname \clf_xmlremapname % element
\let\xmlremapnamespace \clf_xmlremapnamespace % document
\let\xmlsave \clf_xmlsave
-%let\xmlsetfunction \clf_xmlsetfunction
\let\xmlsetsetup \clf_xmlsetsetup
\let\xmlsnippet \clf_xmlsnippet
\let\xmlstrip \clf_xmlstrip
@@ -175,8 +108,8 @@
\let\xmltoparameters \clf_xmltoparameters
\let\xmlverbatim \clf_xmlverbatim
-\def\xmlinfo #1{\hbox{\ttxx[\clf_xmlinfo{#1}]}}
-\def\xmlshow #1{\startpacked\ttx\xmlverbatim{#1}\stoppacked}
+\unexpanded\def\xmlinfo #1{\hbox{\ttxx[\clf_xmlname{#1}]}}
+\unexpanded\def\xmlshow #1{\startpacked\ttx\xmlverbatim{#1}\stoppacked}
% the next one is handy for mode runs because it enforces a consistent
% #1 indexing (needed when using \xmltext{main:123}{...} like calls
@@ -185,7 +118,7 @@
% we need to pass the last argument as function, so
-\def\xmlsetfunction#1#2#3{\ctxcommand{xmlsetfunction("#1",\!!bs#2\!!es,#3)}}
+\unexpanded\def\xmlsetfunction#1#2#3{\ctxcommand{xmlsetfunction("#1",\!!bs#2\!!es,#3)}}
% goodie:
@@ -199,12 +132,12 @@
% kind of special:
-%def\xmlstartraw{\clf_xmlstartraw}
-%def\xmlstopraw {\clf_xmlstopraw}
-
\let\xmlstartraw\clf_xmlstartraw
\let\xmlstopraw \clf_xmlstopraw
+\let\startxmlraw\clf_xmlstartraw
+\let\stopxmlraw \clf_xmlstopraw
+
% these are expandable! todo: \xmldoifelseattribute
\let\xmldoif \clf_xmldoif
@@ -231,34 +164,30 @@
%
% \xmlprependsetup{xml:include}
-\let\xmlgrab\xmlsetsetup % obsolete
-\let\xmlself\s!unknown % obsolete
+% \let\xmlgrab\xmlsetsetup % obsolete
+% \let\xmlself\s!unknown % obsolete
-%\ef\xmlsetup#1#2{\setupwithargument{#2}{#1}}
\let\xmlsetup\setupwithargumentswapped
-
-\let\xmls\setupwithargumentswapped % hardly any faster
-\let\xmlw\setupwithargument % hardly any faster
-
-\newtoks \registeredxmlsetups
+\let\xmls \setupwithargumentswapped % hardly any faster
+\let\xmlw \setupwithargument % hardly any faster
% todo: 1:xml:whatever always before 3:xml:something
-\unexpanded\def\xmlprependsetup #1{\clf_xmlprependsetup {*}{#1}}
-\unexpanded\def\xmlappendsetup #1{\clf_xmlappendsetup {*}{#1}}
-\unexpanded\def\xmlbeforesetup #1#2{\clf_xmlbeforesetup {*}{#1}{#2}}
-\unexpanded\def\xmlaftersetup #1#2{\clf_xmlaftersetup {*}{#1}{#2}}
-
-\unexpanded\def\xmlprependdocumentsetup #1#2{\clf_xmlprependdocumentsetup{#1}{#2}}
-\unexpanded\def\xmlappenddocumentsetup #1#2{\clf_xmlappenddocumentsetup {#1}{#2}}
-\unexpanded\def\xmlbeforedocumentsetup #1#2#3{\clf_xmlbeforedocumentsetup {#1}{#2}{#3}}
-\unexpanded\def\xmlafterdocumentsetup #1#2#3{\clf_xmlafterdocumentsetup {#1}{#2}{#3}}
+\unexpanded\def\xmlprependsetup #1{\clf_xmlprependsetup{*}{#1}}
+\unexpanded\def\xmlappendsetup #1{\clf_xmlappendsetup {*}{#1}}
+\unexpanded\def\xmlbeforesetup #1#2{\clf_xmlbeforesetup {*}{#1}{#2}}
+\unexpanded\def\xmlaftersetup #1#2{\clf_xmlaftersetup {*}{#1}{#2}}
+\unexpanded\def\xmlremovesetup #1{\clf_xmlremovesetup {*}{#1}}
+\unexpanded\def\xmlresetsetups {\clf_xmlresetsetups {*}}
-\unexpanded\def\xmlremovesetup #1{\clf_xmlremovesetup {*}{#1}}
-\unexpanded\def\xmlremovedocumentsetup #1#2{\clf_xmlremovedocumentsetup {#1}{#2}}
+\unexpanded\def\xmlprependdocumentsetup #1#2{\clf_xmlprependsetup{#1}{#2}}
+\unexpanded\def\xmlappenddocumentsetup #1#2{\clf_xmlappendsetup {#1}{#2}}
+\unexpanded\def\xmlbeforedocumentsetup #1#2#3{\clf_xmlbeforesetup {#1}{#2}{#3}}
+\unexpanded\def\xmlafterdocumentsetup #1#2#3{\clf_xmlaftersetup {#1}{#2}{#3}}
+\unexpanded\def\xmlremovedocumentsetup #1#2{\clf_xmlremovesetup {#1}{#2}}
+\unexpanded\def\xmlresetdocumentsetups #1{\clf_xmlresetsetups {#1}}
-\unexpanded\def\xmlflushdocumentsetups #1#2{\clf_xmlflushdocumentsetups {#1}{*}{#2}} % #1 == id where to apply * and #2
-\unexpanded\def\xmlresetdocumentsetups #1{\clf_xmlresetdocumentsetups {#1}}
+\unexpanded\def\xmlflushdocumentsetups #1#2{\clf_xmlflushsetups {#1}{*}{#2}} % #1 == id where to apply * and #2
\let\xmlregistersetup \xmlappendsetup
\let\xmlregisterdocumentsetup\xmlappenddocumentsetup
@@ -278,8 +207,8 @@
\xmldefaulttotext{#1}% after include
\xmlstoptiming}
-\unexpanded\def\xmlstarttiming{\clf_xmlstarttiming}
-\unexpanded\def\xmlstoptiming {\clf_xmlstoptiming}
+\unexpanded\def\xmlstarttiming{\clf_xmlstarttiming} % undocumented
+\unexpanded\def\xmlstoptiming {\clf_xmlstoptiming} % undocumented
\def\lxml_process#1#2#3#4#5% flag \loader id name what initializersetup
{\begingroup
@@ -296,7 +225,6 @@
\unexpanded\def\xmlprocessfile {\lxml_process\plusone \xmlload}
\unexpanded\def\xmlprocessdata {\lxml_process\zerocount\xmlloaddata}
\unexpanded\def\xmlprocessbuffer {\lxml_process\zerocount\xmlloadbuffer}
-\unexpanded\def\xmlprocessregistered{\lxml_process\zerocount\xmlloadregistered}
\let\xmlprocess \xmlprocessfile
\startxmlsetups xml:flush
@@ -312,24 +240,22 @@
{\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
-
-\unexpanded\def\xmlconnect#1#2#3% inefficient
- {\scratchcounter\xmlcount{#1}{#2}\relax
- \ifcase\scratchcounter \or
- \xmlall{#1}{#2}%
- \else
- \dorecurse \scratchcounter
- {\ifnum\recurselevel>\plusone#3\fi
- \xmlidx{#1}{#2}\recurselevel}%
- \fi}
+% replaced by concat
+%
+% \unexpanded\def\xmlconnect#1#2#3% inefficient
+% {\scratchcounter\xmlcount{#1}{#2}\relax
+% \ifcase\scratchcounter \or
+% \xmlall{#1}{#2}%
+% \else
+% \dorecurse \scratchcounter
+% {\ifnum\recurselevel>\plusone#3\fi
+% \xmlidx{#1}{#2}\recurselevel}%
+% \fi}
\unexpanded\def\xmlcdataobeyedline {\obeyedline}
\unexpanded\def\xmlcdataobeyedspace{\strut\obeyedspace}
-\unexpanded\def\xmlcdatabefore {\bgroup\tt}
-\unexpanded\def\xmlcdataafter {\egroup}
+\unexpanded\def\xmlcdatabefore {\begingroup\tt}
+\unexpanded\def\xmlcdataafter {\endgroup}
% verbatim (dodo:pre/post whitespace, maybe splot verbatim and
% cdata commands), experimental:
@@ -343,37 +269,37 @@
%
% this is experimental!
-\unexpanded\def\startxmldisplayverbatim[#1]%
- {\startpacked % \begingroup
- \edef\currenttyping{xml:#1}%
+\unexpanded\def\startxmldisplayverbatim
+ {\dosingleempty\lxml_start_display_verbatim}
+
+\def\lxml_start_display_verbatim[#1]%
+ {\startpacked
+ \edef\currenttyping{#1}%
+ \ifx\currenttyping\empty
+ \let\currenttyping\v!typing
+ \else % maybe test for existence
+ \edef\currenttyping{xml:\currenttyping}%
+ \fi
\unexpanded\def\stopxmldisplayverbatim
{\endofverbatimlines
- \stoppacked} % \endgroup
+ \stoppacked}
\doinitializeverbatim
\beginofverbatimlines}
-\unexpanded\def\startxmlinlineverbatim[#1]%
+\unexpanded\def\startxmlinlineverbatim
+ {\dosingleempty\lxml_start_inline_verbatim}
+
+\unexpanded\def\lxml_start_inline_verbatim[#1]%
{\begingroup
- \edef\currenttype{xml:#1}%
+ \edef\currenttype{#1}%
+ \ifx\currenttype\empty
+ \let\currenttype\v!type
+ \else % maybe test for existence
+ \edef\currenttype{xml:\currenttype}%
+ \fi
\let\stopxmlinlineverbatim\endgroup
\doinitializeverbatim}
-% will move but is developed for xml
-
-\newtoks \collectingtoks
-
-\unexpanded\def\startcollect#1\stopcollect
- {\collectingtoks\@EA{\the\collectingtoks#1}}
-
-\unexpanded\def\startexpandedcollect#1\stopexpandedcollect
- {\normalexpanded{\collectingtoks{\the\collectingtoks#1}}}
-
-\unexpanded\def\startcollecting{\collectingtoks\emptytoks}
-\unexpanded\def\stopcollecting {\the\collectingtoks}
-
-\def\inlinemessage #1{\dontleavehmode{\tttf#1}}
-\def\displaymessage#1{\blank\inlinemessage{#1}\blank}
-
% processing instructions
\unexpanded\def\xmlinstalldirective#1#2%
@@ -405,13 +331,13 @@
\unexpanded\def\xmldefaulttotext
{\ifcase\xmlprocessingmode
- \expandafter\gobbleoneargument % unset
+ \expandafter\gobbleoneargument % 0 (none)
\or
- \expandafter\clf_xmlsetcommandtotext % 1
+ \expandafter\clf_xmlsetcommandtotext % 1 (normal)
\or
- \expandafter\clf_xmlsetcommandtonone % 2
+ \expandafter\clf_xmlsetcommandtonone % 2 (hidden)
\else
- \expandafter\gobbleoneargument % unset
+ \expandafter\gobbleoneargument % (none)
\fi}
\appendtoks
@@ -421,11 +347,13 @@
\setupxml
[\c!default=, % flush all
\c!compress=\v!no, % strip comment
- \c!entities=\v!yes] % replace entities
+ \c!entities=\v!no] % load big entity file
+
+\appendtoks
+ \doif{\directxmlparameter\c!entities}\clf_xmlloadentities
+\to \everysetupxml
\def\xmlmapvalue #1#2#3{\setvalue{\??xmlmapvalue#1:#2}{#3}} % keep #3 to grab spaces
-%def\xmlvalue #1#2#3{\executeifdefined{\??xmlmapvalue#1:#2}{#3}}
-%def\xmlvalue #1#2{\ifcsname\??xmlmapvalue#1:#2\endcsname\csname\??xmlmapvalue#1:#2\expandafter\expandafter\gobbleoneargument\expandafter\endcsname\else\expandafter\firstofoneargument\fi}
\def\xmldoifelsevalue #1#2{\ifcsname\??xmlmapvalue#1:#2\endcsname\expandafter\firstoftwoarguments\else\expandafter\secondoftwoarguments\fi}
\def\xmlvalue#1#2% #3
@@ -453,14 +381,18 @@
\def\xmlwithindex #1#2{\clf_xmlwithindex{\xmldocument}{#1}{#2}}
\def\xmlreference #1#2{\string\xmlwithindex{#1}{#2}}
-%D Entities (might change):
-
-\setnewconstant\xmlautoentities\plusone % 0=off, 1=upper, 2=upper,lower
+%D Entities:
+%D
+%D \starttyping
+%D \xmlsetentity{tex}{\TEX{}} % {} needed
+%D \stoptyping
\unexpanded\def\xmlsetentity#1#2{\clf_xmlsetentity{#1}{\detokenize{#2}}}
\unexpanded\def\xmltexentity#1#2{\clf_xmltexentity{#1}{\detokenize{#2}}}
-% \xmlsetentity{tex}{\TEX{}} % {} needed
+%D The following might change (or even disappear) so we keep it undocumented.
+
+\setnewconstant\xmlautoentities\plusone % 0=off, 1=upper, 2=upper,lower
\unexpanded\def\xmle
{\ifcase\xmlautoentities
@@ -492,7 +424,24 @@
#1%
\fi\fi}
-% handy helpers (analogue to MP and LUA and TEX and also MkII)
+% \def\lxml_e_upper#1#2% can be abbreviation
+% {\ifcsname\detokenize{#2}\endcsname
+% \lastnamedcs
+% \else
+% \detokenize{#1}%
+% \fi}
+
+% \def\lxml_e_upperlower#1#2% can be anything, so unsafe
+% {\ifcsname\detokenize{#2}\endcsname
+% \expandafter\lastnamedcs
+% \else\ifcsname\detokenize{#1}\endcsname
+% \doubleexpandafter\lastnamedcs
+% \else
+% \detokenize{#1}%
+% \fi\fi}
+
+%D We keep these around as there are also MP, LUA and TEX variants but
+%D they are not the same as in \MKII.
\unexpanded\def\processXMLbuffer
{\dosingleempty\lxml_process_buffer}
@@ -538,6 +487,8 @@
\let\xmlapplyselectors\clf_xmlapplyselectors
+% \let\xmlcatcodes\notcatcodes
+
\protect \endinput
% \newcount\charactersactiveoffset \charactersactiveoffset="10000