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 d7225c7 commit aaaf88e
Showing 1 changed file with 43 additions and 4 deletions.
47 changes: 43 additions & 4 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 Down

0 comments on commit aaaf88e

Please sign in to comment.