summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/back-exp.mkiv
blob: 88272fca70c8395616ffa45801a911c3c82de128 (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
%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]
%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[#1][#2][#3]%
  {\ifthirdargument
     \ctxlua{structures.tags.settagproperty("#1","#2", "#3")}%
   \else\ifsecondargument
     \ctxlua{structures.tags.settagproperty("#1","export", "#2")}%
   \fi\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\dotagnoftablecolumns{\attribute\taggedcolumnsattribute\!!counta}%
    \def\dotagnoftablerows   {\attribute\taggedrowsattribute   \!!countb}%
\to \everyenableelements

\appendtoks
    \def\dotagTABLEalign{\attribute\taggedalignattribute\raggedstatus}%
    \def\dotagTABLEcell {\char\zerocount}%
\to \everyenableelements

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

\appendtoks
    \def\dotagsynonym{\ctxlua{structures.tags.setsynonym("\currentsynonym","\currentsynonymtag")}}%
\to \everyenableelements

\appendtoks
    \def\dotagsorting{\ctxlua{structures.tags.setsorting("\currentsorting","\currentsortingtag")}}%
\to \everyenableelements

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

\appendtoks
    \def\dotagsetitemize{\ctxlua{structures.tags.setitemgroup(\ifconditional\packlistitem true\else false\fi,"\currentitemsymbol")}}%
\to \everyenableelements

\appendtoks
    \def\dotagsetdescriptiontag{\ctxlua{structures.tags.setdescriptionid("\currentdescription",\currentdescriptionnumberentry)}}%
\to \everyenableelements

\appendtoks
    \def\dotagsetnotesymbol{\ctxlua{structures.tags.setdescriptionid("\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