diff options
Diffstat (limited to 'tex/context/base/mkiv/back-exp.mkxl')
-rw-r--r-- | tex/context/base/mkiv/back-exp.mkxl | 356 |
1 files changed, 356 insertions, 0 deletions
diff --git a/tex/context/base/mkiv/back-exp.mkxl b/tex/context/base/mkiv/back-exp.mkxl new file mode 100644 index 000000000..f248ca214 --- /dev/null +++ b/tex/context/base/mkiv/back-exp.mkxl @@ -0,0 +1,356 @@ +%D \module +%D [ file=back-exp, +%D version=2010.08.22, +%D title=\CONTEXT\ Backend Macros, +%D subtitle=XML export, +%D author=Hans Hagen, +%D date=\currentdate, +%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 +%C details. + +\writestatus{loading}{ConTeXt Backend Macros / XML export} + +\registerctxluafile{back-exp}{} + +%D This is an experimental exporter and a logical follow up on tagging. The +%D exporter assumes a properly tagged document. Some elements get a couple +%D of attributes because otherwise rendering information would get lost. In +%D general we assume that when the \XML\ is converted to \HTML\ some stylesheet +%D is applied anyway. + +\unprotect + +% we can replace this by a more generic attributeset mechanism where we bind +% to any element (needed anyway, see userdata thingies) + +\definesystemattribute[taggedpar][public] + +\permanent\tolerant\protected\def\setelementexporttag[#1]#*[#2]#*[#3]% + {\ifarguments\or\or + \clf_settagproperty{#1}{export}{#2}% + \or + \clf_settagproperty{#1}{#2}{#3}% + \fi} + +% todo: no need for calls when trialtypesetting + +\permanent\def\taggedctxcommand + {\iftrialtypesetting + \expandafter\gobbleoneargument + \else + \expandafter\ctxcommand + \fi} + +\newcount\tagparcounter + +\aliased\let\dotagsetparcounter\relax +\aliased\let\doresetparcounter \relax + +\appendtoks + \doresetparcounter +\to \everyflushatnextpar + +% \appendtoks +% \dotagsetparcounter +% \to \everypar + +\prependtoks + \dotagsetparcounter +\to \everypar + +% \appendtoks +% \dotagsetparcounter +% \to \neverypar + +\prependtoks + \dotagsetparcounter +\to \neverypar + +\appendtoks + \dotagsetparcounter +\to \everytabulatepar % tricky, maybe this should be neverypar + +\appendtoks + \enforced\permanent\protected\def\dotagTABLEcell + {\iftrialtypesetting\else + \clf_settagtablecell + \numexpr\tablecellrows\relax + \numexpr\tablecellcolumns\relax + \numexpr\raggedstatus\relax + \fi}% + % brrr, we need to tag empty cells (unless we start numbering) + \enforced\permanent\protected\def\dotagTABLEsignal + {\signalcharacter}% +\to \everyenableelements + +\appendtoks + \enforced\permanent\protected\def\dotagtabulatecell + {\iftrialtypesetting\else + \clf_settagtabulatecell\c_tabl_tabulate_align\c_tabl_tabulate_kind + \fi}% + \enforced\permanent\protected\def\dotagtabulatesignal + {\dontleavehmode\signalcharacter\ignorespaces}% +\to \everyenableelements + +\appendtoks + \enforced\permanent\protected\def\dotagsynonym + {\iftrialtypesetting\else\clf_settagsynonym{\currentsynonymtag}\fi}% +\to \everyenableelements + +\appendtoks + \enforced\permanent\protected\def\dotagsorting + {\iftrialtypesetting\else\clf_settagsorting{\currentsortingtag}\fi}% +\to \everyenableelements + +\appendtoks % frozen and assumed global per highlight class + \enforced\permanent\protected\def\dotagconstruct + {\iftrialtypesetting\else + \clf_settagconstruct + {\currentstartstop}% + {\startstopparameter\c!style}% + \c_attr_color + \ifvmode\plusone\else\zerocount\fi + \relax + \fi}% +\to \everyenableelements + +\appendtoks % frozen and assumed global per highlight class + \enforced\permanent\protected\def\dotaghighlight + {\iftrialtypesetting\else + \clf_settaghighlight + {\currenthighlight}% + {\highlightparameter\c!style} + \c_attr_color + \ifvmode\plusone\else\zerocount\fi + \relax + \fi}% +\to \everyenableelements + +\appendtoks % we can have differently scaled images + \enforced\permanent\protected\def\dotagfigure + {\iftrialtypesetting\else + \clf_settagfigure + {\figurefileoriginal}% + {\figurefullname}% + {\figurefilepage}% + \dimexpr\figurewidth\relax + \dimexpr\figureheight\relax + {\figurelabel}% + \fi}% +\to \everyenableelements + +\appendtoks + \enforced\permanent\protected\def\dotagcombination + {\iftrialtypesetting\else + \clf_settagcombination + \numexpr\combinationparameter\c!nx\relax + \numexpr\combinationparameter\c!ny\relax + \fi}% +\to \everyenableelements + +\appendtoks + \enforced\permanent\protected\def\dotagsetparcounter + {\global\advance\tagparcounter\plusone\c_attr_taggedpar\tagparcounter}% + \enforced\permanent\protected\def\doresetparcounter + {\c_attr_taggedpar\attributeunsetvalue}% +\to \everyenableelements + +\appendtoks + \enforced\permanent\protected\def\dotagsetitemgroup + {\iftrialtypesetting\else + \clf_settagitemgroup + \ifconditional\c_strc_itemgroups_pack true\else false\fi\space + \numexpr\currentitemlevel\relax + {\currentitemgroupsymbol}% + \fi}% + \enforced\permanent\protected\def\dotagsetitem#1% + {\iftrialtypesetting\else + \clf_settagitem{#1}% + \fi}% +\to \everyenableelements + +% \appendtoks +% \enforced\permanent\protected\def\dotagsetdescription +% {\iftrialtypesetting\else +% \clf_settagdescription{\currentdescription}\currentdescriptionnumberentry\relax +% \fi}% +% \to \everyenableelements + +\appendtoks + \enforced\permanent\protected\def\dotagsetnotation + {\iftrialtypesetting\else + \clf_settagnotation{\currentnote}\currentnotenumber\relax + \fi}% +\to \everyenableelements + +\appendtoks + \enforced\permanent\protected\def\dotagsetnotesymbol + {\iftrialtypesetting\else + \clf_settagnotationsymbol{\currentnote}\currentnotenumber\relax + \fi}% +\to \everyenableelements + +\appendtoks + \enforced\permanent\protected\def\dotagregisterlocation + {\iftrialtypesetting\else + \clf_settagregister{\currentregister}\currentregisternumber\relax + \fi}% +\to \everyenableelements + +\appendtoks + \enforced\permanent\protected\def\dotaglistlocation + {\iftrialtypesetting\else + \clf_settaglist\currentlistindex\relax + \fi}% +\to \everyenableelements + +\appendtoks + \enforced\permanent\protected\def\dotagsetdelimitedsymbol#1% + {\iftrialtypesetting\else + \clf_settagdelimitedsymbol{#1}\relax + \fi}% +\to \everyenableelements + +\appendtoks + \enforced\permanent\protected\def\dotagsetsubsentencesymbol#1% + {\iftrialtypesetting\else + \clf_settagsubsentencesymbol{#1}\relax + \fi}% +\to \everyenableelements + +\appendtoks + \enforced\permanent\protected\def\dotagregisterfloat#1#2% + {\iftrialtypesetting\else + \clf_settagfloat{#1}{#2}\relax + \fi}% +\to \everyenableelements + +\appendtoks + \enforced\let\specialfixedspace \explicitfixedspace + \enforced\let\specialobeyedspace \explicitobeyedspace + \enforced\let\specialstretchedspace\explicitstretchedspace + \enforced\let\specialcontrolspace \explicitcontrolspace +\to \everyenableelements + +\appendtoks + \enforced\permanent\protected\def\dotagregisterformula#1% + {\iftrialtypesetting\else + \clf_settagformulacontent#1\relax + \fi}% +\to \everyenableelements + +\appendtoks + \enforced\permanent\protected\def\dotagmarginanchor#1% + {\iftrialtypesetting\else\clf_settagmarginanchor#1\relax\fi}% + \enforced\permanent\protected\def\dotagmargintext#1% + {\iftrialtypesetting\else\clf_settagmargintext#1\relax\fi}% +\to \everyenableelements + +\appendtoks + \enforced\permanent\protected\def\dotagpublication#1#2% + {\iftrialtypesetting\else + \clf_settagpublication{#1}{#2}\relax + \fi}% +\to \everyenableelements + +\appendtoks + \enforced\permanent\protected\def\dotagparagraph#1% + {\iftrialtypesetting\else + \clf_settagparagraph{#1}\relax + \fi}% +\to \everyenableelements + +% The action: \setupbackend[export=yes] % or filename + +% maybe xhtml css settings will move to setupexport + +% maybe some day a definer + +\installcorenamespace{export} + +\installparameterhandler \??export {export} +\installsetuphandler \??export {export} + +\setupexport + [\c!align=\number\raggedstatus, + \c!bodyfont=\bodyfontsize, + \c!width=\textwidth, + \c!title={\directinteractionparameter\c!title}, + \c!subtitle={\directinteractionparameter\c!subtitle}, + \c!author={\directinteractionparameter\c!author}, + % \c!firstpage=, % imagename + % \c!lastpage=, % imagename + \c!properties=\v!no, % no: ignore, yes: as attribute, otherwise: use as prefix + \c!hyphen=\v!no, + \c!svgstyle=, + \c!cssfile=, + \c!file=] + +\resetsystemmode\v!export + +\permanent\protected\def\doinitializeexport + {\edef\p_export{\backendparameter\c!export}% + \ifx\p_export\empty \else + % yes | xml + \setuptagging[\c!state=\v!start]% + \clf_initializeexport + \setsystemmode\v!export + \exportingtrue + \writestatus\m!backend\empty % so messages will stand out a bit + \the\everyinitializeexport + \writestatus\m!backend\empty % so messages will stand out a bit + \enforced\glet\doinitializeexport\relax + \fi} + +\permanent\protected\def\dostartexport + {%\glet\dostartexport\relax + \let\currentexport\empty + \clf_setupexport + align {\exportparameter\c!align}% + bodyfont \dimexpr\exportparameter\c!bodyfont\relax + width \dimexpr\exportparameter\c!width\relax + properties {\exportparameter\c!properties}% + hyphen {\exportparameter\c!hyphen}% + title {\exportparameter\c!title}% + subtitle {\exportparameter\c!subtitle}% + author {\exportparameter\c!author}% + firstpage {\exportparameter\c!firstpage}% + lastpage {\exportparameter\c!lastpage}% + svgstyle {\exportparameter\c!svgstyle}% + cssfile {\exportparameter\c!cssfile}% + file {\exportparameter\c!file}% + export {\backendparameter\c!export}% + \relax} + +\permanent\protected\def\dostopexport + {\enforced\glet\dostopexport\relax + \clf_finishexport} + +\appendtoks + \doinitializeexport +\to \everysetupbackend + +\appendtoks + \ifexporting + \dostartexport + \fi +\to \everystarttext + +% better (before pdf gets closed, so we can embed), but it needs testing: + +\appendtoks + \ifexporting + \dostopexport + \fi +\to \everystoptext + +\appendtoks + \ifexporting + \dostartexport % in case it is done inside \starttext + \fi +\to \everystartdocument + +\protect \endinput |