Commit 5257b92e authored by mrodzis's avatar mrodzis 🌿 Committed by Mathias Goebel
Browse files

Add a fix for Markdown parser error (closes #48)

parent c352a193
......@@ -116,10 +116,11 @@ declare function multiviewer:markdown($docpath as xs:string) as item()* {
let $inputDoc := util:binary-doc( $docpath )
let $input := util:binary-to-string($inputDoc)
let $markdown := markdown:parse($input)
let $fixed-markdown := multiviewer:fix-markdown($markdown)
return
<xhtml:div class="markdown">
{local:markdownTransform($markdown)}
{local:markdownTransform($fixed-markdown)}
</xhtml:div>
};
......@@ -137,7 +138,7 @@ declare function local:markdownTransform($nodes) {
for $node in $nodes
return
if( $node/local-name() = "h1" ) then
(: the typeswtich did not cast h1. :)
(: the typeswitch did not cast h1. :)
<xhtml:h2 class="block-header">
<xhtml:span class="title">{ $node/node() }</xhtml:span>
</xhtml:h2>
......@@ -198,3 +199,36 @@ declare function multiviewer:LEGACY-choose-xsl-and-transform($doc, $model as map
return $html
};
(:~
: This fix is necessary due to some bug in eXist's Markdown parser which doesn't
: display nested XML elements.
:
: Apart from that the parser also seems to have problems with XML elements that
: only include a text node.
: This function doesn't solve the second problem, but at least nested elements
: are displayed.
:
: @see https://gitlab.gwdg.de/SADE/SADE/issues/48
: :)
declare function multiviewer:fix-markdown($nodes as node()*) {
for $node in $nodes return
typeswitch ($node)
case text() return
$node
case element(pre) return
element {node-name($node)} {
$node/@*,
serialize($node/node())
=> replace("&amp;lt;", "<")
=> replace("&amp;gt;", ">")
=> replace("<(/){0,1}OBJECT>", "")
}
default return
element {node-name($node)} {
$node/@*,
multiviewer:fix-markdown($node/node())
}
};
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