Skip to content

Commit

Permalink
Merge pull request #567 from ndw/iss-566
Browse files Browse the repository at this point in the history
Support different options for dealing with unhandled elements
  • Loading branch information
ndw authored Dec 4, 2024
2 parents 309b096 + c61c544 commit 4ff16dc
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 48 deletions.
22 changes: 22 additions & 0 deletions src/guide/xml/ref-modes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2030,5 +2030,27 @@ Be aware, however, that the HTML markup is quite constrained for panel sets.
</refsection>
</refentry>

<refentry xml:id="m_unhandled">
<?db filename="m_unhandled"?>
<refmeta>
<refentrytitle>m:unhandled</refentrytitle>
<refmiscinfo>{http://docbook.org/ns/docbook/modes}unhandled</refmiscinfo>
<refmiscinfo class="version">2.5.1</refmiscinfo>
</refmeta>
<refnamediv>
<refname>m:unhandled</refname>
<refpurpose>Process unhandled elements</refpurpose>
<refclass>mode</refclass>
</refnamediv>
<refsection>
<title>Description</title>
<para>When <parameter>on-unhandled-elements</parameter> is set to <literal>custom</literal>,
elements with no other matching template will be processed in this mode. Note that
there are no templates in this mode in the standard stylesheets. This is an extensibility
point for customization layers.
</para>
</refsection>
</refentry>

</reference>

49 changes: 49 additions & 0 deletions src/guide/xml/ref-params.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5898,4 +5898,53 @@ unless a processing instruction overrides it.</para>
</refsection>
</refentry>

<refentry>
<refmeta>
<fieldsynopsis>
<type>xs:string</type>
<varname>on-unhandled-elements</varname>
<initializer>'fail'</initializer>
</fieldsynopsis>
<refmiscinfo class="version">2.5.1</refmiscinfo>
</refmeta>
<refnamediv>
<refpurpose>How to process unhandled elements</refpurpose>
</refnamediv>
<refsection>
<title>Description</title>

<para>This parameter controls how unhandled elements (for example, extension
elements added in a custom schema) should be processed.</para>

<variablelist role="enumeration">
<varlistentry>
<term>
<enumvalue>terminate</enumvalue>
</term>
<listitem>
<para>Generates an error messages and aborts the transformation.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<enumvalue>render</enumvalue>
</term>
<listitem>
<para>Renders the tag name in the output, styled in red and yellow.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<enumvalue>custom</enumvalue>
</term>
<listitem>
<para>Processes the template in the <mode>m:unhandled</mode> mode. These must be defined
in a customization layer; there are no templates in this mode in the standard stylesheets.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsection>
</refentry>

</reference>
13 changes: 12 additions & 1 deletion src/main/scss/media-all.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
--on-primary-color: #ffffff;
--on-primary-variant-color: #ffffff;
--on-secondary-color: #000000;
--on-error-color: #000000;
--on-error-color: #ffee42;
--enabled-color: rgb(240,240,240);
--hovered-color: rgb(235,235,235);
--focused-color: rgb(221,221,221);
Expand Down Expand Up @@ -201,6 +201,17 @@ span.error.broken-link::after {
content: " 🔗 ";
}

.unhandled {
font-family: monospace;
background-color: var(--error-border-color);
color: var(--on-error-color);
font-weight: bold;
}

div.unhandled {
width: 100%;
}

.firstterm {
font-weight: bold;
}
Expand Down
84 changes: 37 additions & 47 deletions src/main/xslt/modules/unhandled.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -9,53 +9,43 @@
version="3.0">

<xsl:template match="*">
<xsl:message terminate="yes"
select="'No template for ' || node-name(.) || ': ' || f:generate-id(.)"/>
<xsl:variable name="inline-style"
select="'font: monospace;
color: yellow;
background-color: red;
font-weight: bold;'"/>
<xsl:variable name="block-style"
select="'font: monospace;
color: yellow;
width: 100%;
background-color: red;
font-weight: bold;'"/>

<xsl:variable name="inline"
select="normalize-space(string-join(text(),'')) != ''"/>

<xsl:element namespace="http://www.w3.org/1999/xhtml"
name="{if ($inline) then 'span' else 'div'}">

<xsl:element namespace="http://www.w3.org/1999/xhtml"
name="{if ($inline) then 'span' else 'div'}">
<xsl:attribute name="style"
select="if ($inline) then $inline-style else $block-style"/>
<xsl:text>&lt;</xsl:text>
<xsl:value-of select="node-name(.)"/>
<xsl:text>&gt;</xsl:text>
</xsl:element>

<xsl:apply-templates/>

<xsl:element namespace="http://www.w3.org/1999/xhtml"
name="{if ($inline) then 'span' else 'div'}">
<xsl:attribute name="style"
select="if ($inline) then $inline-style else $block-style"/>
<xsl:text>&lt;/</xsl:text>
<xsl:value-of select="node-name(.)"/>
<xsl:text>&gt;</xsl:text>
</xsl:element>
</xsl:element>

<!--
<xsl:message>
<xsl:text>Unhandled element: </xsl:text>
<xsl:value-of select="node-name(.)"/>
</xsl:message>
-->
<xsl:choose>
<xsl:when test="$on-unhandled-elements = 'fail'">
<xsl:message terminate="yes"
select="'No template for ' || node-name(.) || ': ' || f:generate-id(.)"/>
</xsl:when>
<xsl:when test="$on-unhandled-elements = 'render'">
<xsl:message select="'No template for ' || node-name(.) || ': ' || f:generate-id(.)"/>

<xsl:variable name="inline"
select="normalize-space(string-join(text(),'')) != ''"/>

<xsl:element namespace="http://www.w3.org/1999/xhtml"
name="{if ($inline) then 'span' else 'div'}">

<xsl:element namespace="http://www.w3.org/1999/xhtml"
name="{if ($inline) then 'span' else 'div'}">
<xsl:attribute name="class" select="'unhandled'"/>
<xsl:text>&lt;</xsl:text>
<xsl:value-of select="node-name(.)"/>
<xsl:text>&gt;</xsl:text>
</xsl:element>

<xsl:apply-templates/>

<xsl:element namespace="http://www.w3.org/1999/xhtml"
name="{if ($inline) then 'span' else 'div'}">
<xsl:attribute name="class" select="'unhandled'"/>
<xsl:text>&lt;/</xsl:text>
<xsl:value-of select="node-name(.)"/>
<xsl:text>&gt;</xsl:text>
</xsl:element>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="." mode="m:unhandled"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template xmlns:h="http://www.w3.org/1999/xhtml"
Expand Down

0 comments on commit 4ff16dc

Please sign in to comment.