Skip to content

Commit

Permalink
[fix] missing document numbers in reader's TOC
Browse files Browse the repository at this point in the history
  • Loading branch information
ccheraa committed Sep 28, 2022
1 parent e97bc38 commit 29ead2c
Showing 1 changed file with 44 additions and 6 deletions.
50 changes: 44 additions & 6 deletions modules/epub3.xql
Original file line number Diff line number Diff line change
Expand Up @@ -274,21 +274,60 @@ declare function local:update-nav($nodes) {
$node/@*,
local:update-nav($node/node())
)}
case element(xhtml:a) return
let $id := substring-after($node/@href/string(), '#')
return if (matches($id, "^d\d+$")) then element {node-name($node)} {(
$node/@*,
concat('[', substring-after($id, 'd'), '] ', $node/text())
)} else $node
default return element {node-name($node)} {(
$node/@*,
for $child in $node/node()
return local:update-nav($child)
)}
};

declare function local:update-navmap($nodes) {
for $node in $nodes
return typeswitch ($node)
case text() return $node
default return
if (name($node)='navPoint') then
element {node-name($node)} {
$node/@*,
for $child-node in $node/node() return
if (name($child-node)='navLabel') then
let $id := $node/@id/string()
return if (matches($id, "^navpoint-d\d+$")) then
element {node-name($child-node)} {
$child-node/@*,
let $text := $child-node/node()[name()='text']
return element {node-name($text)} {
$text/@*,
concat('[', substring-after($id, 'navpoint-d'), '] ', $text/text())
}
}
else
$child-node
else
local:update-navmap($child-node)
}
else
element {node-name($node)} {(
$node/@*,
for $child in $node/node()
return local:update-navmap($child)
)}
};

declare function local:update-toc($nodes) {
for $node in $nodes
return typeswitch ($node)
case text() return $node
case element(ncx:navMap) return
case element(ncx:navMap) return
element {node-name($node)} {(
$node/@*,
$node/node()[not(@id="navpoint-title")][not(./text()="Title")]
local:update-navmap($node/node())
)}
default return element {node-name($node)} {(
$node/@*,
Expand Down Expand Up @@ -632,8 +671,8 @@ declare function local:update-text-node($config, $node, $skip-nesting) {
(
element {node-name($node/tei:head)} {(
(
$node/tei:head/@*,
attribute rend { if ($node/parent::tei:body) then "compilation-title" else "chapter-title" }
$node/tei:head/@*,
attribute rend { if ($node/parent::tei:body) then "compilation-title" else "chapter-title" }
),
$node/tei:head/node()
)}
Expand All @@ -648,15 +687,14 @@ declare function local:update-text-node($config, $node, $skip-nesting) {
<div>
<ul>{
for $document in $node/tei:div[@type='chapter']
let $docnumber := frus:document-number($document)
let $docid := frus:document-id($document)
let $doctitle := frus:document-head-sans-number($document)
let $docsource := frus:source-note($document)/string()
let $docdateline := local:update-text-node($config, frus:dateline($document))
let $docsummary := $document//tei:note[@type='summary']/string()
return (
<tei:milestone/>,
<tei:ref rend="ref-title" target="#{$docid}">{if (not(starts-with($document/tei:head, concat($document/@n, '.')))) then concat('[', $docnumber, ']') else concat($docnumber, '. '), $doctitle}</tei:ref>,
<tei:ref rend="ref-title" target="#{$docid}">{$doctitle}</tei:ref>,
<opener><p class="dateline">{$docdateline}</p></opener>,
if (exists($docsummary)) then <p>{$docsummary}</p> else (),
<p class="sourcenote">{$docsource}</p>
Expand Down

0 comments on commit 29ead2c

Please sign in to comment.