[dev-context] xml and tuo files
Hans Hagen
pragma at wxs.nl
Thu Jul 21 15:52:32 CEST 2005
Hi,
FYI
\unprotect
\mathchardef \utf at h=2048
\def\numbertoutf#1%
{\ifnum#1<128
\rawcharacter{#1}%
\else\ifnum#1<2048
\rawcharacter{\the\numexpr192+#1/64\relax}%
\rawcharacter{\the\numexpr128+#1-(#1/64)*64\relax}%
\else % 3 bytes
\rawcharacter{\the\numexpr224+#1/4096\relax}%
\rawcharacter{\the\numexpr128+(#1-(#1/4096)*4096)/128\relax}%
\rawcharacter{\the\numexpr128+(#1-(#1/4096)*4096)+(#1-(#1/4096)*4096)/128\relax}%
\fi\fi}
\def\numbertoutf#1% raw characters are not active
{\ifnum#1<\utf at g
\rawcharacter{#1}%
\else\ifnum#1<\utf at h
\rawcharacter{\the\numexpr\utf at d+#1/\utf at a\relax}%
\rawcharacter{\the\numexpr\utf at g+#1-(#1/\utf at a)*\utf at a\relax}%
\else
\rawcharacter{\the\numexpr\utf at e+#1/\utf at b\relax}%
\rawcharacter{\the\numexpr\utf at g+(#1-(#1/\utf at b)*\utf at b)/\utf at g\relax}%
\rawcharacter{\the\numexpr\utf at g+(#1-(#1/\utf at b)*\utf at b)+(#1-(#1/\utf at b)*\utf at b)/\utf at g\relax}%
\fi\fi}
\unprotect
\def\v!xml{xml}
\setupXMLprocessing
[\c!escape=e]
\def\XMLprocessingparameter#1%
{\csname\??xp#1\endcsname}
\appendtoks
\defineXMLargument[\XMLprocessingparameter\c!escape]\getXMlentity
\to \aftersetupXMLprocessing
Hi,
In the end i want more clever tuo/xml interaction, but for the moment i
can provide:
\bgroup \catcode`\<=\active
\long\gdef\expandxmlargument#1\to
{\begingroup
\let\uppercase\firstofoneargument
\def\getXMLhexcharacter##1{\numbertoutf{"##1}}%
\def\getXMLdeccharacter##1{\numbertoutf{##1}}%
\def\getXMLentity##1{<e>##1</e>}
\def<{\noexpand<}%
\xdef\@@globalexpanded{#1}%
\endgroup
\convertcommand\@@globalexpanded\to}
\egroup
\installexpander \v!xml {\expandxmlargument}
\protect
\setuphead[chapter][expansion=xml]
\setuplist[chapter][textcommand=\enableXML]
\enableregime[utf]
\starttext
\placelist[chapter]
\defineXMLargument[chapter]{\chapter}
\startXMLdata
<chapter>test ë test &oeps; test <e>ediaresis</e></chapter>
\stopXMLdata
\stoptext
I hope that i got the utf converter right
Hans
-----------------------------------------------------------------
Hans Hagen | PRAGMA ADE
Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
| www.pragma-pod.nl
-----------------------------------------------------------------
More information about the dev-context
mailing list