Skip to content

Commit

Permalink
remove svg:defs from individual diagrams (fixes #9)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuntherRademacher committed Jan 6, 2023
1 parent 2ad5244 commit f072af2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ plugins {
defaultTasks 'build'
build.dependsOn 'distZip'

version = '1.64'
version = '1.65'
group = 'de.bottlecaps.rr'
def buildTime = new Date()

Expand Down
3 changes: 1 addition & 2 deletions src/main/resources/de/bottlecaps/railroad/xq/ast-to-svg.xq
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,6 @@ declare function s:convert-to-svg($p as element(g:production), $page-width as xs
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="{$width + 1}" height="{$height + 1}">
<defs>{s:style($color, $spread)}</defs>
{
s:translate(1 - xs:integer($dimensions/@x1), 1 - xs:integer($dimensions/@y1), $rendered)
}
Expand Down Expand Up @@ -1297,7 +1296,7 @@ declare function s:combine-path($node)
if (not($node is $paths[last()])) then
()
else
element svg:path
element path
{
$node/@class,
attribute d
Expand Down
20 changes: 15 additions & 5 deletions src/main/resources/de/bottlecaps/railroad/xq/disassemble.xq
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ declare namespace xhtml="http://www.w3.org/1999/xhtml";
declare namespace xlink="http://www.w3.org/1999/xlink";
declare namespace xsl="http://www.w3.org/1999/XSL/Transform";

declare function d:file($name as xs:string, $content, $type)
declare function d:file($name as xs:string, $type, $content)
{
element file
{
Expand Down Expand Up @@ -37,7 +37,17 @@ declare function d:rewrite($nodes, $format, $hotspots as xs:boolean, $referenced
let $img-name := concat("diagram/", $name, ".", $format)
return
(
d:file($img-name, $node, "xml"),
d:file
(
$img-name,
"xml",
element {node-name($node)}
{
$node/@*,
$node/preceding::xhtml:head/svg:svg/svg:defs,
$node/node()
}
),
let $map-name := concat($name, ".map")
let $links := $node//svg:a
let $map :=
Expand Down Expand Up @@ -106,7 +116,7 @@ declare function d:rewrite($nodes, $format, $hotspots as xs:boolean, $referenced
attribute alt {$target}
}</area>
}</map>
return d:file($map-path, $mapfile, "xhtml")
return d:file($map-path, "xhtml", $mapfile)
),
if (not($referenced-by)) then
()
Expand All @@ -124,7 +134,7 @@ declare function d:rewrite($nodes, $format, $hotspots as xs:boolean, $referenced
let $referrer := data($a/@title)
return <li><a href="ref-{$referrer}.htm" title="{$referrer}">{$referrer}</a></li>
}</ul>
return d:file($referenced-by-path, $referenced-by, "xhtml")
return d:file($referenced-by-path, "xhtml", $referenced-by)
)
)
)
Expand Down Expand Up @@ -158,7 +168,7 @@ declare function d:disassemble($input, $format)
let $directive := $input//processing-instruction()[local-name() = "rr"]/tokenize(., "\s+")[.]
let $hotspots := $directive = "hotspots"
let $referenced-by := $directive = "referenced-by"
let $files := d:file("index.html", d:rewrite($input, $format, $hotspots, $referenced-by), "xml")
let $files := d:file("index.html", "xml", d:rewrite($input, $format, $hotspots, $referenced-by))
for $file in $files/descendant-or-self::file
order by lower-case($file/@name)
return element file {$file/@*, d:unnest($file/node())}
Expand Down
10 changes: 9 additions & 1 deletion src/main/resources/de/bottlecaps/railroad/xq/xhtml-to-md.xq
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@ declare function m:rewrite($nodes, $format, $referenced-by as xs:boolean)
else
string(count($node/preceding::svg:svg) + 1)
let $ebnf := string-join($node/following::xhtml:div[@class="ebnf"][1]/xhtml:code/*, "&#xA;")
let $img := concat("![", $name, "](data:image/svg+xml,", encode-for-uri(serialize($node, $m:serialization-options)), ")")
!replace(., "&#xA0;", " ")
let $svg :=
element {node-name($node)}
{
$node/@*,
$node/preceding::xhtml:head/svg:svg/svg:defs,
$node/node()
}
let $img := concat("![", $name, "](data:image/svg+xml,", encode-for-uri(serialize($svg, $m:serialization-options)), ")")
return
if (empty($node/following::svg:svg)) then
(
Expand Down

0 comments on commit f072af2

Please sign in to comment.