preprocess-flagging.html 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <!DOCTYPE html
  2. SYSTEM "about:legacy-compat">
  3. <html lang="en-us"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta charset="UTF-8"><meta name="copyright" content="(C) Copyright 2019"><meta name="DC.rights.owner" content="(C) Copyright 2019"><meta name="DC.type" content="reference"><meta name="description" content="Beginning with DITA-OT 1.7, flagging support is implemented as a common flag-module preprocessing 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."><meta name="DC.subject" content=", foreign, ditaval-startprop, prop, revprop, startflag, endflag, ditaval-endprop, ditaval-prop, p, ol, li, outputclass, xtrf, xtrc, rev, DITAVAL, preprocess step, flag-module, DITA, specializations, preprocessing, flagging, XSLT, CSS, images"><meta name="keywords" content=", foreign, ditaval-startprop, prop, revprop, startflag, endflag, ditaval-endprop, ditaval-prop, p, ol, li, outputclass, xtrf, xtrc, rev, DITAVAL, preprocess step, flag-module, DITA, specializations, preprocessing, flagging, XSLT, CSS, images"><meta name="DC.relation" scheme="URI" content="../reference/preprocessing.html"><meta name="DC.relation" scheme="URI" content="../reference/preprocess-topicpull.html"><meta name="DC.relation" scheme="URI" content="../reference/preprocess-clean-map.html"><meta name="DC.format" content="HTML5"><meta name="DC.identifier" content="flagging"><meta name="DC.language" content="en-US"><link rel="stylesheet" type="text/css" href="../css/commonltr.css"><link rel="stylesheet" type="text/css" href="../css/dita-ot-doc.css"><title>Flagging (flag-module)</title></head><body id="flagging"><header role="banner"><div class="header">
  4. <p>DITA Open Toolkit</p>
  5. <hr>
  6. </div></header><nav role="toc"><ul><li><a href="../index.html">DITA Open Toolkit 3.3</a></li><li><a href="../release-notes/index.html">Release Notes</a></li><li><a href="../topics/installing-client.html">Installing DITA-OT</a></li><li><a href="../topics/alternative-input-formats.html">Authoring formats</a></li><li><a href="../topics/building-output.html">Building output</a></li><li><a href="../parameters/index.html">Setting parameters</a></li><li><a href="../topics/customizing.html">Customizing DITA-OT</a></li><li><a href="../topics/troubleshooting-overview.html">Troubleshooting</a></li><li><a href="../reference/index.html">Reference</a><ul><li><a href="../reference/architecture.html">DITA-OT architecture</a><ul><li><a href="../reference/processing-structure.html">Processing structure</a></li><li><a href="../reference/map-first-preprocessing.html">Map-first preprocessing</a></li><li><a href="../reference/processing-pipeline-modules.html">Processing modules</a></li><li><a href="../reference/processing-order.html">Processing order</a></li><li><a href="../reference/preprocessing.html">Pre-processing modules</a><ul><li><a href="../reference/preprocess-genlist.html">Generate lists (gen-list)</a></li><li><a href="../reference/preprocess-debugfilter.html">Debug and filter (debug-filter)</a></li><li><a href="../reference/preprocess-mapref.html">Resolve map references (mapref)</a></li><li><a href="../reference/preprocess-branch-filter.html">Branch filtering (branch-filter)</a></li><li><a href="../reference/preprocess-keyref.html">Resolve key references (keyref)</a></li><li><a href="../reference/preprocess-copy-to.html">Copy topics (copy-to)</a></li><li><a href="../reference/preprocess-conrefpush.html">Conref push (conrefpush)</a></li><li><a href="../reference/preprocess-conref.html">Resolve content references (conref)</a></li><li><a href="../reference/preprocess-profile.html">Filter conditional content (profile)</a></li><li><a href="../reference/preprocess-topic-fragment.html">Resolve topic fragments and code references (topic-fragment)</a></li><li><a href="../reference/preprocess-chunk.html">Chunk topics (chunk)</a></li><li><a href="../reference/preprocess-metadata.html">Move metadata (move-meta-entries) and pull content into maps (mappull) </a></li><li><a href="../reference/preprocess-maplink.html">Map based linking (maplink)</a></li><li><a href="../reference/preprocess-topicpull.html">Pull content into topics (topicpull)</a></li><li class="active"><a href="../reference/preprocess-flagging.html">Flagging (flag-module)</a></li><li><a href="../reference/preprocess-clean-map.html">Map cleanup (clean-map)</a></li><li><a href="../reference/preprocess-copyfiles.html">Copy related files (copy-files)</a></li></ul></li><li><a href="../reference/XhtmlWithNavigation.html">HTML-based processing modules</a></li><li><a href="../reference/pdf-transform.html">PDF processing modules</a></li></ul></li><li><a href="../reference/DITA_spec-support.html">DITA specification support</a></li><li><a href="../reference/license.html">License</a></li></ul></li><li><a href="../topics/dita-and-dita-ot-resources.html">Resources</a></li></ul></nav><main role="main"><article role="article" aria-labelledby="ariaid-title1">
  7. <h1 class="title topictitle1" id="ariaid-title1">Flagging (flag-module)</h1>
  8. <div class="body refbody"><p class="shortdesc">Beginning with DITA-OT 1.7, flagging support is implemented as a common <code class="ph codeph">flag-module</code>
  9. preprocessing step. The module evaluates the DITAVAL against all flagging attributes, and adds DITA-OT–specific
  10. hints to the topic when flags are active. Any extended transformation type may use these hints to support flagging
  11. without adding logic to interpret the DITAVAL.</p>
  12. <section class="section"><h2 class="title sectiontitle">Evaluating the DITAVAL flags</h2>
  13. <p class="p">Flagging is implemented as a reusable module during the preprocess stage. If a DITAVAL file is not used with a
  14. build, this step is skipped with no change to the file.</p>
  15. <p class="p">When a flag is active, relevant sections of the DITAVAL itself are copied into the topic as a sub-element of
  16. the current topic. The active flags are enclosed in a pseudo-specialization of the
  17. <code class="keyword markupname xmlelement">&lt;foreign&gt;</code> element (referred to as a pseudo-specialization because it is used only under
  18. the covers, with all topic types; it is not integrated into any shipped document types).</p>
  19. <dl class="dl parml">
  20. <dt class="dt pt dlterm"><code class="keyword markupname xmlelement">&lt;ditaval-startprop&gt;</code></dt>
  21. <dd class="dd pd">
  22. <p class="p">When any flag is active on an element, a <code class="keyword markupname xmlelement">&lt;ditaval-startprop&gt;</code> element will be
  23. created as the first child of the flagged element:</p>
  24. <pre class="pre codeblock language-xml"><code>&lt;ditaval-startprop class="+ topic/foreign ditaot-d/ditaval-startprop "&gt;</code></pre>
  25. <div class="p">The <code class="keyword markupname xmlelement">&lt;ditaval-startprop&gt;</code> element will contain the following:
  26. <ul class="ul">
  27. <li class="li">If the active flags should create a new style, that style is included using standard CSS markup on
  28. the <code class="keyword markupname xmlatt">@outputclass</code> attribute. Output types that make use of CSS, such as XHTML, can use
  29. this value as-is.</li>
  30. <li class="li">If styles conflict, and a <code class="keyword markupname xmlelement">&lt;style-conflict&gt;</code> element exists in the DITAVAL, it
  31. will be copied as a child of <code class="keyword markupname xmlelement">&lt;ditaval-startprop&gt;</code>.</li>
  32. <li class="li">Any <code class="keyword markupname xmlelement">&lt;prop&gt;</code> or <code class="keyword markupname xmlelement">&lt;revprop&gt;</code> elements that define active
  33. flags will be copied in as children of the <code class="keyword markupname xmlelement">&lt;ditaval-startprop&gt;</code> element. Any
  34. <code class="keyword markupname xmlelement">&lt;startflag&gt;</code> children of the properties will be included, but
  35. <code class="keyword markupname xmlelement">&lt;endflag&gt;</code> children will not.</li>
  36. </ul>
  37. </div>
  38. </dd>
  39. <dt class="dt pt dlterm"><code class="keyword markupname xmlelement">&lt;ditaval-endprop&gt;</code></dt>
  40. <dd class="dd pd">
  41. <p class="p">When any flag is active on an element, a <code class="keyword markupname xmlelement">&lt;ditaval-endprop&gt;</code> element will be created
  42. as the last child of the flagged element:</p>
  43. <pre class="pre codeblock language-xml"><code>&lt;ditaval-endprop class="+ topic/foreign ditaot-d/ditaval-endprop "&gt;</code></pre>
  44. <p class="p">CSS values and <code class="keyword markupname xmlelement">&lt;style-conflict&gt;</code> elements are not included on this element.</p>
  45. <p class="p">Any <code class="keyword markupname xmlelement">&lt;prop&gt;</code> or <code class="keyword markupname xmlelement">&lt;revprop&gt;</code> elements that define active flags
  46. will be copied in as children of <code class="keyword markupname xmlelement">&lt;ditaval-prop&gt;</code>. Any
  47. <code class="keyword markupname xmlelement">&lt;startflag&gt;</code> children of the properties will be included, but
  48. <code class="keyword markupname xmlelement">&lt;endflag&gt;</code> children will not.</p>
  49. </dd>
  50. </dl>
  51. </section>
  52. <section class="section"><h2 class="title sectiontitle">Supporting flags in overrides or custom transformation types</h2>
  53. <p class="p">For most transformation types, the <code class="keyword markupname xmlelement">&lt;foreign&gt;</code> element should be ignored by default,
  54. because arbitrary non-DITA content may not mix well unless coded for ahead of time. If the
  55. <code class="keyword markupname xmlelement">&lt;foreign&gt;</code> element is ignored by default, or if a rule is added to specifically ignore
  56. <code class="keyword markupname xmlelement">&lt;ditaval-startprop&gt;</code> and <code class="keyword markupname xmlelement">&lt;ditaval-endprop&gt;</code>, then the added
  57. elements will have no impact on a transform. If desired, flagging support may be integrated at any time in the
  58. future.</p>
  59. <p class="p">The processing described above runs as part of the common preprocess, so any transform that uses the default
  60. preprocess will get the topic updates. To support generating flags as images, XSLT based transforms can use
  61. default fallthrough processing in most cases. For example, if a paragraph is flagged, the first child of
  62. <code class="keyword markupname xmlelement">&lt;p&gt;</code> will contain the start flag information; adding a rule to handle images in
  63. <code class="keyword markupname xmlelement">&lt;ditaval-startprop&gt;</code> will cause the image to appear at the start of the paragraph
  64. content.</p>
  65. <p class="p">In some cases fallthrough processing will not result in valid output; for those cases, the flags must be
  66. explicitly processed. This is done in the XHTML transform for elements like <code class="keyword markupname xmlelement">&lt;ol&gt;</code>, because
  67. fallthrough processing would place images in between <code class="keyword markupname xmlelement">&lt;ol&gt;</code> and
  68. <code class="keyword markupname xmlelement">&lt;li&gt;</code>. To handle this, the code processes <code class="keyword markupname xmlelement">&lt;ditaval-startprop&gt;</code>
  69. before starting the element, and <code class="keyword markupname xmlelement">&lt;ditaval-endprop&gt;</code> at the end. Fallthrough processing is
  70. then disabled for those elements as children of <code class="keyword markupname xmlelement">&lt;ol&gt;</code>.</p></section>
  71. <div class="example"><h2 class="title sectiontitle">Example DITAVAL</h2>
  72. <p class="p">Assume the following DITAVAL file is in use during a build. This DITAVAL will be used for each of the following
  73. content examples.</p>
  74. <pre class="pre codeblock language-xml normalize-space show-line-numbers show-whitespace"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  75. &lt;val&gt;
  76. <em class="ph i">&lt;!-- Define what happens in the case of conflicting styles --&gt;</em>
  77. &lt;style-conflict background-conflict-color="red"/&gt;
  78. <em class="ph i">&lt;!-- Define two flagging properties that give styles (no image) --&gt;</em>
  79. &lt;prop action="flag" att="audience" style="underline" val="user"
  80. backcolor="green"/&gt;
  81. &lt;prop action="flag" att="platform" style="overline" val="win"
  82. backcolor="blue"/&gt;
  83. <em class="ph i">&lt;!-- Define a property that includes start and end image flags --&gt;</em>
  84. &lt;prop action="flag" att="platform" val="linux" style="overline"
  85. backcolor="blue"&gt;
  86. &lt;startflag imageref="startlin.png"&gt;
  87. &lt;alt-text&gt;Start linux&lt;/alt-text&gt;&lt;/startflag&gt;
  88. &lt;endflag imageref="endlin.png"&gt;
  89. &lt;alt-text&gt;End linux&lt;/alt-text&gt;&lt;/endflag&gt;
  90. &lt;/prop&gt;
  91. <em class="ph i">&lt;!-- Define a revision that includes start and end image flags --&gt;</em>
  92. &lt;revprop action="flag" style="double-underline" val="rev2"&gt;
  93. &lt;startflag imageref="start_rev.gif"&gt;
  94. &lt;alt-text&gt;START&lt;/alt-text&gt;&lt;/startflag&gt;
  95. &lt;endflag imageref="end_rev.gif"&gt;&lt;alt-text&gt;END&lt;/alt-text&gt;&lt;/endflag&gt;
  96. &lt;/revprop&gt;
  97. &lt;/val&gt;</code></pre>
  98. </div>
  99. <div class="example"><h2 class="title sectiontitle">Content example 1: Adding style</h2>
  100. <p class="p">Now assume the following paragraph exists in a topic. Class attributes are included, as they would normally be
  101. in the middle of the preprocess routine; <code class="keyword markupname xmlatt">@xtrf</code> and <code class="keyword markupname xmlatt">@xtrc</code> are left off for
  102. clarity.</p>
  103. <pre class="pre codeblock language-xml"><code>&lt;p audience="user"&gt;Simple user; includes style but no images&lt;/p&gt;</code></pre>
  104. <p class="p">Based on the DITAVAL above, audience="user" results in a style with underlining and with a green background.
  105. The interpreted CSS value is added to <code class="keyword markupname xmlatt">@outputclass</code> on
  106. <code class="keyword markupname xmlelement">&lt;ditaval-startprop&gt;</code>, and the actual property definition is included at the start and end
  107. of the element. The output from the flagging step looks like this (with newlines added for clarity, and class
  108. attributes added as they would appear in the temporary file):</p>
  109. <p class="p">The resulting file after the flagging step looks like this; for clarity, newlines are added, while
  110. <code class="keyword markupname xmlatt">@xtrf</code> and <code class="keyword markupname xmlatt">@xtrc</code> are removed:</p>
  111. <pre class="pre codeblock language-xml normalize-space show-line-numbers show-whitespace"><code>&lt;p audience="user" class="- topic/p "&gt;
  112. <strong class="ph b">&lt;ditaval-startprop</strong>
  113. <strong class="ph b">class="+ topic/foreign ditaot-d/ditaval-startprop "</strong>
  114. <strong class="ph b">outputclass="background-color:green;text-decoration:underline;"&gt;</strong>
  115. <strong class="ph b">&lt;prop action="flag" att="audience" style="underline" val="user"
  116. backcolor="green"/&gt;</strong>
  117. <strong class="ph b">&lt;/ditaval-startprop&gt;</strong>
  118. Simple user; includes style but no images
  119. <strong class="ph b">&lt;ditaval-endprop</strong>
  120. <strong class="ph b">class="+ topic/foreign ditaot-d/ditaval-endprop "&gt;</strong>
  121. <strong class="ph b">&lt;prop action="flag" att="audience" style="underline" val="user"
  122. backcolor="green"/&gt;</strong>
  123. <strong class="ph b">&lt;/ditaval-endprop&gt;</strong>
  124. &lt;/p&gt;</code></pre>
  125. </div>
  126. <div class="example"><h2 class="title sectiontitle">Content example 2: Conflicting styles</h2>
  127. <p class="p">This example includes a paragraph with conflicting styles. When the audience and platform attributes are both
  128. evaluated, the DITAVAL indicates that the background color is both green and blue. In this situation, the
  129. <code class="keyword markupname xmlelement">&lt;style-conflict&gt;</code> element is evaluated to determine how to style the content.</p>
  130. <pre class="pre codeblock language-xml"><code>&lt;p audience="user" platform="win"&gt;Conflicting styles (still no images)&lt;/p&gt;</code></pre>
  131. <p class="p">The <code class="keyword markupname xmlelement">&lt;style-conflict&gt;</code> element results in a background color of red, so this value is
  132. added to <code class="keyword markupname xmlatt">@outputclass</code> on <code class="keyword markupname xmlelement">&lt;ditaval-startprop&gt;</code>. As above, active properties
  133. are copied into the generated elements; the <code class="keyword markupname xmlelement">&lt;style-conflict&gt;</code> element itself is also
  134. copied into the generated <code class="keyword markupname xmlelement">&lt;ditaval-startprop&gt;</code> element.</p>
  135. <p class="p">The resulting file after the flagging step looks like this; for clarity, newlines are added, while
  136. <code class="keyword markupname xmlatt">@xtrf</code> and <code class="keyword markupname xmlatt">@xtrc</code> are removed:</p>
  137. <pre class="pre codeblock language-xml normalize-space show-line-numbers show-whitespace"><code>&lt;p audience="user" platform="win" class="- topic/p "&gt;
  138. <strong class="ph b">&lt;ditaval-startprop</strong>
  139. <strong class="ph b">class="+ topic/foreign ditaot-d/ditaval-startprop "</strong>
  140. <strong class="ph b">outputclass="background-color:red;"&gt;</strong>
  141. <strong class="ph b">&lt;style-conflict background-conflict-color="red"/&gt;</strong>
  142. <strong class="ph b">&lt;prop action="flag" att="audience" style="underline" val="user"
  143. backcolor="green"/&gt;</strong>
  144. <strong class="ph b">&lt;prop action="flag" att="platform" style="overline" val="win"
  145. backcolor="blue"/&gt;</strong>
  146. <strong class="ph b">&lt;/ditaval-startprop&gt;</strong>
  147. Conflicting styles (still no images)
  148. <strong class="ph b">&lt;ditaval-endprop</strong>
  149. <strong class="ph b">class="+ topic/foreign ditaot-d/ditaval-endprop "&gt;</strong>
  150. <strong class="ph b">&lt;prop action="flag" att="platform" style="overline" val="win"
  151. backcolor="blue"/&gt;</strong>
  152. <strong class="ph b">&lt;prop action="flag" att="audience" style="underline" val="user"
  153. backcolor="green"/&gt;</strong><strong class="ph b">
  154. &lt;/ditaval-endprop&gt;</strong>
  155. &lt;/p&gt;</code></pre>
  156. </div>
  157. <div class="example"><h2 class="title sectiontitle">Content example 3: Adding image flags</h2>
  158. <p class="p">This example includes image flags for both <code class="keyword markupname xmlatt">@platform</code> and <code class="keyword markupname xmlatt">@rev</code>, which are
  159. defined in DITAVAL <code class="keyword markupname xmlelement">&lt;prop&gt;</code> and <code class="keyword markupname xmlelement">&lt;revprop&gt;</code> elements.</p>
  160. <pre class="pre codeblock language-xml normalize-space show-line-numbers show-whitespace"><code>&lt;ol platform="linux" rev="rev2"&gt;
  161. &lt;li&gt;Generate images for platform="linux" and rev="2"&lt;/li&gt;
  162. &lt;/ol&gt;</code></pre>
  163. <p class="p">As above, the <code class="keyword markupname xmlelement">&lt;ditaval-startprop&gt;</code> and <code class="keyword markupname xmlelement">&lt;ditaval-endprop&gt;</code> nest the
  164. active property definitions, with the calculated CSS value on <code class="keyword markupname xmlatt">@outputclass</code>. The
  165. <code class="keyword markupname xmlelement">&lt;ditaval-startprop&gt;</code> drops the ending image, and
  166. <code class="keyword markupname xmlelement">&lt;ditaval-endprop&gt;</code> drops the starting image. To make document-order processing more
  167. consistent, property flags are always included before revisions in <code class="keyword markupname xmlelement">&lt;ditaval-startprop&gt;</code>,
  168. and the order is reversed for <code class="keyword markupname xmlelement">&lt;ditaval-endprop&gt;</code>.</p>
  169. <p class="p">The resulting file after the flagging step looks like this; for clarity, newlines are added, while
  170. <code class="keyword markupname xmlatt">@xtrf</code> and <code class="keyword markupname xmlatt">@xtrc</code> are removed:</p>
  171. <pre class="pre codeblock language-xml normalize-space show-line-numbers show-whitespace"><code>&lt;ol platform="linux" rev="rev2" class="- topic/ol "&gt;
  172. <strong class="ph b">&lt;ditaval-startprop</strong>
  173. <strong class="ph b">class="+ topic/foreign ditaot-d/ditaval-startprop "</strong>
  174. <strong class="ph b">outputclass="background-color:blue;</strong>
  175. <strong class="ph b">text-decoration:underline;</strong>
  176. <strong class="ph b">text-decoration:overline;"&gt;</strong>
  177. <strong class="ph b">&lt;prop action="flag" att="platform" val="linux" style="overline"
  178. backcolor="blue"&gt;</strong>
  179. <strong class="ph b">&lt;startflag imageref="startlin.png"&gt;</strong>
  180. <strong class="ph b">&lt;alt-text&gt;Start linux&lt;/alt-text&gt;&lt;/startflag&gt;&lt;/prop&gt;</strong>
  181. <strong class="ph b">&lt;revprop action="flag" style="double-underline" val="rev2"&gt;</strong>
  182. <strong class="ph b">&lt;startflag imageref="start_rev.gif"&gt;</strong>
  183. <strong class="ph b">&lt;alt-text&gt; &lt;/alt-text&gt;&lt;/startflag&gt;&lt;/revprop&gt;</strong>
  184. <strong class="ph b">&lt;/ditaval-startprop&gt;</strong>
  185. &lt;li class="- topic/li "&gt;
  186. Generate images for platform="linux" and rev="2"
  187. &lt;/li&gt;
  188. <strong class="ph b">&lt;ditaval-endprop</strong>
  189. <strong class="ph b">class="+ topic/foreign ditaot-d/ditaval-endprop "&gt;</strong>
  190. <strong class="ph b">&lt;revprop action="flag" style="double-underline" val="rev2"&gt;</strong>
  191. <strong class="ph b">&lt;endflag imageref="end_rev.gif"&gt;</strong>
  192. <strong class="ph b">&lt;alt-text&gt;END&lt;/alt-text&gt;&lt;/endflag&gt;&lt;/revprop&gt;</strong>
  193. <strong class="ph b">&lt;prop action="flag" att="platform" val="linux" style="overline"</strong>
  194. <strong class="ph b">backcolor="blue"&gt;</strong>
  195. <strong class="ph b">&lt;endflag imageref="endlin.png"&gt;</strong>
  196. <strong class="ph b">&lt;alt-text&gt;End linux&lt;/alt-text&gt;&lt;/endflag&gt;&lt;/prop&gt;</strong>
  197. <strong class="ph b">&lt;/ditaval-endprop&gt;</strong>
  198. &lt;/ol&gt;</code></pre>
  199. </div>
  200. </div>
  201. <nav role="navigation" class="related-links"><div class="familylinks"><div class="parentlink"><strong>Parent topic:</strong> <a class="link" href="../reference/preprocessing.html" title="The pre-processing operation is a set of steps that typically runs at the beginning of every DITA-OT transformation. Each step or stage corresponds to an Ant target in the build pipeline; the preprocess target calls the entire set of steps.">Pre-processing modules</a></div><div class="previouslink"><strong>Previous topic:</strong> <a class="link" href="../reference/preprocess-topicpull.html" title="The topicpull step pulls content into xref and link elements. This step is implemented in XSLT.">Pull content into topics (topicpull)</a></div><div class="nextlink"><strong>Next topic:</strong> <a class="link" href="../reference/preprocess-clean-map.html" title="The clean-map step removes any elements and attributes that were added to files to support preprocessing.">Map cleanup (clean-map)</a></div></div></nav></article></main></body></html>