summaryrefslogtreecommitdiff
path: root/tex/context/base/back-exp.mkiv
blob: 131dfe295118b73d0884a693e2e2225cfc699f68 (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
%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}{}

%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]

\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\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

% The action: \setubackend[export=yes] % or filename

\def\c!export{export}

\appendtoks
    \doifsomething{\backendparameter\c!export}
      {\setupstructure[\c!state=\v!start]%
       \enabledirectives[backend.export=\backendparameter\c!export]}%
\to \everysetupbackend

\protect \endinput