summary refs log tree commit diff
diff options
context:
space:
mode:
authorNaïm Favier <n@monade.li>2021-10-03 17:59:35 +0200
committerNaïm Favier <n@monade.li>2021-10-03 17:59:44 +0200
commit330b1e08b8df4e1f0100a0a7810ec3157749e5ee (patch)
treebe2e913c277a3faa96a6d53a91a1bbb590bc32ee
parent52a2e4136e270f9efd6838adb69304fe6d4d431e (diff)
downloadnixpkgs-330b1e08b8df4e1f0100a0a7810ec3157749e5ee.tar
nixpkgs-330b1e08b8df4e1f0100a0a7810ec3157749e5ee.tar.gz
nixpkgs-330b1e08b8df4e1f0100a0a7810ec3157749e5ee.tar.bz2
nixpkgs-330b1e08b8df4e1f0100a0a7810ec3157749e5ee.tar.lz
nixpkgs-330b1e08b8df4e1f0100a0a7810ec3157749e5ee.tar.xz
nixpkgs-330b1e08b8df4e1f0100a0a7810ec3157749e5ee.tar.zst
nixpkgs-330b1e08b8df4e1f0100a0a7810ec3157749e5ee.zip
nixos/lib/make-options-doc: implement literalDocBook
-rw-r--r--nixos/lib/make-options-doc/options-to-docbook.xsl46
1 files changed, 28 insertions, 18 deletions
diff --git a/nixos/lib/make-options-doc/options-to-docbook.xsl b/nixos/lib/make-options-doc/options-to-docbook.xsl
index 18d19fddaca..da4cd164bf2 100644
--- a/nixos/lib/make-options-doc/options-to-docbook.xsl
+++ b/nixos/lib/make-options-doc/options-to-docbook.xsl
@@ -54,7 +54,7 @@
                 <para>
                   <emphasis>Default:</emphasis>
                   <xsl:text> </xsl:text>
-                  <xsl:apply-templates select="attr[@name = 'default']" mode="top" />
+                  <xsl:apply-templates select="attr[@name = 'default']/*" mode="top" />
                 </para>
               </xsl:if>
 
@@ -62,14 +62,7 @@
                 <para>
                   <emphasis>Example:</emphasis>
                   <xsl:text> </xsl:text>
-                  <xsl:choose>
-                    <xsl:when test="attr[@name = 'example']/attrs[attr[@name = '_type' and string[@value = 'literalExample']]]">
-                      <programlisting><xsl:value-of select="attr[@name = 'example']/attrs/attr[@name = 'text']/string/@value" /></programlisting>
-                    </xsl:when>
-                    <xsl:otherwise>
-                      <xsl:apply-templates select="attr[@name = 'example']" mode="top" />
-                    </xsl:otherwise>
-                  </xsl:choose>
+                  <xsl:apply-templates select="attr[@name = 'example']/*" mode="top" />
                 </para>
               </xsl:if>
 
@@ -107,20 +100,37 @@
   </xsl:template>
 
 
-  <xsl:template match="*" mode="top">
+  <xsl:template match="attrs[attr[@name = '_type' and string[@value = 'literalExpression']]]" mode = "top">
     <xsl:choose>
-      <xsl:when test="string[contains(@value, '&#010;')]">
-<programlisting>
-<xsl:text>''
-</xsl:text><xsl:value-of select='str:replace(string/@value, "${", "&apos;&apos;${")' /><xsl:text>''</xsl:text></programlisting>
+      <xsl:when test="contains(attr[@name = 'text']/string/@value, '&#010;')">
+        <programlisting><xsl:value-of select="attr[@name = 'text']/string/@value" /></programlisting>
       </xsl:when>
       <xsl:otherwise>
-        <literal><xsl:apply-templates /></literal>
+        <literal><xsl:value-of select="attr[@name = 'text']/string/@value" /></literal>
       </xsl:otherwise>
     </xsl:choose>
   </xsl:template>
 
 
+  <xsl:template match="attrs[attr[@name = '_type' and string[@value = 'literalDocBook']]]" mode = "top">
+    <xsl:value-of disable-output-escaping="yes" select="attr[@name = 'text']/string/@value" />
+  </xsl:template>
+
+
+  <xsl:template match="string[contains(@value, '&#010;')]" mode="top">
+    <programlisting>
+      <xsl:text>''&#010;</xsl:text>
+      <xsl:value-of select='str:replace(str:replace(@value, "&apos;&apos;", "&apos;&apos;&apos;"), "${", "&apos;&apos;${")' />
+      <xsl:text>''</xsl:text>
+    </programlisting>
+  </xsl:template>
+
+
+  <xsl:template match="*" mode="top">
+    <literal><xsl:apply-templates select="." /></literal>
+  </xsl:template>
+
+
   <xsl:template match="null">
     <xsl:text>null</xsl:text>
   </xsl:template>
@@ -129,10 +139,10 @@
   <xsl:template match="string">
     <xsl:choose>
       <xsl:when test="(contains(@value, '&quot;') or contains(@value, '\')) and not(contains(@value, '&#010;'))">
-        <xsl:text>''</xsl:text><xsl:value-of select='str:replace(@value, "${", "&apos;&apos;${")' /><xsl:text>''</xsl:text>
+        <xsl:text>''</xsl:text><xsl:value-of select='str:replace(str:replace(@value, "&apos;&apos;", "&apos;&apos;&apos;"), "${", "&apos;&apos;${")' /><xsl:text>''</xsl:text>
       </xsl:when>
       <xsl:otherwise>
-        <xsl:text>"</xsl:text><xsl:value-of select="str:replace(str:replace(str:replace(str:replace(@value, '\', '\\'), '&quot;', '\&quot;'), '&#010;', '\n'), '$', '\$')" /><xsl:text>"</xsl:text>
+        <xsl:text>"</xsl:text><xsl:value-of select="str:replace(str:replace(str:replace(str:replace(@value, '\', '\\'), '&quot;', '\&quot;'), '&#010;', '\n'), '${', '\${')" /><xsl:text>"</xsl:text>
       </xsl:otherwise>
     </xsl:choose>
   </xsl:template>
@@ -163,7 +173,7 @@
   </xsl:template>
 
 
-  <xsl:template match="attrs[attr[@name = '_type' and string[@value = 'literalExample']]]">
+  <xsl:template match="attrs[attr[@name = '_type' and string[@value = 'literalExpression']]]">
     <xsl:value-of select="attr[@name = 'text']/string/@value" />
   </xsl:template>