preprocess-flagging.dita 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE reference PUBLIC "-//OASIS//DTD DITA Reference//EN" "reference.dtd">
  3. <!-- This file is part of the DITA Open Toolkit project. See the accompanying LICENSE file for applicable license. -->
  4. <reference id="flagging" rev="1.7" xml:lang="en-US">
  5. <title>Flagging (flag-module)</title>
  6. <shortdesc>Beginning with DITA-OT 1.7, flagging support is implemented as a common <codeph>flag-module</codeph>
  7. preprocessing step. The module evaluates the DITAVAL against all flagging attributes, and adds DITA-OT–specific
  8. hints to the topic when flags are active. Any extended transformation type may use these hints to support flagging
  9. without adding logic to interpret the DITAVAL.</shortdesc>
  10. <prolog>
  11. <metadata>
  12. <keywords>
  13. <indexterm><xmlelement>foreign</xmlelement></indexterm>
  14. <indexterm><xmlelement>ditaval-startprop</xmlelement></indexterm>
  15. <indexterm><xmlelement>prop</xmlelement></indexterm>
  16. <indexterm><xmlelement>revprop</xmlelement></indexterm>
  17. <indexterm><xmlelement>startflag</xmlelement></indexterm>
  18. <indexterm><xmlelement>endflag</xmlelement></indexterm>
  19. <indexterm><xmlelement>ditaval-endprop</xmlelement></indexterm>
  20. <indexterm><xmlelement>ditaval-prop</xmlelement></indexterm>
  21. <indexterm><xmlelement>p</xmlelement></indexterm>
  22. <indexterm><xmlelement>ol</xmlelement></indexterm>
  23. <indexterm><xmlelement>li</xmlelement></indexterm>
  24. <indexterm><xmlatt>outputclass</xmlatt></indexterm>
  25. <indexterm><xmlatt>xtrf</xmlatt></indexterm>
  26. <indexterm><xmlatt>xtrc</xmlatt></indexterm>
  27. <indexterm><xmlatt>outputclass</xmlatt></indexterm>
  28. <indexterm><xmlatt>rev</xmlatt></indexterm>
  29. <indexterm>DITAVAL<indexterm><codeph>flag-module</codeph> preprocess step</indexterm></indexterm>
  30. <indexterm>DITA<indexterm>specializations</indexterm></indexterm>
  31. <indexterm>preprocessing<indexterm><codeph>flag-module</codeph></indexterm></indexterm>
  32. <indexterm><codeph>flag-module</codeph></indexterm>
  33. <indexterm>flagging</indexterm>
  34. <indexterm>XSLT<indexterm><codeph>flag-module</codeph> preprocess step</indexterm></indexterm>
  35. <indexterm>CSS<indexterm><xmlatt>outputclass</xmlatt></indexterm></indexterm>
  36. <indexterm>images<indexterm>flagging</indexterm></indexterm>
  37. </keywords>
  38. </metadata>
  39. </prolog>
  40. <refbody>
  41. <section>
  42. <title>Evaluating the DITAVAL flags</title>
  43. <p>Flagging is implemented as a reusable module during the preprocess stage. If a DITAVAL file is not used with a
  44. build, this step is skipped with no change to the file.</p>
  45. <p>When a flag is active, relevant sections of the DITAVAL itself are copied into the topic as a sub-element of
  46. the current topic. The active flags are enclosed in a pseudo-specialization of the
  47. <xmlelement>foreign</xmlelement> element (referred to as a pseudo-specialization because it is used only under
  48. the covers, with all topic types; it is not integrated into any shipped document types).</p>
  49. <parml>
  50. <plentry>
  51. <pt><xmlelement>ditaval-startprop</xmlelement></pt>
  52. <pd>
  53. <p>When any flag is active on an element, a <xmlelement>ditaval-startprop</xmlelement> element will be
  54. created as the first child of the flagged element:</p>
  55. <codeblock outputclass="language-xml">&lt;ditaval-startprop class="+ topic/foreign ditaot-d/ditaval-startprop "></codeblock>
  56. <p>The <xmlelement>ditaval-startprop</xmlelement> element will contain the following:
  57. <ul>
  58. <li>If the active flags should create a new style, that style is included using standard CSS markup on
  59. the <xmlatt>outputclass</xmlatt> attribute. Output types that make use of CSS, such as XHTML, can use
  60. this value as-is.</li>
  61. <li>If styles conflict, and a <xmlelement>style-conflict</xmlelement> element exists in the DITAVAL, it
  62. will be copied as a child of <xmlelement>ditaval-startprop</xmlelement>.</li>
  63. <li>Any <xmlelement>prop</xmlelement> or <xmlelement>revprop</xmlelement> elements that define active
  64. flags will be copied in as children of the <xmlelement>ditaval-startprop</xmlelement> element. Any
  65. <xmlelement>startflag</xmlelement> children of the properties will be included, but
  66. <xmlelement>endflag</xmlelement> children will not.</li>
  67. </ul>
  68. </p>
  69. </pd>
  70. </plentry>
  71. <plentry>
  72. <pt><xmlelement>ditaval-endprop</xmlelement></pt>
  73. <pd>
  74. <p>When any flag is active on an element, a <xmlelement>ditaval-endprop</xmlelement> element will be created
  75. as the last child of the flagged element:</p>
  76. <codeblock outputclass="language-xml">&lt;ditaval-endprop class="+ topic/foreign ditaot-d/ditaval-endprop "></codeblock>
  77. <p>CSS values and <xmlelement>style-conflict</xmlelement> elements are not included on this element.</p>
  78. <p>Any <xmlelement>prop</xmlelement> or <xmlelement>revprop</xmlelement> elements that define active flags
  79. will be copied in as children of <xmlelement>ditaval-prop</xmlelement>. Any
  80. <xmlelement>startflag</xmlelement> children of the properties will be included, but
  81. <xmlelement>endflag</xmlelement> children will not.</p>
  82. </pd>
  83. </plentry>
  84. </parml>
  85. </section>
  86. <section>
  87. <title>Supporting flags in overrides or custom transformation types</title>
  88. <p>For most transformation types, the <xmlelement>foreign</xmlelement> element should be ignored by default,
  89. because arbitrary non-DITA content may not mix well unless coded for ahead of time. If the
  90. <xmlelement>foreign</xmlelement> element is ignored by default, or if a rule is added to specifically ignore
  91. <xmlelement>ditaval-startprop</xmlelement> and <xmlelement>ditaval-endprop</xmlelement>, then the added
  92. elements will have no impact on a transform. If desired, flagging support may be integrated at any time in the
  93. future.</p>
  94. <p>The processing described above runs as part of the common preprocess, so any transform that uses the default
  95. preprocess will get the topic updates. To support generating flags as images, XSLT based transforms can use
  96. default fallthrough processing in most cases. For example, if a paragraph is flagged, the first child of
  97. <xmlelement>p</xmlelement> will contain the start flag information; adding a rule to handle images in
  98. <xmlelement>ditaval-startprop</xmlelement> will cause the image to appear at the start of the paragraph
  99. content.</p>
  100. <p>In some cases fallthrough processing will not result in valid output; for those cases, the flags must be
  101. explicitly processed. This is done in the XHTML transform for elements like <xmlelement>ol</xmlelement>, because
  102. fallthrough processing would place images in between <xmlelement>ol</xmlelement> and
  103. <xmlelement>li</xmlelement>. To handle this, the code processes <xmlelement>ditaval-startprop</xmlelement>
  104. before starting the element, and <xmlelement>ditaval-endprop</xmlelement> at the end. Fallthrough processing is
  105. then disabled for those elements as children of <xmlelement>ol</xmlelement>.</p></section>
  106. <example>
  107. <title>Example DITAVAL</title>
  108. <p>Assume the following DITAVAL file is in use during a build. This DITAVAL will be used for each of the following
  109. content examples.</p>
  110. <codeblock outputclass="language-xml normalize-space show-line-numbers show-whitespace">&lt;?xml version="1.0" encoding="UTF-8"?>
  111. &lt;val>
  112. <i>&lt;!-- Define what happens in the case of conflicting styles --></i>
  113. &lt;style-conflict background-conflict-color="red"/>
  114. <i>&lt;!-- Define two flagging properties that give styles (no image) --></i>
  115. &lt;prop action="flag" att="audience" style="underline" val="user"
  116. backcolor="green"/>
  117. &lt;prop action="flag" att="platform" style="overline" val="win"
  118. backcolor="blue"/>
  119. <i>&lt;!-- Define a property that includes start and end image flags --></i>
  120. &lt;prop action="flag" att="platform" val="linux" style="overline"
  121. backcolor="blue">
  122. &lt;startflag imageref="startlin.png">
  123. &lt;alt-text>Start linux&lt;/alt-text>&lt;/startflag>
  124. &lt;endflag imageref="endlin.png">
  125. &lt;alt-text>End linux&lt;/alt-text>&lt;/endflag>
  126. &lt;/prop>
  127. <i>&lt;!-- Define a revision that includes start and end image flags --></i>
  128. &lt;revprop action="flag" style="double-underline" val="rev2">
  129. &lt;startflag imageref="start_rev.gif">
  130. &lt;alt-text>START&lt;/alt-text>&lt;/startflag>
  131. &lt;endflag imageref="end_rev.gif">&lt;alt-text>END&lt;/alt-text>&lt;/endflag>
  132. &lt;/revprop>
  133. &lt;/val></codeblock>
  134. </example>
  135. <example>
  136. <title>Content example 1: Adding style</title>
  137. <p>Now assume the following paragraph exists in a topic. Class attributes are included, as they would normally be
  138. in the middle of the preprocess routine; <xmlatt>xtrf</xmlatt> and <xmlatt>xtrc</xmlatt> are left off for
  139. clarity.</p>
  140. <codeblock outputclass="language-xml">&lt;p audience="user">Simple user; includes style but no images&lt;/p></codeblock>
  141. <p>Based on the DITAVAL above, audience="user" results in a style with underlining and with a green background.
  142. The interpreted CSS value is added to <xmlatt>outputclass</xmlatt> on
  143. <xmlelement>ditaval-startprop</xmlelement>, and the actual property definition is included at the start and end
  144. of the element. The output from the flagging step looks like this (with newlines added for clarity, and class
  145. attributes added as they would appear in the temporary file):</p>
  146. <p>The resulting file after the flagging step looks like this; for clarity, newlines are added, while
  147. <xmlatt>xtrf</xmlatt> and <xmlatt>xtrc</xmlatt> are removed:</p>
  148. <codeblock outputclass="language-xml normalize-space show-line-numbers show-whitespace">&lt;p audience="user" class="- topic/p ">
  149. <b>&lt;ditaval-startprop</b>
  150. <b>class="+ topic/foreign ditaot-d/ditaval-startprop "</b>
  151. <b>outputclass="background-color:green;text-decoration:underline;"></b>
  152. <b>&lt;prop action="flag" att="audience" style="underline" val="user"
  153. backcolor="green"/></b>
  154. <b>&lt;/ditaval-startprop></b>
  155. Simple user; includes style but no images
  156. <b>&lt;ditaval-endprop</b>
  157. <b>class="+ topic/foreign ditaot-d/ditaval-endprop "></b>
  158. <b>&lt;prop action="flag" att="audience" style="underline" val="user"
  159. backcolor="green"/></b>
  160. <b>&lt;/ditaval-endprop></b>
  161. &lt;/p></codeblock>
  162. </example>
  163. <example>
  164. <title>Content example 2: Conflicting styles</title>
  165. <p>This example includes a paragraph with conflicting styles. When the audience and platform attributes are both
  166. evaluated, the DITAVAL indicates that the background color is both green and blue. In this situation, the
  167. <xmlelement>style-conflict</xmlelement> element is evaluated to determine how to style the content.</p>
  168. <codeblock outputclass="language-xml">&lt;p audience="user" platform="win">Conflicting styles (still no images)&lt;/p></codeblock>
  169. <p>The <xmlelement>style-conflict</xmlelement> element results in a background color of red, so this value is
  170. added to <xmlatt>outputclass</xmlatt> on <xmlelement>ditaval-startprop</xmlelement>. As above, active properties
  171. are copied into the generated elements; the <xmlelement>style-conflict</xmlelement> element itself is also
  172. copied into the generated <xmlelement>ditaval-startprop</xmlelement> element.</p>
  173. <p>The resulting file after the flagging step looks like this; for clarity, newlines are added, while
  174. <xmlatt>xtrf</xmlatt> and <xmlatt>xtrc</xmlatt> are removed:</p>
  175. <codeblock outputclass="language-xml normalize-space show-line-numbers show-whitespace">&lt;p audience="user" platform="win" class="- topic/p ">
  176. <b>&lt;ditaval-startprop</b>
  177. <b>class="+ topic/foreign ditaot-d/ditaval-startprop "</b>
  178. <b>outputclass="background-color:red;"></b>
  179. <b>&lt;style-conflict background-conflict-color="red"/></b>
  180. <b>&lt;prop action="flag" att="audience" style="underline" val="user"
  181. backcolor="green"/></b>
  182. <b>&lt;prop action="flag" att="platform" style="overline" val="win"
  183. backcolor="blue"/></b>
  184. <b>&lt;/ditaval-startprop></b>
  185. Conflicting styles (still no images)
  186. <b>&lt;ditaval-endprop</b>
  187. <b>class="+ topic/foreign ditaot-d/ditaval-endprop "></b>
  188. <b>&lt;prop action="flag" att="platform" style="overline" val="win"
  189. backcolor="blue"/></b>
  190. <b>&lt;prop action="flag" att="audience" style="underline" val="user"
  191. backcolor="green"/></b><b>
  192. &lt;/ditaval-endprop></b>
  193. &lt;/p></codeblock>
  194. </example>
  195. <example>
  196. <title>Content example 3: Adding image flags</title>
  197. <p>This example includes image flags for both <xmlatt>platform</xmlatt> and <xmlatt>rev</xmlatt>, which are
  198. defined in DITAVAL <xmlelement>prop</xmlelement> and <xmlelement>revprop</xmlelement> elements.</p>
  199. <codeblock outputclass="language-xml normalize-space show-line-numbers show-whitespace">&lt;ol platform="linux" rev="rev2">
  200. &lt;li>Generate images for platform="linux" and rev="2"&lt;/li>
  201. &lt;/ol></codeblock>
  202. <p>As above, the <xmlelement>ditaval-startprop</xmlelement> and <xmlelement>ditaval-endprop</xmlelement> nest the
  203. active property definitions, with the calculated CSS value on <xmlatt>outputclass</xmlatt>. The
  204. <xmlelement>ditaval-startprop</xmlelement> drops the ending image, and
  205. <xmlelement>ditaval-endprop</xmlelement> drops the starting image. To make document-order processing more
  206. consistent, property flags are always included before revisions in <xmlelement>ditaval-startprop</xmlelement>,
  207. and the order is reversed for <xmlelement>ditaval-endprop</xmlelement>.</p>
  208. <p>The resulting file after the flagging step looks like this; for clarity, newlines are added, while
  209. <xmlatt>xtrf</xmlatt> and <xmlatt>xtrc</xmlatt> are removed:</p>
  210. <codeblock outputclass="language-xml normalize-space show-line-numbers show-whitespace">&lt;ol platform="linux" rev="rev2" class="- topic/ol ">
  211. <b>&lt;ditaval-startprop</b>
  212. <b>class="+ topic/foreign ditaot-d/ditaval-startprop "</b>
  213. <b>outputclass="background-color:blue;</b>
  214. <b>text-decoration:underline;</b>
  215. <b>text-decoration:overline;"></b>
  216. <b>&lt;prop action="flag" att="platform" val="linux" style="overline"
  217. backcolor="blue"></b>
  218. <b>&lt;startflag imageref="startlin.png"></b>
  219. <b>&lt;alt-text>Start linux&lt;/alt-text>&lt;/startflag>&lt;/prop></b>
  220. <b>&lt;revprop action="flag" style="double-underline" val="rev2"></b>
  221. <b>&lt;startflag imageref="start_rev.gif"></b>
  222. <b>&lt;alt-text> &lt;/alt-text>&lt;/startflag>&lt;/revprop></b>
  223. <b>&lt;/ditaval-startprop></b>
  224. &lt;li class="- topic/li ">
  225. Generate images for platform="linux" and rev="2"
  226. &lt;/li>
  227. <b>&lt;ditaval-endprop</b>
  228. <b>class="+ topic/foreign ditaot-d/ditaval-endprop "></b>
  229. <b>&lt;revprop action="flag" style="double-underline" val="rev2"></b>
  230. <b>&lt;endflag imageref="end_rev.gif"></b>
  231. <b>&lt;alt-text>END&lt;/alt-text>&lt;/endflag>&lt;/revprop></b>
  232. <b>&lt;prop action="flag" att="platform" val="linux" style="overline"</b>
  233. <b>backcolor="blue"></b>
  234. <b>&lt;endflag imageref="endlin.png"></b>
  235. <b>&lt;alt-text>End linux&lt;/alt-text>&lt;/endflag>&lt;/prop></b>
  236. <b>&lt;/ditaval-endprop></b>
  237. &lt;/ol></codeblock>
  238. </example>
  239. </refbody>
  240. </reference>