%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.lua}{1.001} %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 becaus eitherwise 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] \def\setelementexporttag {\dotripleargument\dosetelementexporttag} \def\dosetelementexporttag {\ifthirdargument \expandafter\dosetelementexporttaga \else\ifsecondargument \expandafter\expandafter\expandafter\dosetelementexporttagb \fi\fi} \def\dosetelementexporttaga[#1][#2][#3]{\taggedctxcommand{settagproperty("#1","#2","#3")}} \def\dosetelementexporttagb[#1][#2][#3]{\taggedctxcommand{settagproperty("#1","export","#2")}} % todo: no need for calls when trialtypesetting \def\taggedctxcommand {\iftrialtypesetting \expandafter\gobbleoneargument \else \expandafter\ctxcommand \fi} \newcount\tagparcounter \let\dotagsetparcounter\relax \appendtoks \dotagsetparcounter \to \everypar \appendtoks \dotagsetparcounter \to \neverypar \appendtoks \dotagsetparcounter \to \everytabulatepar % tricky, maybe this should be neverypar \appendtoks \def\dotagTABLEcell {\taggedctxcommand{settagtablecell(\number\tablecellrows,\number\tablecellcolumns,\number\raggedstatus)}}% \def\dotagTABLEsignal{\char\zerocount}% brrr, we need to tag empty cells (unless we start numbering) \to \everyenableelements \appendtoks \def\dotagtabulatecell {\taggedctxcommand{settagtabulatecell(\number\tabulatealign)}}% \def\dotagtabulatesignal{\dontleavehmode\char\zerocount\ignorespaces}% \to \everyenableelements \appendtoks \def\dotagsynonym{\taggedctxcommand{settagsynonym("\currentsynonym","\currentsynonymtag")}}% \to \everyenableelements \appendtoks % frozen and assumed global per highlight class \def\dotaghighlight{\taggedctxcommand{settaghighlight("\currenthighlight","\highlightparameter\c!style",\number\attribute\colorattribute)}}% \to \everyenableelements \appendtoks % we can have differently scaled images \def\dotagfigure{\taggedctxcommand{settagfigure("\figurefileoriginal","\figurefilepage",\number\dimexpr\figurewidth,\number\dimexpr\figureheight)}}% \to \everyenableelements \appendtoks %\def\dotagcombination{\taggedctxcommand{settagcombination(\combinationparameter\c!nx,\combinationparameter\c!ny)}}% \def\dotagcombination{\taggedctxcommand{settagcombination(\number\horcombination,\number\totcombination)}}% \to \everyenableelements \appendtoks \def\dotagsorting{\taggedctxcommand{settagsorting("\currentsorting","\currentsortingtag")}}% \to \everyenableelements \appendtoks \def\dotagsetparcounter{\global\advance\tagparcounter\plusone\attribute\taggedparattribute\tagparcounter}% \to \everyenableelements \appendtoks \def\dotagsetitemgroup{\taggedctxcommand{settagitemgroup("\currentitemgroup",\ifconditional\packlistitem true\else false\fi,"\currentitemsymbol")}}% \to \everyenableelements \appendtoks \def\dotagsetdescription{\taggedctxcommand{settagdescription("\currentdescription",\currentdescriptionnumberentry)}}% \to \everyenableelements \appendtoks \def\dotagsetnotesymbol{\taggedctxcommand{settagdescriptionsymbol("\currentnote",\currentnotenumber)}}% \to \everyenableelements \appendtoks \unexpanded\def\doverbatimspace{\char32\relax}% will be done permanently \to \everyenableelements % The action: \setupbackend[export=yes] % or filename \def\c!export {export} % maybe: option={css,xhtml} \def\c!css {css} \def\c!xhtml {xhtml} \appendtoks \doifsomething{\backendparameter\c!xhtml} {\enabledirectives[backend.export.xhtml=\backendparameter\c!xhtml]}% \doifsomething{\backendparameter\c!css} {\enabledirectives[backend.export.css={\backendparameter\c!css}]}% \to \everysetupbackend \appendtoks \doifsomething{\backendparameter\c!export} {\setupstructure [\c!state=\v!start]% \enabledirectives [backend.export=\backendparameter\c!export]}% \to \everysetupbackend \protect \endinput