kotlinx.html
kotlinx.html copied to clipboard
Unable to set namespaces
I'm not able to properly render an SVG tag, because it is not possible to include the xmlns:xlink="http://www.w3.org/1999/xlink" attribute. The library complains that this is not a valid attribute name.
Are you trying to render svg
root element or something else? svg {}
should set the namespace properly.
If you are using the 'use' element inside the svg, you have to specify the xlink namespace.
<svg width="100%" height="100%" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<g id="Port">
<circle style="fill:inherit" r="10"/>
</g>
</defs>
<text y="15">black</text>
<use x="50" y="10" xlink:href="#Port" />
</svg>
But I am not able to do this out of the box. Obviously, in the long run, there is likely a lot more to do to fully enable SVG support in this library (and I may end up submitting a pull for some of this functionality), but for now, allowing for the addition of this custom namespace is required.
I have a similar requirements. But in the root html tag.
<html t:type="Layout" title="Bot Crow"
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_4.xsd"
xmlns:p="tapestry:parameter">
</html>
need a custom namespace for xmlns:t and xmlns:p
I tried putting it as an attribute, but it gets rejected.
attributes["xmlns:t"] = "http://tapestry.apache.org/schema/tapestry_5_4.xsd"
attributes["xmlns:p"] = "tapestry:parameter"
Okay for now i'm using a workaround by using String.replace to replace the xmlns to xmlns:t.
I had a similar problem and needed to define two SVG graphics:
<svg xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" xmlns="http://www.w3.org/2000/svg" height="0" width="0" style="position: absolute;">
<defs>
<g id="folder" fill="none">
<path d="M285.22 37.55h-142.6L110.9 0H31.7C14.25 0 0 16.9 0 37.55v75.1h316.92V75.1c0-20.65-14.26-37.55-31.7-37.55z" fill="#FFA000"></path>
<path d="M285.22 36H31.7C14.25 36 0 50.28 0 67.74v158.7c0 17.47 14.26 31.75 31.7 31.75H285.2c17.44 0 31.7-14.3 31.7-31.75V67.75c0-17.47-14.26-31.75-31.7-31.75z" fill="#FFCA28"></path>
</g>
<g id="file" stroke="#000" stroke-width="25" fill="#FFF" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round">
<path d="M13 24.12v274.76c0 6.16 5.87 11.12 13.17 11.12H239c7.3 0 13.17-4.96 13.17-11.12V136.15S132.6 13 128.37 13H26.17C18.87 13 13 17.96 13 24.12z"></path>
<path d="M129.37 13L129 113.9c0 10.58 7.26 19.1 16.27 19.1H249L129.37 13z"></path>
</g>
</defs>
</svg>
Got the same problem. I want to create epub files which require two namespaces in the header:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ops="http://www.idpf.org/2007/ops" xml:lang="de">
Trying to set either ´xmlns:ops´ or ´xml:lang´ via the attributes map results in an error ´Tag html has invalid attribute name´.
Any way to set these two entries via the DSL?
@henningBunk use raw()
const val SVG = """
<svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" height="0" width="0" style="position: absolute;">
<defs>
.........
</defs>
</svg>
"""
body {
unsafe { raw(SVG) }
}
@XhstormR I don't get how this should work though since I will wrap my hardcoded string which represents the root element inside of the body which breaks the hierarchy. It should be the other way around. What am I missing?
Also I would have to write a lot of the html/xml myself that way, which isnt the point of a DSL.
I settled for a replacement method, but still wished it would be possible with the native DSL.
buildString {
appendLine("""<?xml version="1.0" encoding="UTF-8"?>""")
appendLine("""<!DOCTYPE html>""")
appendHTML().html(
namespace = "http://www.w3.org/1999/xhtml"
) {
attributes["placeholder"] = "replace"
...
}
}.replace(
"""placeholder="replace"""".toRegex(),
"""xmlns:ops="http://www.idpf.org/2007/ops" xml:lang="de""""
)