oxygenxml / dita-ot-diagrams-plugin

Dynamically convert PlantUML content inside DITA topics to SVG
Apache License 2.0
9 stars 3 forks source link

Feature Request: accept markdown format like this: ```mermaid (also plantuml in the similar format) #13

Open SmartLayer opened 1 year ago

SmartLayer commented 1 year ago

I am unsure whether this request should be filed with https://github.com/vsch/flexmark-java or this project. The feature requested is to enable support for Mermaid, and PlantUML in the github/gitlab format.

Sample PlantUML/Kroki/Mermaid codes can be found in this gitlab link.

This request is not because I dislike the <foreign> tag, but rather because having the ability to render diagrams on github/gitlab is crucial for workflows based on their features.

For comparison, examples of using <foreign> versus using the github format are here:

Using github format: https://github.com/TokenScript/documents/blob/6604b1453c7845ddf84aa475928a261290c56893/src/usecase/guide/air.cab.md#instantiation-process

Using <foreign> format: https://github.com/TokenScript/documents/blob/50d775de825502a2a42f6a0da7115ebc5c152a73/src/usecase/guide/air.cab.md#instantiation-process

raducoravu commented 1 year ago

This particular "dita-ot-diagrams-plugin" plugin adds xslt processing which matches the DITA XML "foreign" element with various output class values and produces the diagrams from it.

When you have Markdown content referenced in a DITA Map, the DITA Open Toolkit has a pre-installed plugin: https://github.com/jelovirt/org.lwdita The job of this "org.lwdita" plugin is to dynamically convert Markdown to DITA XML content while publishing. It uses the Flexmark engine to accomplish this. So my "dita-ot-diagrams-plugin" plugin applies its processing later on in the publishing stage, when the Markdown has been converted to DITA XML by the "org.lwdita".

I tried this experiment: 1) Created a DITA Map which refers to a Markdown file containing a small Plantuml graph inside in Markdown format:

        # Title

        Text
        ```plantuml
        Alice -> Bob: Authentication Request
        Bob --> Alice: Authentication Response

        Alice -> Bob: Another authentication Request
        Alice <-- Bob: Another authentication Response
        ```

2) Published the DITA Map to HTML5 setting the "clean.temp=no" parameter. 3) After publishing I looked in the transformation temporary files folder and the original Markdown file was converted to this:

        <topic ...>
            <title..>Title</title..>
            <body ..>
                <p ..>Text</p>
                <codeblock class="+ topic/pre pr-d/codeblock " xml:space="preserve" outputclass="plantuml" ...>Alice -&gt; Bob: Authentication Request
        Bob --&gt; Alice: Authentication Response

        Alice -&gt; Bob: Another authentication Request
        Alice &lt;-- Bob: Another authentication Response</codeblock>
            </body>
        </topic>

So the "org.lwdita" plugin converts the plantuml embedded content to a DITA XML codeblock with a certain @outputclass attribute value. But my plugin matches "foreign" with a certain @outputclass value. So maybe the XSLT templates in my plugin can be made more flexible like:

https://github.com/oxygenxml/dita-ot-diagrams-plugin/blob/master/com.oxygenxml.diagrams.svg/xsl/xhtmlSVG.xsl

 <xsl:template match="*[contains(@class, ' topic/foreign ')][contains(@outputclass, 'embed-plant-uml')] | *[contains(@class, ' topic/plant-uml ')]" priority="10">

could be replaced with:

  <xsl:template match="*[contains(@class, ' topic/foreign ')][contains(@outputclass, 'embed-plant-uml')] | *[contains(@class, ' topic/plant-uml ')] | *[contains(@class, ' pr-d/codeblock ')][contains(@outputclass, 'plantuml')]" priority="10">

so that it also matches codeblocks with a certain outputclass value. Maybe you can experiment with this and open a pull request if it works for you.