diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/lxml-ini.mkiv')
-rw-r--r-- | Master/texmf-dist/tex/context/base/lxml-ini.mkiv | 162 |
1 files changed, 94 insertions, 68 deletions
diff --git a/Master/texmf-dist/tex/context/base/lxml-ini.mkiv b/Master/texmf-dist/tex/context/base/lxml-ini.mkiv index a1d6b50a878..84ebc58233c 100644 --- a/Master/texmf-dist/tex/context/base/lxml-ini.mkiv +++ b/Master/texmf-dist/tex/context/base/lxml-ini.mkiv @@ -5,7 +5,7 @@ %D subtitle=Initialization, %D author=Hans Hagen, %D date=\currentdate, -%D copyright={PRAGMA / Hans Hagen \& Ton Otten}] +%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}] %C %C This module is part of the \CONTEXT\ macro||package and is %C therefore copyrighted by \PRAGMA. See mreadme.pdf for @@ -20,13 +20,12 @@ %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{char-ent}{1.001} \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 +\unprotect % todo \!!bs \!!es where handy (slower) \def\ctxlxml #1{\directlua\zerocount{lxml.#1}} @@ -52,6 +51,8 @@ \def\xmlfunction #1#2{\ctxlxml{applyfunction("#1",\!!bs#2\!!es)}} \def\xmlfirst #1#2{\ctxlxml{first("#1","#2")}} \def\xmlflush #1{\ctxlxml{flush("#1")}} +\def\xmlflushlinewise #1{\ctxlxml{flushlinewise("#1")}} +\def\xmlflushspacewise #1{\ctxlxml{flushspacewise("#1")}} %def\xmlcontent #1{\ctxlxml{content("#1")}} %def\xmlflushstripped #1{\ctxlxml{strip("#1",true)}} \def\xmldirect #1{\ctxlxml{direct("#1")}} % in loops, not dt but root @@ -86,10 +87,10 @@ \def\xmldisplayverbatim #1{\ctxlxml{displayverbatim("#1")}} \def\xmlinlineverbatim #1{\ctxlxml{inlineverbatim("#1")}} -\def\xmlload #1#2{\ctxlxml{load("#1","#2","\@@xmentities","\@@xmcompress")}} -\def\xmlloadbuffer #1#2{\ctxlxml{loadbuffer("#1","#2","\@@xmentities","\@@xmcompress")}} -\def\xmlloaddata #1#2{\ctxlxml{loaddata("#1",\!!bs#2\!!es,"\@@xmentities","\@@xmcompress")}} -\def\xmlloadregistered #1#2{\ctxlxml{loadregistered("#1","\@@xmentities","\@@xmcompress")}} +\def\xmlload #1#2{\ctxlxml{load("#1","#2","\p_lxml_entities","\p_lxml_compress")}} +\def\xmlloadbuffer #1#2{\ctxlxml{loadbuffer("#1","#2","\p_lxml_entities","\p_lxml_compress")}} +\def\xmlloaddata #1#2{\ctxlxml{loaddata("#1",\!!bs#2\!!es,"\p_lxml_entities","\p_lxml_compress")}} +\def\xmlloadregistered #1#2{\ctxlxml{loadregistered("#1","\p_lxml_entities","\p_lxml_compress")}} \def\xmlloaddirectives #1{\ctxlxml{directives.load("any:///#1")}} \def\xmlpos #1{\ctxlxml{pos("#1")}} @@ -104,12 +105,12 @@ % todo: \xmldoifelseattribute -\def\xmldoif #1#2{\ctxlxml{doif (\!!bs#1\!!es,\!!bs#2\!!es)}} -\def\xmldoifnot #1#2{\ctxlxml{doifnot (\!!bs#1\!!es,\!!bs#2\!!es)}} -\def\xmldoifelse #1#2{\ctxlxml{doifelse (\!!bs#1\!!es,\!!bs#2\!!es)}} -\def\xmldoiftext #1#2{\ctxlxml{doiftext (\!!bs#1\!!es,\!!bs#2\!!es)}} -\def\xmldoifnottext #1#2{\ctxlxml{doifnottext (\!!bs#1\!!es,\!!bs#2\!!es)}} -\def\xmldoifelsetext #1#2{\ctxlxml{doifelsetext(\!!bs#1\!!es,\!!bs#2\!!es)}} +\def\xmldoif #1#2{\ctxlxml{doif (\!!bs#1\!!es,\!!bs#2\!!es)}} % expandable +\def\xmldoifnot #1#2{\ctxlxml{doifnot (\!!bs#1\!!es,\!!bs#2\!!es)}} % expandable +\def\xmldoifelse #1#2{\ctxlxml{doifelse (\!!bs#1\!!es,\!!bs#2\!!es)}} % expandable +\def\xmldoiftext #1#2{\ctxlxml{doiftext (\!!bs#1\!!es,\!!bs#2\!!es)}} % expandable +\def\xmldoifnottext #1#2{\ctxlxml{doifnottext (\!!bs#1\!!es,\!!bs#2\!!es)}} % expandable +\def\xmldoifelsetext #1#2{\ctxlxml{doifelsetext(\!!bs#1\!!es,\!!bs#2\!!es)}} % expandable %def\xmldoifelseempty #1#2{\ctxlxml{doifelseempty("#1","#2")}} % #2, "*" or "" == self not yet implemented %def\xmldoifelseselfempty #1{\ctxlxml{doifelseempty("#1")}} @@ -132,44 +133,44 @@ % todo: 1:xml:whatever always before 3:xml:something -\def\xmlprependsetup #1{\ctxlxml{installsetup(1,"*","#1")}} -\def\xmlappendsetup #1{\ctxlxml{installsetup(2,"*","#1")}} -\def\xmlbeforesetup #1#2{\ctxlxml{installsetup(3,"*","#1","#2"))}} -\def\xmlaftersetup #1#2{\ctxlxml{installsetup(4,"*","#1","#2"))}} +\unexpanded\def\xmlprependsetup #1{\ctxlxml{installsetup(1,"*","#1")}} +\unexpanded\def\xmlappendsetup #1{\ctxlxml{installsetup(2,"*","#1")}} +\unexpanded\def\xmlbeforesetup #1#2{\ctxlxml{installsetup(3,"*","#1","#2")}} +\unexpanded\def\xmlaftersetup #1#2{\ctxlxml{installsetup(4,"*","#1","#2")}} -\def\xmlprependdocumentsetup #1#2{\ctxlxml{installsetup(1,"#1","#2")}} -\def\xmlappenddocumentsetup #1#2{\ctxlxml{installsetup(2,"#1","#2")}} -\def\xmlbeforedocumentsetup#1#2#3{\ctxlxml{installsetup(3,"#1","#2","#3"))}} -\def\xmlafterdocumentsetup #1#2#3{\ctxlxml{installsetup(4,"#1","#2","#3"))}} +\unexpanded\def\xmlprependdocumentsetup #1#2{\ctxlxml{installsetup(1,"#1","#2")}} +\unexpanded\def\xmlappenddocumentsetup #1#2{\ctxlxml{installsetup(2,"#1","#2")}} +\unexpanded\def\xmlbeforedocumentsetup#1#2#3{\ctxlxml{installsetup(3,"#1","#2","#3")}} +\unexpanded\def\xmlafterdocumentsetup #1#2#3{\ctxlxml{installsetup(4,"#1","#2","#3")}} -\def\xmlremovesetup #1{\ctxlxml{removesetup("*","#1")}} -\def\xmlremovedocumentsetup #1#2{\ctxlxml{removesetup("#1","#2")}} +\unexpanded\def\xmlremovesetup #1{\ctxlxml{removesetup("*","#1")}} +\unexpanded\def\xmlremovedocumentsetup #1#2{\ctxlxml{removesetup("#1","#2")}} -\def\xmlflushdocumentsetups #1#2{\ctxlxml{flushsetups("#1","*","#2")}} % #1 == id where to apply * and #2 -\def\xmlresetdocumentsetups #1{\ctxlxml{resetsetups("#1")}} +\unexpanded\def\xmlflushdocumentsetups #1#2{\ctxlxml{flushsetups("#1","*","#2")}} % #1 == id where to apply * and #2 +\unexpanded\def\xmlresetdocumentsetups #1{\ctxlxml{resetsetups("#1")}} \let\xmlregistersetup \xmlappendsetup \let\xmlregisterdocumentsetup\xmlappenddocumentsetup \def\xmldocument{main} -\def\xmlregisteredsetups +\unexpanded\def\xmlregisteredsetups {\xmlstarttiming \xmlflushsetups \xmldefaulttotext\xmldocument % after include \xmlstoptiming} -\def\xmlregistereddocumentsetups#1#2% id setups +\unexpanded\def\xmlregistereddocumentsetups#1#2% id setups {\xmlstarttiming % todo: test for duplicates ! \xmlflushdocumentsetups{#1}{#2}% \xmldefaulttotext{#1}% after include \xmlstoptiming} -\def\xmlstarttiming{\ctxlua{statistics.starttiming(lxml)}} -\def\xmlstoptiming {\ctxlua{statistics.stoptiming (lxml)}} +\unexpanded\def\xmlstarttiming{\ctxlua{statistics.starttiming(lxml)}} +\unexpanded\def\xmlstoptiming {\ctxlua{statistics.stoptiming (lxml)}} -\def\doxmlprocess#1#2#3#4#5% flag \loader id name what initializersetup +\def\lxml_process#1#2#3#4#5% flag \loader id name what initializersetup {\begingroup \edef\xmldocument{#3}% #2 can be \xmldocument and set as such %xmlpushdocument{#3}% @@ -181,10 +182,10 @@ %xmlpopdocument \endgroup} -\def\xmlprocessfile {\doxmlprocess\plusone \xmlload} -\def\xmlprocessdata {\doxmlprocess\zerocount\xmlloaddata} -\def\xmlprocessbuffer {\doxmlprocess\zerocount\xmlloadbuffer} -\def\xmlprocessregistered{\doxmlprocess\zerocount\xmlloadregistered} +\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 @@ -196,7 +197,7 @@ \xmlmain{#1} \stopxmlsetups -\def\xmlloadonly#1#2#3% +\unexpanded\def\xmlloadonly#1#2#3% {\xmlload{#1}{#2}% \xmlregistereddocumentsetups{#1}{#3}} @@ -204,7 +205,7 @@ % instructions preceding the root element; well, in some % sense that is the root -\long\def\xmlconnect#1#2#3% inefficient +\unexpanded\def\xmlconnect#1#2#3% inefficient {\scratchcounter\xmlcount{#1}{#2}\relax \ifcase\scratchcounter \or \xmlall{#1}{#2}% @@ -214,10 +215,10 @@ \xmlidx{#1}{#2}\recurselevel}% \fi} -\def\xmlcdataobeyedline {\obeyedline} -\def\xmlcdataobeyedspace{\strut\obeyedspace} -\def\xmlcdatabefore {\bgroup\tt} -\def\xmlcdataafter {\egroup} +\unexpanded\def\xmlcdataobeyedline {\obeyedline} +\unexpanded\def\xmlcdataobeyedspace{\strut\obeyedspace} +\unexpanded\def\xmlcdatabefore {\bgroup\tt} +\unexpanded\def\xmlcdataafter {\egroup} % verbatim (dodo:pre/post whitespace, maybe splot verbatim and % cdata commands), experimental: @@ -238,7 +239,6 @@ \unexpanded\def\startxmldisplayverbatim[#1]% {\startpacked % \begingroup - \let\currenttypingclass\??tp \edef\currenttyping{xml:#1}% \unexpanded\def\stopxmldisplayverbatim {\endofverbatimlines @@ -248,8 +248,7 @@ \unexpanded\def\startxmlinlineverbatim[#1]% {\begingroup - \let\currenttypingclass\??ty - \edef\currenttyping{xml:#1}% + \edef\currenttype{xml:#1}% \let\stopxmldisplayverbatim\endgroup \doinitializeverbatim} @@ -288,16 +287,18 @@ \newconstant\xmlprocessingmode % 0=unset, 1=text, 2=hidden -\newtoks\everysetupxml +\installcorenamespace{xml} +\installcorenamespace{xmldefaults} +\installcorenamespace{xmlmapvalue} -\unexpanded\def\setupxml[#1]{\getparameters[\??xm][#1]\the\everysetupxml} +\installdirectcommandhandler \??xml {xml} -\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{\??xmldefaults\v!normal}\zerocount +\letvalue{\??xmldefaults\v!none }\zerocount +\letvalue{\??xmldefaults\v!text }\plusone +\letvalue{\??xmldefaults\v!hidden}\plustwo -\def\xmldefaulttotext#1% +\unexpanded\def\xmldefaulttotext#1% {\ifcase\xmlprocessingmode % unset \or @@ -309,20 +310,29 @@ \fi} \appendtoks - \xmlprocessingmode\executeifdefined{\??xm:\s!default:\@@xmdefault}\plusone + \xmlprocessingmode\executeifdefined{\??xmldefaults\directxmlparameter\c!default}\plusone \to \everysetupxml -\def\xmlinitialize{\the\everysetupxml} +\unexpanded\def\xmlinitialize + {\the\everysetupxml} + +\let\p_lxml_entities\empty +\let\p_lxml_compress\empty + +\appendtoks + \edef\p_lxml_entities{\directxmlparameter\c!entities}% + \edef\p_lxml_compress{\directxmlparameter\c!compress}% +\to \everysetupxml \setupxml [\c!default=, % flush all \c!compress=\v!no, % strip comment \c!entities=\v!yes] % replace entities -\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} +\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} \let\xmlmapval\xmlmapvalue \let\xmlval \xmlvalue @@ -334,39 +344,37 @@ \def\xmlwithindex #1#2{\ctxlxml{withindex("\xmldocument","#1","#2")}} \def\xmlreference #1#2{\string\xmlwithindex{#1}{#2}} -%D Entities: +%D Entities (might change): \setnewconstant\xmlautoentities\plusone % 0=off, 1=upper, 2=upper,lower -\let\isolatedentity\firstofoneargument - \def\xmlsetentity#1#2{\ctxlua{xml.registerentity('#1',\!!bs\detokenize{#2}\!!es)}} -\def\xmltexentity#1#2{\ctxlua{xml.registerentity('#1',\!!bs\detokenize{\isolatedentity{#2}}\!!es)}} +\def\xmltexentity#1#2{\ctxlua{lxml.registerentity('#1',\!!bs\detokenize{#2}\!!es)}} % \xmlsetentity{tex}{\TEX{}} % {} needed \unexpanded\def\xmle {\ifcase\xmlautoentities - \expandafter\xmle@none + \expandafter\lxml_e_none \or - \expandafter\xmle@upper + \expandafter\lxml_e_upper \or - \expandafter\xmle@upperlower + \expandafter\lxml_e_upperlower \else - \expandafter\xmle@none + \expandafter\lxml_e_none \fi} -\def\xmle@none#1#2% safe +\def\lxml_e_none#1#2% safe {#1} -\def\xmle@upper#1#2% can be abbreviation +\def\lxml_e_upper#1#2% can be abbreviation {\ifcsname#2\endcsname \csname#2\expandafter\endcsname \else #1% \fi} -\def\xmle@upperlower#1#2% can be anything, so unsafe +\def\lxml_e_upperlower#1#2% can be anything, so unsafe {\ifcsname#2\endcsname \csname#2\expandafter\endcsname \else\ifcsname#1\endcsname @@ -375,6 +383,24 @@ #1% \fi\fi} +% handy helpers (analogue to MP and LUA and TEX and also MkII) + +\unexpanded\def\processXMLbuffer + {\dosingleempty\lxml_process_buffer} + +\def\lxml_process_buffer[#1]% + {\xmlprocessbuffer{temp}{#1}{}} + +\unexpanded\def\processXMLfile#1% + {\xmlprocessfile{temp}{#1}{}} + +\unexpanded\def\XMLdata#1% + {\xmlprocessdata{temp}{#1}{}} + +\let\processxmlbuffer\processXMLbuffer +\let\processxmlfile \processXMLfile +\let\xmldata \XMLdata + \protect \endinput % \newcount\charactersactiveoffset \charactersactiveoffset="10000 |