asciidoctor / asciidoctor-diagram

:left_right_arrow: Asciidoctor diagram extension, with support for AsciiToSVG, BlockDiag (BlockDiag, SeqDiag, ActDiag, NwDiag), Ditaa, Erd, GraphViz, Mermaid, Msc, PlantUML, Shaape, SvgBob, Syntrax, UMLet, Vega, Vega-Lite and WaveDrom.
http://asciidoctor.org
MIT License
431 stars 106 forks source link

Allow linking to source file for `svg-type=inline` #433

Closed KartikSoneji closed 10 months ago

KartikSoneji commented 10 months ago

Inline svgs are great but that doesn't provide access to the source svg. For example, right click > open in new tab to allow a focused view of only that image.

Can we add an option like svg-type=inline-linked that wraps the whole svg tag with <a href="image.svg" target="_blank"> that will open the image in a new tab when clicked?

I believe the changes will need to be made here: https://github.com/asciidoctor/asciidoctor-diagram/blob/2636028423f79b2411e25ef3d7aada7c720f63ef/lib/asciidoctor-diagram/diagram_processor.rb#L255-L265

pepijnve commented 10 months ago

I can add that in the diagram extension, but without support from the html5 backend it won't have much effect. Is this something the html5 backend already supports?

pepijnve commented 10 months ago

See https://docs.asciidoctor.org/asciidoc/latest/macros/image-svg/ for the available options

KartikSoneji commented 10 months ago

Is this something the html5 backend already supports?

I don't think it does. Maybe this should be a feature request to asciidoctor as well?

KartikSoneji commented 10 months ago

Something like opts=inline-linked here:

(source)

        if node.option? 'inline'
          img = (read_svg_contents node, target) || %(<span class="alt">#{node.alt}</span>)
        elsif node.option? 'interactive'
          fallback = (node.attr? 'fallback') ? %(<img src="#{node.image_uri node.attr 'fallback'}" alt="#{encode_attribute_value node.alt}"#{attrs}#{@void_element_slash}>) : %(<span class="alt">#{node.alt}</span>)
          img = %(<object type="image/svg+xml" data="#{src = node.image_uri target}"#{attrs}>#{fallback}</object>)
        else
          img = %(<img src="#{src = node.image_uri target}" alt="#{encode_attribute_value node.alt}"#{attrs}#{@void_element_slash}>)
mojavelinux commented 10 months ago

Self linking for images has been proposed and implemented. However, it's not yet available in a release. See https://github.com/asciidoctor/asciidoctor/issues/3656

KartikSoneji commented 10 months ago

That's great! Does that support inline images as well?

mojavelinux commented 10 months ago
pepijnve commented 10 months ago

Unless I'm mistaken this should just work out of the box since the diagram extension passes most attributes through to the generated block.

Edit: ah but 2.1.0 hasn't been release yet of course. Either way, I'm going to close this issue since it's something asciidoctor core should and will handle.

mojavelinux commented 10 months ago

Yes, once 2.1.0 is released. I recommend holding out for that release rather than changing Asciidoctor Diagram, as you suggested.