Skip to content

Commit 4ff16dc

Browse files
authored
Merge pull request docbook#567 from ndw/iss-566
Support different options for dealing with unhandled elements
2 parents 309b096 + c61c544 commit 4ff16dc

File tree

4 files changed

+120
-48
lines changed

4 files changed

+120
-48
lines changed

src/guide/xml/ref-modes.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2030,5 +2030,27 @@ Be aware, however, that the HTML markup is quite constrained for panel sets.
20302030
</refsection>
20312031
</refentry>
20322032

2033+
<refentry xml:id="m_unhandled">
2034+
<?db filename="m_unhandled"?>
2035+
<refmeta>
2036+
<refentrytitle>m:unhandled</refentrytitle>
2037+
<refmiscinfo>{http://docbook.org/ns/docbook/modes}unhandled</refmiscinfo>
2038+
<refmiscinfo class="version">2.5.1</refmiscinfo>
2039+
</refmeta>
2040+
<refnamediv>
2041+
<refname>m:unhandled</refname>
2042+
<refpurpose>Process unhandled elements</refpurpose>
2043+
<refclass>mode</refclass>
2044+
</refnamediv>
2045+
<refsection>
2046+
<title>Description</title>
2047+
<para>When <parameter>on-unhandled-elements</parameter> is set to <literal>custom</literal>,
2048+
elements with no other matching template will be processed in this mode. Note that
2049+
there are no templates in this mode in the standard stylesheets. This is an extensibility
2050+
point for customization layers.
2051+
</para>
2052+
</refsection>
2053+
</refentry>
2054+
20332055
</reference>
20342056

src/guide/xml/ref-params.xml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5898,4 +5898,53 @@ unless a processing instruction overrides it.</para>
58985898
</refsection>
58995899
</refentry>
59005900

5901+
<refentry>
5902+
<refmeta>
5903+
<fieldsynopsis>
5904+
<type>xs:string</type>
5905+
<varname>on-unhandled-elements</varname>
5906+
<initializer>'fail'</initializer>
5907+
</fieldsynopsis>
5908+
<refmiscinfo class="version">2.5.1</refmiscinfo>
5909+
</refmeta>
5910+
<refnamediv>
5911+
<refpurpose>How to process unhandled elements</refpurpose>
5912+
</refnamediv>
5913+
<refsection>
5914+
<title>Description</title>
5915+
5916+
<para>This parameter controls how unhandled elements (for example, extension
5917+
elements added in a custom schema) should be processed.</para>
5918+
5919+
<variablelist role="enumeration">
5920+
<varlistentry>
5921+
<term>
5922+
<enumvalue>terminate</enumvalue>
5923+
</term>
5924+
<listitem>
5925+
<para>Generates an error messages and aborts the transformation.</para>
5926+
</listitem>
5927+
</varlistentry>
5928+
<varlistentry>
5929+
<term>
5930+
<enumvalue>render</enumvalue>
5931+
</term>
5932+
<listitem>
5933+
<para>Renders the tag name in the output, styled in red and yellow.</para>
5934+
</listitem>
5935+
</varlistentry>
5936+
<varlistentry>
5937+
<term>
5938+
<enumvalue>custom</enumvalue>
5939+
</term>
5940+
<listitem>
5941+
<para>Processes the template in the <mode>m:unhandled</mode> mode. These must be defined
5942+
in a customization layer; there are no templates in this mode in the standard stylesheets.
5943+
</para>
5944+
</listitem>
5945+
</varlistentry>
5946+
</variablelist>
5947+
</refsection>
5948+
</refentry>
5949+
59015950
</reference>

src/main/scss/media-all.scss

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
--on-primary-color: #ffffff;
1313
--on-primary-variant-color: #ffffff;
1414
--on-secondary-color: #000000;
15-
--on-error-color: #000000;
15+
--on-error-color: #ffee42;
1616
--enabled-color: rgb(240,240,240);
1717
--hovered-color: rgb(235,235,235);
1818
--focused-color: rgb(221,221,221);
@@ -201,6 +201,17 @@ span.error.broken-link::after {
201201
content: " 🔗 ";
202202
}
203203

204+
.unhandled {
205+
font-family: monospace;
206+
background-color: var(--error-border-color);
207+
color: var(--on-error-color);
208+
font-weight: bold;
209+
}
210+
211+
div.unhandled {
212+
width: 100%;
213+
}
214+
204215
.firstterm {
205216
font-weight: bold;
206217
}

src/main/xslt/modules/unhandled.xsl

Lines changed: 37 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -9,53 +9,43 @@
99
version="3.0">
1010

1111
<xsl:template match="*">
12-
<xsl:message terminate="yes"
13-
select="'No template for ' || node-name(.) || ': ' || f:generate-id(.)"/>
14-
<xsl:variable name="inline-style"
15-
select="'font: monospace;
16-
color: yellow;
17-
background-color: red;
18-
font-weight: bold;'"/>
19-
<xsl:variable name="block-style"
20-
select="'font: monospace;
21-
color: yellow;
22-
width: 100%;
23-
background-color: red;
24-
font-weight: bold;'"/>
25-
26-
<xsl:variable name="inline"
27-
select="normalize-space(string-join(text(),'')) != ''"/>
28-
29-
<xsl:element namespace="http://www.w3.org/1999/xhtml"
30-
name="{if ($inline) then 'span' else 'div'}">
31-
32-
<xsl:element namespace="http://www.w3.org/1999/xhtml"
33-
name="{if ($inline) then 'span' else 'div'}">
34-
<xsl:attribute name="style"
35-
select="if ($inline) then $inline-style else $block-style"/>
36-
<xsl:text>&lt;</xsl:text>
37-
<xsl:value-of select="node-name(.)"/>
38-
<xsl:text>&gt;</xsl:text>
39-
</xsl:element>
40-
41-
<xsl:apply-templates/>
42-
43-
<xsl:element namespace="http://www.w3.org/1999/xhtml"
44-
name="{if ($inline) then 'span' else 'div'}">
45-
<xsl:attribute name="style"
46-
select="if ($inline) then $inline-style else $block-style"/>
47-
<xsl:text>&lt;/</xsl:text>
48-
<xsl:value-of select="node-name(.)"/>
49-
<xsl:text>&gt;</xsl:text>
50-
</xsl:element>
51-
</xsl:element>
52-
53-
<!--
54-
<xsl:message>
55-
<xsl:text>Unhandled element: </xsl:text>
56-
<xsl:value-of select="node-name(.)"/>
57-
</xsl:message>
58-
-->
12+
<xsl:choose>
13+
<xsl:when test="$on-unhandled-elements = 'fail'">
14+
<xsl:message terminate="yes"
15+
select="'No template for ' || node-name(.) || ': ' || f:generate-id(.)"/>
16+
</xsl:when>
17+
<xsl:when test="$on-unhandled-elements = 'render'">
18+
<xsl:message select="'No template for ' || node-name(.) || ': ' || f:generate-id(.)"/>
19+
20+
<xsl:variable name="inline"
21+
select="normalize-space(string-join(text(),'')) != ''"/>
22+
23+
<xsl:element namespace="http://www.w3.org/1999/xhtml"
24+
name="{if ($inline) then 'span' else 'div'}">
25+
26+
<xsl:element namespace="http://www.w3.org/1999/xhtml"
27+
name="{if ($inline) then 'span' else 'div'}">
28+
<xsl:attribute name="class" select="'unhandled'"/>
29+
<xsl:text>&lt;</xsl:text>
30+
<xsl:value-of select="node-name(.)"/>
31+
<xsl:text>&gt;</xsl:text>
32+
</xsl:element>
33+
34+
<xsl:apply-templates/>
35+
36+
<xsl:element namespace="http://www.w3.org/1999/xhtml"
37+
name="{if ($inline) then 'span' else 'div'}">
38+
<xsl:attribute name="class" select="'unhandled'"/>
39+
<xsl:text>&lt;/</xsl:text>
40+
<xsl:value-of select="node-name(.)"/>
41+
<xsl:text>&gt;</xsl:text>
42+
</xsl:element>
43+
</xsl:element>
44+
</xsl:when>
45+
<xsl:otherwise>
46+
<xsl:apply-templates select="." mode="m:unhandled"/>
47+
</xsl:otherwise>
48+
</xsl:choose>
5949
</xsl:template>
6050

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

0 commit comments

Comments
 (0)