summaryrefslogtreecommitdiff
path: root/tex/context/base/back-exp.mkiv
blob: d6fb74a97f656832108edd02ac00c89b06392397 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
%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[taggedrows]   [public]
\definesystemattribute[taggedcolumns][public]
\definesystemattribute[taggedalign]  [public]
\definesystemattribute[taggedpar]    [public]
\definesystemattribute[taggedpacked] [public]
\definesystemattribute[taggedsymbol] [public]
\definesystemattribute[taggedinsert] [public]
\definesystemattribute[taggedtag]    [public]

\def\setelementexporttag
  {\dotripleargument\dosetelementexporttag}

\def\dosetelementexporttag
  {\ifthirdargument
     \expandafter\dosetelementexporttaga
   \else\ifsecondargument
     \expandafter\expandafter\expandafter\dosetelementexporttagb
   \fi\fi}

\def\dosetelementexporttaga[#1][#2][#3]{\ctxcommand{settagproperty("#1","#2","#3")}}
\def\dosetelementexporttagb[#1][#2][#3]{\ctxcommand{settagproperty("#1","export","#2")}}

\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\dotagnofTABLEcolumns{\attribute\taggedcolumnsattribute\!!counta}%
    \def\dotagnofTABLErows   {\attribute\taggedrowsattribute   \!!countb}%
\to \everyenableelements

\appendtoks
    \def\dotagTABLEalign{\attribute\taggedalignattribute\raggedstatus}%
    \def\dotagTABLEcell {\char\zerocount}% brrr, we need to tag empty cells (unless we start numbering)
\to \everyenableelements

\appendtoks
    \def\dotagtabulatesignal{\dontleavehmode\char\zerocount\ignorespaces}%
\to \everyenableelements

\appendtoks
    \def\dotagtabulatealign{\attribute\taggedalignattribute\ifcase\tabulatealign\attributeunsetvalue\or\plusthree\or\plusone\or\plustwo\or\attributeunsetvalue\fi}%
\to \everyenableelements

\appendtoks
    \def\dotagsynonym{\ctxcommand{settagsynonym("\currentsynonym","\currentsynonymtag")}}%
\to \everyenableelements

\appendtoks
    \def\dotagsorting{\ctxcommand{settagsorting("\currentsorting","\currentsortingtag")}}%
\to \everyenableelements

\appendtoks
    \def\dotagsetparcounter{\global\advance\tagparcounter\plusone\attribute\taggedparattribute\tagparcounter}%
\to \everyenableelements

\appendtoks
    \def\dotagsetitemize{\ctxcommand{settagitemgroup(\ifconditional\packlistitem true\else false\fi,"\currentitemsymbol")}}%
\to \everyenableelements

\appendtoks
    \def\dotagsetdescriptiontag{\ctxcommand{settagdescriptionid("\currentdescription",\currentdescriptionnumberentry)}}%
\to \everyenableelements

\appendtoks
    \def\dotagsetnotesymbol{\ctxcommand{settagdescriptionid("\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