/
preprocess-flagging.dita
269 lines (264 loc) · 16 KB
/
preprocess-flagging.dita
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE reference PUBLIC "-//OASIS//DTD DITA Reference//EN" "reference.dtd">
<!-- This file is part of the DITA Open Toolkit project. See the accompanying LICENSE file for applicable license. -->
<reference id="flagging" rev="1.7">
<title>Flagging (<codeph>flag-module</codeph>)</title>
<shortdesc>Beginning with DITA-OT 1.7, flagging support is implemented as a common <codeph>flag-module</codeph>
pre-processing step. The module evaluates the DITAVAL against all flagging attributes, and adds DITA-OT–specific
hints to the topic when flags are active. Any extended transformation type may use these hints to support flagging
without adding logic to interpret the DITAVAL.</shortdesc>
<prolog>
<metadata>
<keywords>
<indexterm><xmlelement>foreign</xmlelement></indexterm>
<indexterm><xmlelement>ditaval-startprop</xmlelement></indexterm>
<indexterm><xmlelement>prop</xmlelement></indexterm>
<indexterm><xmlelement>revprop</xmlelement></indexterm>
<indexterm><xmlelement>startflag</xmlelement></indexterm>
<indexterm><xmlelement>endflag</xmlelement></indexterm>
<indexterm><xmlelement>ditaval-endprop</xmlelement></indexterm>
<indexterm><xmlelement>ditaval-prop</xmlelement></indexterm>
<indexterm><xmlelement>p</xmlelement></indexterm>
<indexterm><xmlelement>ol</xmlelement></indexterm>
<indexterm><xmlelement>li</xmlelement></indexterm>
<indexterm><xmlatt>outputclass</xmlatt></indexterm>
<indexterm><xmlatt>xtrf</xmlatt></indexterm>
<indexterm><xmlatt>xtrc</xmlatt></indexterm>
<indexterm><xmlatt>outputclass</xmlatt></indexterm>
<indexterm><xmlatt>rev</xmlatt></indexterm>
<indexterm>DITAVAL
<indexterm><codeph>flag-module</codeph> preprocess step</indexterm></indexterm>
<indexterm>DITA
<indexterm>specializations</indexterm></indexterm>
<indexterm>pre-processing
<indexterm><codeph>flag-module</codeph></indexterm></indexterm>
<indexterm><codeph>flag-module</codeph></indexterm>
<indexterm>flagging</indexterm>
<indexterm>XSLT
<indexterm><codeph>flag-module</codeph> preprocess step</indexterm></indexterm>
<indexterm>CSS
<indexterm><xmlatt>outputclass</xmlatt></indexterm></indexterm>
<indexterm>images
<indexterm>flagging</indexterm></indexterm>
</keywords>
</metadata>
</prolog>
<refbody>
<section>
<title>Evaluating the DITAVAL flags</title>
<p>Flagging is implemented as a reusable module during the preprocess stage. If a DITAVAL file is not used with a
build, this step is skipped with no change to the file.</p>
<p>When a flag is active, relevant sections of the DITAVAL itself are copied into the topic as a sub-element of
the current topic. The active flags are enclosed in a pseudo-specialization of the
<xmlelement>foreign</xmlelement> element (referred to as a pseudo-specialization because it is used only under
the covers, with all topic types; it is not integrated into any shipped document types).</p>
<parml>
<plentry>
<pt><xmlelement>ditaval-startprop</xmlelement></pt>
<pd>
<p>When any flag is active on an element, a <xmlelement>ditaval-startprop</xmlelement> element will be
created as the first child of the flagged element:</p>
<codeblock
outputclass="language-xml"
><ditaval-startprop class="+ topic/foreign ditaot-d/ditaval-startprop "></codeblock>
<p>The <xmlelement>ditaval-startprop</xmlelement> element will contain the following:
<ul>
<li>If the active flags should create a new style, that style is included using standard CSS markup on
the <xmlatt>outputclass</xmlatt> attribute. Output types that make use of CSS, such as XHTML, can use
this value as-is.</li>
<li>If styles conflict, and a <xmlelement>style-conflict</xmlelement> element exists in the DITAVAL, it
will be copied as a child of <xmlelement>ditaval-startprop</xmlelement>.</li>
<li>Any <xmlelement>prop</xmlelement> or <xmlelement>revprop</xmlelement> elements that define active
flags will be copied in as children of the <xmlelement>ditaval-startprop</xmlelement> element. Any
<xmlelement>startflag</xmlelement> children of the properties will be included, but
<xmlelement>endflag</xmlelement> children will not.</li>
</ul>
</p>
</pd>
</plentry>
<plentry>
<pt><xmlelement>ditaval-endprop</xmlelement></pt>
<pd>
<p>When any flag is active on an element, a <xmlelement>ditaval-endprop</xmlelement> element will be created
as the last child of the flagged element:</p>
<codeblock
outputclass="language-xml"
><ditaval-endprop class="+ topic/foreign ditaot-d/ditaval-endprop "></codeblock>
<p>CSS values and <xmlelement>style-conflict</xmlelement> elements are not included on this element.</p>
<p>Any <xmlelement>prop</xmlelement> or <xmlelement>revprop</xmlelement> elements that define active flags
will be copied in as children of <xmlelement>ditaval-prop</xmlelement>. Any
<xmlelement>startflag</xmlelement> children of the properties will be included, but
<xmlelement>endflag</xmlelement> children will not.</p>
</pd>
</plentry>
</parml>
</section>
<section>
<title>Supporting flags in overrides or custom transformation types</title>
<p>For most transformation types, the <xmlelement>foreign</xmlelement> element should be ignored by default,
because arbitrary non-DITA content may not mix well unless coded for ahead of time. If the
<xmlelement>foreign</xmlelement> element is ignored by default, or if a rule is added to specifically ignore
<xmlelement>ditaval-startprop</xmlelement> and <xmlelement>ditaval-endprop</xmlelement>, then the added
elements will have no impact on a transform. If desired, flagging support may be integrated at any time in the
future.</p>
<p>The processing described above runs as part of the common preprocess, so any transform that uses the default
preprocess will get the topic updates. To support generating flags as images, XSLT-based transforms can use
default fallthrough processing in most cases. For example, if a paragraph is flagged, the first child of
<xmlelement>p</xmlelement> will contain the start flag information; adding a rule to handle images in
<xmlelement>ditaval-startprop</xmlelement> will cause the image to appear at the start of the paragraph
content.</p>
<p>In some cases fallthrough processing will not result in valid output; for those cases, the flags must be
explicitly processed. This is done in the XHTML transform for elements like <xmlelement>ol</xmlelement>, because
fallthrough processing would place images in between <xmlelement>ol</xmlelement> and
<xmlelement>li</xmlelement>. To handle this, the code processes <xmlelement>ditaval-startprop</xmlelement>
before starting the element, and <xmlelement>ditaval-endprop</xmlelement> at the end. Fallthrough processing is
then disabled for those elements as children of <xmlelement>ol</xmlelement>.</p></section>
<example>
<title>Example DITAVAL</title>
<p>Assume the following DITAVAL file is in use during a build. This DITAVAL will be used for each of the following
content examples.</p>
<codeblock
outputclass="language-xml normalize-space show-line-numbers show-whitespace"
><?xml version="1.0" encoding="UTF-8"?>
<val>
<i><!-- Define what happens in the case of conflicting styles --></i>
<style-conflict background-conflict-color="red"/>
<i><!-- Define two flagging properties that give styles (no image) --></i>
<prop action="flag" att="audience" style="underline" val="user"
backcolor="green"/>
<prop action="flag" att="platform" style="overline" val="win"
backcolor="blue"/>
<i><!-- Define a property that includes start and end image flags --></i>
<prop action="flag" att="platform" val="linux" style="overline"
backcolor="blue">
<startflag imageref="startlin.png">
<alt-text>Start linux</alt-text></startflag>
<endflag imageref="endlin.png">
<alt-text>End linux</alt-text></endflag>
</prop>
<i><!-- Define a revision that includes start and end image flags --></i>
<revprop action="flag" style="double-underline" val="rev2">
<startflag imageref="start_rev.gif">
<alt-text>START</alt-text></startflag>
<endflag imageref="end_rev.gif"><alt-text>END</alt-text></endflag>
</revprop>
</val></codeblock>
</example>
<example>
<title>Content example 1: Adding style</title>
<p>Now assume the following paragraph exists in a topic. Class attributes are included, as they would normally be
in the middle of the preprocess routine; <xmlatt>xtrf</xmlatt> and <xmlatt>xtrc</xmlatt> are left off for
clarity.</p>
<codeblock
outputclass="language-xml"
><p audience="user">Simple user; includes style but no images</p></codeblock>
<p>Based on the DITAVAL above, audience="user" results in a style with underlining and with a green background.
The interpreted CSS value is added to <xmlatt>outputclass</xmlatt> on
<xmlelement>ditaval-startprop</xmlelement>, and the actual property definition is included at the start and end
of the element. The output from the flagging step looks like this (with newlines added for clarity, and class
attributes added as they would appear in the temporary file):</p>
<p>The resulting file after the flagging step looks like this; for clarity, newlines are added, while
<xmlatt>xtrf</xmlatt> and <xmlatt>xtrc</xmlatt> are removed:</p>
<codeblock
outputclass="language-xml normalize-space show-line-numbers show-whitespace"
><p audience="user" class="- topic/p ">
<b><ditaval-startprop</b>
<b>class="+ topic/foreign ditaot-d/ditaval-startprop "</b>
<b>outputclass="background-color:green;text-decoration:underline;"></b>
<b><prop action="flag" att="audience" style="underline" val="user"
backcolor="green"/></b>
<b></ditaval-startprop></b>
Simple user; includes style but no images
<b><ditaval-endprop</b>
<b>class="+ topic/foreign ditaot-d/ditaval-endprop "></b>
<b><prop action="flag" att="audience" style="underline" val="user"
backcolor="green"/></b>
<b></ditaval-endprop></b>
</p></codeblock>
</example>
<example>
<title>Content example 2: Conflicting styles</title>
<p>This example includes a paragraph with conflicting styles. When the audience and platform attributes are both
evaluated, the DITAVAL indicates that the background color is both green and blue. In this situation, the
<xmlelement>style-conflict</xmlelement> element is evaluated to determine how to style the content.</p>
<codeblock
outputclass="language-xml"
><p audience="user" platform="win">Conflicting styles (still no images)</p></codeblock>
<p>The <xmlelement>style-conflict</xmlelement> element results in a background color of red, so this value is
added to <xmlatt>outputclass</xmlatt> on <xmlelement>ditaval-startprop</xmlelement>. As above, active properties
are copied into the generated elements; the <xmlelement>style-conflict</xmlelement> element itself is also
copied into the generated <xmlelement>ditaval-startprop</xmlelement> element.</p>
<p>The resulting file after the flagging step looks like this; for clarity, newlines are added, while
<xmlatt>xtrf</xmlatt> and <xmlatt>xtrc</xmlatt> are removed:</p>
<codeblock
outputclass="language-xml normalize-space show-line-numbers show-whitespace"
><p audience="user" platform="win" class="- topic/p ">
<b><ditaval-startprop</b>
<b>class="+ topic/foreign ditaot-d/ditaval-startprop "</b>
<b>outputclass="background-color:red;"></b>
<b><style-conflict background-conflict-color="red"/></b>
<b><prop action="flag" att="audience" style="underline" val="user"
backcolor="green"/></b>
<b><prop action="flag" att="platform" style="overline" val="win"
backcolor="blue"/></b>
<b></ditaval-startprop></b>
Conflicting styles (still no images)
<b><ditaval-endprop</b>
<b>class="+ topic/foreign ditaot-d/ditaval-endprop "></b>
<b><prop action="flag" att="platform" style="overline" val="win"
backcolor="blue"/></b>
<b><prop action="flag" att="audience" style="underline" val="user"
backcolor="green"/></b><b>
</ditaval-endprop></b>
</p></codeblock>
</example>
<example>
<title>Content example 3: Adding image flags</title>
<p>This example includes image flags for both <xmlatt>platform</xmlatt> and <xmlatt>rev</xmlatt>, which are
defined in DITAVAL <xmlelement>prop</xmlelement> and <xmlelement>revprop</xmlelement> elements.</p>
<codeblock
outputclass="language-xml normalize-space show-line-numbers show-whitespace"
><ol platform="linux" rev="rev2">
<li>Generate images for platform="linux" and rev="2"</li>
</ol></codeblock>
<p>As above, the <xmlelement>ditaval-startprop</xmlelement> and <xmlelement>ditaval-endprop</xmlelement> nest the
active property definitions, with the calculated CSS value on <xmlatt>outputclass</xmlatt>. The
<xmlelement>ditaval-startprop</xmlelement> drops the ending image, and
<xmlelement>ditaval-endprop</xmlelement> drops the starting image. To make document-order processing more
consistent, property flags are always included before revisions in <xmlelement>ditaval-startprop</xmlelement>,
and the order is reversed for <xmlelement>ditaval-endprop</xmlelement>.</p>
<p>The resulting file after the flagging step looks like this; for clarity, newlines are added, while
<xmlatt>xtrf</xmlatt> and <xmlatt>xtrc</xmlatt> are removed:</p>
<codeblock
outputclass="language-xml normalize-space show-line-numbers show-whitespace"
><ol platform="linux" rev="rev2" class="- topic/ol ">
<b><ditaval-startprop</b>
<b>class="+ topic/foreign ditaot-d/ditaval-startprop "</b>
<b>outputclass="background-color:blue;</b>
<b>text-decoration:underline;</b>
<b>text-decoration:overline;"></b>
<b><prop action="flag" att="platform" val="linux" style="overline"
backcolor="blue"></b>
<b><startflag imageref="startlin.png"></b>
<b><alt-text>Start linux</alt-text></startflag></prop></b>
<b><revprop action="flag" style="double-underline" val="rev2"></b>
<b><startflag imageref="start_rev.gif"></b>
<b><alt-text> </alt-text></startflag></revprop></b>
<b></ditaval-startprop></b>
<li class="- topic/li ">
Generate images for platform="linux" and rev="2"
</li>
<b><ditaval-endprop</b>
<b>class="+ topic/foreign ditaot-d/ditaval-endprop "></b>
<b><revprop action="flag" style="double-underline" val="rev2"></b>
<b><endflag imageref="end_rev.gif"></b>
<b><alt-text>END</alt-text></endflag></revprop></b>
<b><prop action="flag" att="platform" val="linux" style="overline"</b>
<b>backcolor="blue"></b>
<b><endflag imageref="endlin.png"></b>
<b><alt-text>End linux</alt-text></endflag></prop></b>
<b></ditaval-endprop></b>
</ol></codeblock>
</example>
</refbody>
</reference>