diff options
author | Felix Krause <contact@flyx.org> | 2016-02-02 20:20:59 +0100 |
---|---|---|
committer | Felix Krause <contact@flyx.org> | 2016-02-02 20:20:59 +0100 |
commit | facd4c6f19190f061ad4db9e8ab37c347b31b105 (patch) | |
tree | 197fe467369bf934047ea4cf98a90a123a388185 /lib/packages | |
parent | ac1e7a245093bb28a1a366f1e169ab50e6660c94 (diff) | |
download | Nim-facd4c6f19190f061ad4db9e8ab37c347b31b105.tar.gz |
RST: Output <object> for SVG images in HTML
Diffstat (limited to 'lib/packages')
-rw-r--r-- | lib/packages/docutils/rstgen.nim | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/lib/packages/docutils/rstgen.nim b/lib/packages/docutils/rstgen.nim index 22d944597..602f03328 100644 --- a/lib/packages/docutils/rstgen.nim +++ b/lib/packages/docutils/rstgen.nim @@ -757,10 +757,15 @@ proc renderImage(d: PDoc, n: PRstNode, result: var string) = template valid(s): expr = s.len > 0 and allCharsInSet(s, {'.','/',':','%','_','\\','\128'..'\xFF'} + Digits + Letters + WhiteSpace) - - var options = "" + let + arg = getArgument(n) + isObject = arg.toLower().endsWith(".svg") + var + options = "" + content = "" var s = getFieldValue(n, "scale") - if s.valid: dispA(d.target, options, " scale=\"$1\"", " scale=$1", [strip(s)]) + if s.valid: dispA(d.target, options, if isObject: "" else: " scale=\"$1\"", + " scale=$1", [strip(s)]) s = getFieldValue(n, "height") if s.valid: dispA(d.target, options, " height=\"$1\"", " height=$1", [strip(s)]) @@ -769,16 +774,21 @@ proc renderImage(d: PDoc, n: PRstNode, result: var string) = if s.valid: dispA(d.target, options, " width=\"$1\"", " width=$1", [strip(s)]) s = getFieldValue(n, "alt") - if s.valid: dispA(d.target, options, " alt=\"$1\"", "", [strip(s)]) + if s.valid: + # <object> displays its content if it cannot render the image + if isObject: dispA(d.target, content, "$1", "", [strip(s)]) + else: dispA(d.target, options, " alt=\"$1\"", "", [strip(s)]) s = getFieldValue(n, "align") if s.valid: dispA(d.target, options, " align=\"$1\"", "", [strip(s)]) if options.len > 0: options = dispF(d.target, "$1", "[$1]", [options]) - - let arg = getArgument(n) + if arg.valid: - dispA(d.target, result, "<img src=\"$1\"$2 />", "\\includegraphics$2{$1}", + let htmlOut = if isObject: + "<object data=\"$1\" type=\"image/svg+xml\"$2 >" & content & "</object>" + else: "<img src=\"$1\"$2 />" + dispA(d.target, result, htmlOut, "\\includegraphics$2{$1}", [arg, options]) if len(n) >= 3: renderRstToOut(d, n.sons[2], result) |