Commit 15ff7420 authored by mrodzis's avatar mrodzis 🌎
Browse files

Improve whitespace handling in tei:rs (cf. print#37)

parent 6ce18514
......@@ -80,7 +80,8 @@ declare function fontaneSimple:transform($nodes as node()*, $uri as xs:string) a
or $node/ancestor::tei:desc[@type = "edited_text"]
or $node/ancestor::tei:note[@type = "editorial"]) then
if($node/parent::tei:rs and starts-with($node, " ")
and not($node/preceding-sibling::*[1][self::tei:handShift])) then
and not($node/preceding-sibling::*[1][self::tei:handShift])
and simpleHelpers:is-trimming-necessary($node)) then
simpleHelpers:prepare-text(text{substring-after($node, " ")})
else
simpleHelpers:prepare-text($node)
......@@ -131,11 +132,6 @@ declare function fontaneSimple:transform($nodes as node()*, $uri as xs:string) a
(if($node/@type = "edited_text"
or $node/child::tei:seg[@type = "multiphrase"]) then
fontaneSimple:copy-element($node, $uri)
(: :)
(: else if($node[matches(@copyOf, $node/preceding::tei:seg/@xml:id):)
(: and not(@cause = "unclear")]) then:)
(: fontaneSimple:mark-intervention($node):)
else if($node/@cause = "unclear") then
()
......@@ -304,6 +300,16 @@ declare function fontaneSimple:transform($nodes as node()*, $uri as xs:string) a
$node/@type,
fontaneSimple:transform($node/node(), $uri)
}
else if($node/@type = "item") then
element {QName("http://www.tei-c.org/ns/1.0", $node/@type)} {
$node/(@xml:id, @subtype, @rendition, @prev, @next),
if($node/@rend) then
attribute rendition {$node/@rend}
else
(),
fontaneSimple:transform($node/node(), $uri)
}
else
fontaneSimple:transform($node/node(), $uri)
......@@ -509,7 +515,7 @@ declare function fontaneSimple:transform($nodes as node()*, $uri as xs:string) a
()
else if($node/@type = "toc") then
element {QName("http://www.tei-c.org/ns/1.0", "list")} {
element {QName("http://www.tei-c.org/ns/1.0", "div")} {
$node/(@type, @subtype),
fontaneSimple:transform($node/node(), $uri)
}
......@@ -541,13 +547,16 @@ declare function fontaneSimple:transform($nodes as node()*, $uri as xs:string) a
fontaneSimple:transform($node/node(), $uri)
else if($node/@xml:id) then
(if($node/@xml:id = "C06_14r_9") then
util:log-system-out($node)
else (),
element {QName("http://www.tei-c.org/ns/1.0", "seg")} {
$node/@xml:id,
$node/@prev,
$node/@next,
$node/@corresp,
fontaneSimple:transform($node/node(), $uri)
}
})
else
fontaneSimple:transform($node/node(), $uri)
......@@ -607,7 +616,7 @@ declare function fontaneSimple:transform($nodes as node()*, $uri as xs:string) a
$node/@*,
attribute href {tbleapi:get-url($uri, $node/@xml:id, "png")},
fontaneSimple:transform($node/node(), $uri)
}, util:log-system-out($node))
})
else
()
else
......@@ -654,7 +663,6 @@ declare function fontaneSimple:transform($nodes as node()*, $uri as xs:string) a
fontaneSimple:copy-element($node, $uri)
case element(tei:rs) return
let $bla := util:log-system-out($node)
let $index-type := substring-before($node/@ref, ":")
return
(: ignore tei:rs elements that are empty after presorting. this
......@@ -707,6 +715,10 @@ declare function fontaneSimple:transform($nodes as node()*, $uri as xs:string) a
: @return node() a copy of the current node
:)
declare function fontaneSimple:copy-element($node as node(), $uri as xs:string) as node() {
if($node[self::tei:note]) then
util:log-system-out($node)
else
(),
element {QName("http://www.tei-c.org/ns/1.0", $node/name())}{
$node/(@* except @rend),
if($node/@rend) then
......
......@@ -80,13 +80,14 @@ declare function simpleHelpers:prepare-text($node as text()) as text()? {
since we sometimes have cases where a hyphen is the only content of a
string. functx:substring-before-last would therefore produce an empty
string which leads to problems while preparing the text any further. :)
let $cleared-hyphen :=
let $cleared-end-hyphen :=
if(ends-with($node, "-") and not(simpleHelpers:keep-hyphen($node))) then
text {functx:substring-before-last($node, "-") || "@P"}
else if(ends-with($node, "⸗") and not(simpleHelpers:keep-hyphen($node))) then
text {functx:substring-before-last($node, "⸗") || "@P"}
else
replace($node, "⸗", "-")
let $cleared-hyphen := replace($cleared-end-hyphen, "⸗", "-")
let $cleared-round-s := replace($cleared-hyphen, "ſ", "s")
let $cleared-Tironian := replace($cleared-round-s, "⁊c.", "etc.")
(: let $normalized := normalize-space($cleared-round-s):)
......@@ -436,4 +437,17 @@ declare function simpleHelpers:assure-dir-available($dir-name as xs:string) {
()
else
xmldb:create-collection($config:app-root, $dir-name)
};
(:~ Checks if a text node that begins with a whitespace needs trimming at its
: start.
: :)
declare function simpleHelpers:is-trimming-necessary($text as text()) {
let $second-character := substring($text, 2, 2)
return
if(matches($second-character, "[A-Z(]")) then
false()
else
true()
};
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment