asciidoctor-reveal.js
asciidoctor-reveal.js copied to clipboard
Support inline option on SVG images
When rendering asciidoc to plain html I can do e.g. image::my-image.svg[opts=inline] and it would inline the image into the resulting html.
Is is possible to do so with asciidoctor-reveal.js.
Cheers, Mario :)
I guess it misses conditions in this template to support this feature:
https://github.com/asciidoctor/asciidoctor-reveal.js/blob/acb2247380fe70e51dadcbb71568e2902d8865ce/templates/image.html.slim#L15-L19
For the sake of justifying the need behind this issue, with inline SVG it is possible to interact with the content of the SVG (eg. links, animation, scripting, etc). It is actually well explained in asciidoctor documentation.
This feature would open new possibilities for even better presentations with asciidoctor-reveal.js 😀
Thanks for the issue. I was very confused I'd done something wrong. If this could further be defined globally for a document - that'd be quite handy
@rezib
This feature would open new possibilities for even better presentations with asciidoctor-reveal.js
I totally agree, I think this is the mosst hurdle since I often mail my presentations - now I need to publish them all the time.
Cheers, Mario :)
If someone stil encounters the issue, there is a possible hack done the following way
- Add the
role=svgto each generated svg diagram. This will add thesvghtml class to the image container div (well, provided you use a block image, but I guess you did) - Create a footer docinfo file
- In that footer docinfo file, add the following javascript
<script>
function replaceSVGImagesTags() {
// We add the svg role in asciidoc document to SVG images.
// This is in fact added to container div.
// So we locate those container div contained images to replace them
// Hopefully modern JS has a pseudo-CSS syntax for that
const svgImages = document.querySelectorAll("div.svg img")
// Now let's browse those images and change their content
svgImages.forEach(img => {
const src = img.getAttribute("src")
console.info("replacing image having source ", src)
const parent = img.parentElement
parent.removeChild(img)
// Now create an object which data is the given src
fetch(src)
.then(response => response.text())
.then(responseText => new window.DOMParser().parseFromString(responseText, "text/xml"))
.then(responseXML => parent.appendChild(responseXML.rootElement));
})
}
replaceSVGImagesTags()
</script>
- In your presentation stylesheet, don't forget to add
div.svg { font-size: initial }otherwise your font will render weirdly.
With these modifications, your image diagrams will all be inlined as direct SVG tags. This allow more interactivity, and ability to select individual SVG elements
The relevant code in the built-in HTML5 converter: https://github.com/asciidoctor/asciidoctor/blob/a040b60300efaa0d75cc6a3b031241dbe7b5a864/lib/asciidoctor/converter/html5.rb#L1214-L1220
It seems that we can reuse read_svg_contents .
Let's do it. If you need me to lend a hand, just call on me.
@obilodeau @ggrossetie ping. Please merge the PR if u agree.