nixos/make-options-doc: render default/example contents through MD
removes some trailing whitespaces from the html output, no other changes.
This commit is contained in:
parent
2bd8129a47
commit
3a5f1ae029
|
@ -203,6 +203,30 @@ def convertMD(options: Dict[str, Any]) -> str:
|
||||||
if '_type' not in option[key]: return False
|
if '_type' not in option[key]: return False
|
||||||
return option[key]['_type'] == typ
|
return option[key]['_type'] == typ
|
||||||
|
|
||||||
|
def convertCode(name: str, option: Dict[str, Any], key: str):
|
||||||
|
rendered = f"{key}-db"
|
||||||
|
if optionIs(option, key, 'literalMD'):
|
||||||
|
docbook = convertString(name, f"*{key.capitalize()}:*\n{option[key]['text']}")
|
||||||
|
option[rendered] = f"<para>{docbook}</para>"
|
||||||
|
elif optionIs(option, key, 'literalExpression'):
|
||||||
|
code = option[key]['text']
|
||||||
|
# for multi-line code blocks we only have to count ` runs at the beginning
|
||||||
|
# of a line, but this is much easier.
|
||||||
|
multiline = '\n' in code
|
||||||
|
longest, current = (0, 0)
|
||||||
|
for c in code:
|
||||||
|
current = current + 1 if c == '`' else 0
|
||||||
|
longest = max(current, longest)
|
||||||
|
# inline literals need a space to separate ticks from content, code blocks
|
||||||
|
# need newlines. inline literals need one extra tick, code blocks need three.
|
||||||
|
ticks, sep = ('`' * (longest + (3 if multiline else 1)), '\n' if multiline else ' ')
|
||||||
|
docbook = convertString(name, f"*{key.capitalize()}:*\n{ticks}{sep}{code}{sep}{ticks}")
|
||||||
|
option[rendered] = f"<para>{docbook}</para>"
|
||||||
|
elif optionIs(option, key, 'literalDocBook'):
|
||||||
|
option[rendered] = f"<para><emphasis>{key.capitalize()}:</emphasis> {option[key]['text']}</para>"
|
||||||
|
elif key in option:
|
||||||
|
raise Exception(f"{name} {key} has unrecognized type", option[key])
|
||||||
|
|
||||||
for (name, option) in options.items():
|
for (name, option) in options.items():
|
||||||
try:
|
try:
|
||||||
if optionIs(option, 'description', 'mdDoc'):
|
if optionIs(option, 'description', 'mdDoc'):
|
||||||
|
@ -210,12 +234,8 @@ def convertMD(options: Dict[str, Any]) -> str:
|
||||||
elif markdownByDefault:
|
elif markdownByDefault:
|
||||||
option['description'] = convertString(name, option['description'])
|
option['description'] = convertString(name, option['description'])
|
||||||
|
|
||||||
if optionIs(option, 'example', 'literalMD'):
|
convertCode(name, option, 'example')
|
||||||
docbook = convertString(name, option['example']['text'])
|
convertCode(name, option, 'default')
|
||||||
option['example'] = { '_type': 'literalDocBook', 'text': docbook }
|
|
||||||
if optionIs(option, 'default', 'literalMD'):
|
|
||||||
docbook = convertString(name, option['default']['text'])
|
|
||||||
option['default'] = { '_type': 'literalDocBook', 'text': docbook }
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise Exception(f"Failed to render option {name}: {str(e)}")
|
raise Exception(f"Failed to render option {name}: {str(e)}")
|
||||||
|
|
||||||
|
|
|
@ -72,22 +72,14 @@
|
||||||
</para>
|
</para>
|
||||||
</xsl:if>
|
</xsl:if>
|
||||||
|
|
||||||
<xsl:if test="attr[@name = 'default']">
|
<xsl:if test="attr[@name = 'default-db']">
|
||||||
<para>
|
<xsl:value-of disable-output-escaping="yes"
|
||||||
<emphasis>Default:</emphasis>
|
select="attr[@name = 'default-db']/string/@value" />
|
||||||
<xsl:text>
|
|
||||||
</xsl:text>
|
|
||||||
<xsl:apply-templates select="attr[@name = 'default']/*" mode="top" />
|
|
||||||
</para>
|
|
||||||
</xsl:if>
|
</xsl:if>
|
||||||
|
|
||||||
<xsl:if test="attr[@name = 'example']">
|
<xsl:if test="attr[@name = 'example-db']">
|
||||||
<para>
|
<xsl:value-of disable-output-escaping="yes"
|
||||||
<emphasis>Example:</emphasis>
|
select="attr[@name = 'example-db']/string/@value" />
|
||||||
<xsl:text>
|
|
||||||
</xsl:text>
|
|
||||||
<xsl:apply-templates select="attr[@name = 'example']/*" mode="top" />
|
|
||||||
</para>
|
|
||||||
</xsl:if>
|
</xsl:if>
|
||||||
|
|
||||||
<xsl:if test="attr[@name = 'relatedPackages']">
|
<xsl:if test="attr[@name = 'relatedPackages']">
|
||||||
|
@ -123,19 +115,6 @@
|
||||||
</xsl:template>
|
</xsl:template>
|
||||||
|
|
||||||
|
|
||||||
<xsl:template match="attrs[attr[@name = '_type' and string[@value = 'literalExpression']]]" mode = "top">
|
|
||||||
<xsl:choose>
|
|
||||||
<xsl:when test="contains(attr[@name = 'text']/string/@value, '
')">
|
|
||||||
<programlisting><xsl:value-of select="attr[@name = 'text']/string/@value" /><xsl:text>
|
|
||||||
</xsl:text></programlisting>
|
|
||||||
</xsl:when>
|
|
||||||
<xsl:otherwise>
|
|
||||||
<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: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:value-of disable-output-escaping="yes" select="attr[@name = 'text']/string/@value" />
|
||||||
</xsl:template>
|
</xsl:template>
|
||||||
|
|
Loading…
Reference in a new issue