Skip to content

Commit

Permalink
Added support for titleabbrev-passthrough
Browse files Browse the repository at this point in the history
  • Loading branch information
ndw committed Feb 3, 2024
1 parent a77847d commit 511d916
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 12 deletions.
51 changes: 51 additions & 0 deletions src/guide/xml/ref-params.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5648,4 +5648,55 @@ in the online stylesheets (but might in the future).</para>
</refsection>
</refentry>

<refentry>
<refmeta>
<fieldsynopsis>
<type>xs:string</type>
<varname>titleabbrev-passthrough</varname>
<initializer>'true'</initializer>
</fieldsynopsis>
</refmeta>
<refnamediv>
<refpurpose>Pass <tag>titleabbrev</tag> elements through to the HTML</refpurpose>
</refnamediv>
<refsection>
<title>Description</title>

<para>The <tag>titleabbrev</tag> element allows an author to provide
an abbreviated title. This is used, for example, in the Table of
Contents and in other “lists of titles” (LoT).</para>

<para>The actual titles of books, chapters, sections, etc. come from
the <tag>title</tag> element. But if downstream processing generates an LoT
dynamically, for example the <link linkend="onpage-toc">on-page table of contents</link>,
it’s useful to have access to the <tag>titleabbrev</tag> content.</para>

<para>Unfortunately, HTML doesn’t provide an obvious mechanism to pass
content that should not be rendered. (Simply suppressing the content
with CSS is insufficient in this case because the abbreviated title
really shouldn’t appear even if CSS is not available.) The only element that won’t
render is the
<tag namespace="http://www.w3.org/1999/xhtml">script</tag> element.</para>

<para>If this parameter <glossterm>is true</glossterm>, the rendered
<tag>titleabbrev</tag> content will be embedded in the header using a
script element. For example:</para>

<programlisting language="xml"><![CDATA[<header>
<h1>
<script type="text/html" class="titleabbrev"
>Buckaroo Banzai</script>The Adventures of
Buckaroo Banzai Across the 8th Dimension
</h1>
</header>]]></programlisting>

<para>If it’s present, the on-page ToC feature will render the abbreviated title.
This parameter is true by default. Abbreviated titles are relatively uncommon
and the presence of extra script elements isn’t likely to be a problem. But if your
environment has hard requirements to avoid script elements, this feature can
be disabled by setting the parameter to “false”.</para>

</refsection>
</refentry>

</reference>
6 changes: 5 additions & 1 deletion src/main/web/js/pagetoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,13 @@
}
const id = sect.getAttribute("id");
const header = sect.querySelector("header");
const title = header && header.querySelector("h1,h2,h3,h4,h5,h6");
const skip = sect.classList.contains("nopagetoc");

let title = header && header.querySelector("h1,h2,h3,h4,h5,h6");
if (title.querySelector("script.titleabbrev")) {
title = title.querySelector("script.titleabbrev");
}

if (title && !skip) {
toclength++;
sections.push({
Expand Down
15 changes: 15 additions & 0 deletions src/main/xslt/modules/titles.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,21 @@
</xsl:if>
</xsl:variable>

<xsl:if test="f:is-true($titleabbrev-passthrough)
and db:info/db:titleabbrev and not($purpose = 'lot')">
<script type="text/html" class="titleabbrev">
<xsl:apply-templates select="$template" mode="mp:localization">
<xsl:with-param name="context" select="."/>
<xsl:with-param name="label" select="$label"/>
<xsl:with-param name="content">
<xsl:apply-templates select="." mode="m:headline-title">
<xsl:with-param name="purpose" select="'abbrev'"/>
</xsl:apply-templates>
</xsl:with-param>
</xsl:apply-templates>
</script>
</xsl:if>

<xsl:apply-templates select="$template" mode="mp:localization">
<xsl:with-param name="context" select="."/>
<xsl:with-param name="label" select="$label"/>
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/expected/article.005.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
Some text. Some text. Some text. Some text. Some text. Some text.
Some text. Some text. Some text. Some text. Some text. Some text.
Some text. Some text. Some text. Some text. Some text. Some text.
</p></section></section><section id="article_s1_2" class="sect1"><header><h2><span class="label">2</span><span class="sep"></span>Second Sect1</h2></header><p>
</p></section></section><section id="article_s1_2" class="sect1"><header><h2><script type="text/html" class="titleabbrev"><span class="label">2</span><span class="sep">. </span>SecondAbbrev</script><span class="label">2</span><span class="sep"></span>Second Sect1</h2></header><p>
The <code class="tag tag-element">titleabbrev</code> is set to
<code class="literal">SecondAbbrev</code>. Ensure it's using the abbreviated
title in the TOC.</p><p>
Foo bar foo bar. Foo bar foo bar. Foo bar foo bar. Foo bar foo bar.
Foo bar foo bar. Foo bar foo bar. Foo bar foo bar. Foo bar foo bar.
Foo bar foo bar. Foo bar foo bar.
</p></section><section id="article_s1_3" class="sect1"><header><h2><span class="label">3</span><span class="sep"></span>Using Sect1Info</h2></header><p>
</p></section><section id="article_s1_3" class="sect1"><header><h2><script type="text/html" class="titleabbrev"><span class="label">3</span><span class="sep">. </span>Second1Info</script><span class="label">3</span><span class="sep"></span>Using Sect1Info</h2></header><p>
The <code class="tag tag-element">titleabbrev</code> is set to
<code class="literal">Second1Info</code>. Ensure it's using the abbreviated
title in the TOC.</p><p>
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/expected/book.001.html
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
aute irure dolor in reprehenderit in voluptate velit esse cillum
dolore eu fugiat nulla pariatur. Excepteur sint occaecat
cupidatat non proident, sunt in culpa qui officia deserunt
mollit anim id est laborum.</p></section></article><div class="list-of-titles"><div class="lot toc"><div class="title">Table of Contents</div><ul class="toc"><li><a href="#chap1"><span class="label">1</span><span class="sep"></span>F. Chap</a><ul class="toc"><li><a href="#c1s1"><span class="label">1</span><span class="sep"></span>F. Sect</a></li><li><a href="#c1s2"><span class="label">2</span><span class="sep"></span>Second Section</a></li><li><a href="#c1s3"><span class="label">3</span><span class="sep"></span>Third Section</a></li></ul></li><li><a href="#chap2"><span class="label">2</span><span class="sep"></span>Second Chapter</a><ul class="toc"><li><a href="#c2s1"><span class="label">1</span><span class="sep"></span>First Section</a></li><li><a href="#c2s2"><span class="label">2</span><span class="sep"></span>Second Section</a></li><li><a href="#c2s3"><span class="label">3</span><span class="sep"></span>Third Section</a></li></ul></li></ul></div></div><section id="chap1" class="chapter component"><header><h1>Chapter <span class="label">1</span><span class="sep"></span>First Chapter</h1></header><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit,
mollit anim id est laborum.</p></section></article><div class="list-of-titles"><div class="lot toc"><div class="title">Table of Contents</div><ul class="toc"><li><a href="#chap1"><span class="label">1</span><span class="sep"></span>F. Chap</a><ul class="toc"><li><a href="#c1s1"><span class="label">1</span><span class="sep"></span>F. Sect</a></li><li><a href="#c1s2"><span class="label">2</span><span class="sep"></span>Second Section</a></li><li><a href="#c1s3"><span class="label">3</span><span class="sep"></span>Third Section</a></li></ul></li><li><a href="#chap2"><span class="label">2</span><span class="sep"></span>Second Chapter</a><ul class="toc"><li><a href="#c2s1"><span class="label">1</span><span class="sep"></span>First Section</a></li><li><a href="#c2s2"><span class="label">2</span><span class="sep"></span>Second Section</a></li><li><a href="#c2s3"><span class="label">3</span><span class="sep"></span>Third Section</a></li></ul></li></ul></div></div><section id="chap1" class="chapter component"><header><h1><script type="text/html" class="titleabbrev">Chapter <span class="label">1</span><span class="sep">. </span>F. Chap</script>Chapter <span class="label">1</span><span class="sep"></span>First Chapter</h1></header><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation
ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis
Expand Down Expand Up @@ -252,7 +252,7 @@
erat. Cras mollis scelerisque nunc. Nullam arcu. Aliquam
consequat. Curabitur augue lorem, dapibus quis, laoreet et,
pretium ac, nisi. Aenean magna nisl, mollis quis, molestie eu,
feugiat in, orci. In hac habitasse platea dictumst.</p><section id="c1s1" class="section"><header><h2><span class="label">1</span><span class="sep"></span>First Section</h2></header><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit,
feugiat in, orci. In hac habitasse platea dictumst.</p><section id="c1s1" class="section"><header><h2><script type="text/html" class="titleabbrev"><span class="label">1</span><span class="sep">. </span>F. Sect</script><span class="label">1</span><span class="sep"></span>First Section</h2></header><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation
ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/expected/fit.001.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
new (and better!) styles with CSS. You can also write stylesheet
extensions to customize the markup, to add additional details to
the header and footer, for example.
</p></dd></dl></div></section><section id="toc" class="chapter component"><header><h2>Chapter <span class="label">2</span><span class="sep"></span>Persistent Table of Contents</h2></header><p>The Persistent Table of Contents brings the document’s Table of
</p></dd></dl></div></section><section id="toc" class="chapter component"><header><h2><script type="text/html" class="titleabbrev">Chapter <span class="label">2</span><span class="sep">. </span>Persistent ToC</script>Chapter <span class="label">2</span><span class="sep"></span>Persistent Table of Contents</h2></header><p>The Persistent Table of Contents brings the document’s Table of
Contents navigation hierarchy to every page. Clicking on the
<span class="inlinemediaobject" summary="[toc]"><span class="media image"><picture class="imageobject"><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAQCAYAAAAWGF8bAAAACXBIWXMAABYlAAAWJQFJUiTwAAABDklEQVQ4je2UUW3EMAyGv0wDUAhlkDBIyuAYXCEclEJoGZRBUgYOgzJoGHgPW6o7rWq35+2TIkWW9duW7N+oKuM46jiOGGMAaNsW5xzee5xzn8EvRESXZUFEWNcVAFWl73v6vjcGUIAYIyEEANZ1RUSY55lSCo/HA4BhGGiahtvthnOOtm0BSCnRdd1eVAGNMeoR27aptVattbpt22FOjFGrzjsX1I7q/4q3y4xf8i/4FwT3Pcw5Y4zBWvujfQMopZBzJuf8XbCeVyWEgHOO+/2+x0SEaZpIKSEih0X2Wz6jdlxKuezaqL7qpZS0lLKbw/M4ANba3RyapiGE8OJGqOrpizGq916999VATvM/AGFn1sxsVjL5AAAAAElFTkSuQmCC" alt="[toc]"/></picture></span></span>
link in the upper right corner slides out the Table of Contents window
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/expected/fit.002.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
new (and better!) styles with CSS. You can also write stylesheet
extensions to customize the markup, to add additional details to
the header and footer, for example.
</p></dd></dl></div></section><section id="toc" class="chapter component"><header><h2>Chapter <span class="label">2</span><span class="sep"></span>Persistent Table of Contents</h2></header><p>The Persistent Table of Contents brings the document’s Table of
</p></dd></dl></div></section><section id="toc" class="chapter component"><header><h2><script type="text/html" class="titleabbrev">Chapter <span class="label">2</span><span class="sep">. </span>Persistent ToC</script>Chapter <span class="label">2</span><span class="sep"></span>Persistent Table of Contents</h2></header><p>The Persistent Table of Contents brings the document’s Table of
Contents navigation hierarchy to every page. Clicking on the
<span class="inlinemediaobject" summary="[toc]"><span class="media image"><picture class="imageobject"><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAQCAYAAAAWGF8bAAAACXBIWXMAABYlAAAWJQFJUiTwAAABDklEQVQ4je2UUW3EMAyGv0wDUAhlkDBIyuAYXCEclEJoGZRBUgYOgzJoGHgPW6o7rWq35+2TIkWW9duW7N+oKuM46jiOGGMAaNsW5xzee5xzn8EvRESXZUFEWNcVAFWl73v6vjcGUIAYIyEEANZ1RUSY55lSCo/HA4BhGGiahtvthnOOtm0BSCnRdd1eVAGNMeoR27aptVattbpt22FOjFGrzjsX1I7q/4q3y4xf8i/4FwT3Pcw5Y4zBWvujfQMopZBzJuf8XbCeVyWEgHOO+/2+x0SEaZpIKSEih0X2Wz6jdlxKuezaqL7qpZS0lLKbw/M4ANba3RyapiGE8OJGqOrpizGq916999VATvM/AGFn1sxsVjL5AAAAAElFTkSuQmCC" alt="[toc]"/></picture></span></span>
link in the upper right corner slides out the Table of Contents window
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/expected/link.003.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" class="no-js"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><script>(function(H){H.className=H.className.replace(/\bno-js\b/,'js')})(document.documentElement)</script><title>Article wrapper</title><meta name="viewport" content="width=device-width, initial-scale=1.0"/><link href="https://purl.org/dc/elements/1.1/" rel="schema.dc"/><meta content="2011-04-22T17:02:00-06:00" name="dc.modified"/><meta content="DocBook xslTNG" name="generator"/><link href="./css/docbook.css" rel="stylesheet" media="screen"/></head><body class="home"><nav class="top"></nav><main><article class="article component"><header><h1>Article wrapper</h1></header><div class="list-of-titles"><div class="lot toc"><div class="title">Table of Contents</div><ul class="toc"><li><a href="#section"><span class="label">1</span><span class="sep"></span>Section Title</a></li><li><a href="#section2"><span class="label">2</span><span class="sep"></span>Long Section Title</a></li></ul></div></div><section id="section" class="section"><header><h2><span class="label">1</span><span class="sep"></span>Section Title</h2></header><p>A <a href="#section" class="link">self-referential link</a>.</p><p>A link without content: <a href="#section2" class="xref xref-section">Section <span class="label">2</span>, “Long Section Title”</a>.</p><p>A link without content, but with an xreflabel:
<a href="#section2" class="xref xref-section">Section <span class="label">2</span>, “Long Section Title”</a>.</p><p>A link with content and an xreflabel:
<a href="#section2" class="link">here</a>.</p></section><section id="section2" class="section"><header><h2><span class="label">2</span><span class="sep"></span>A Very Long Section Title That I Don't Want To Use For My XRef</h2></header><p>Some text with a <a href="#section" class="link">link back</a> to the
<a href="#section2" class="link">here</a>.</p></section><section id="section2" class="section"><header><h2><script type="text/html" class="titleabbrev"><span class="label">2</span><span class="sep">. </span>Long Section Title</script><span class="label">2</span><span class="sep"></span>A Very Long Section Title That I Don't Want To Use For My XRef</h2></header><p>Some text with a <a href="#section" class="link">link back</a> to the
first section.</p></section></article></main><nav class="bottom"></nav></body></html>
Loading

0 comments on commit 511d916

Please sign in to comment.