asciidoctor / kramdown-asciidoc

A kramdown extension for converting Markdown documents to AsciiDoc.
Other
207 stars 19 forks source link

Detect diagram type #76

Closed pomdtr closed 2 years ago

pomdtr commented 4 years ago

I use kramdoc as a converter to be able to transform markdown to pdf (Asciidoc is awesome, but our documentation generator only support markdown).

My current script looks like this:

#!/usr/bin/env sh
#This scripts require the installation of the ruby gems asciidoctor, asciidoctor-pdf, kramdoc and rouge

kramdoc "$1" -o - | asciidoctor-pdf -a "source-highlighter=rouge" -r rouge -o "${1%.*}.pdf" -

I would love to be able to also generate diagrams during the process, using asciidoctor-diagram.

Howerver, if i write in my markdown file :

```plantuml @startuml Alice --> Bob: Hello @enduml ```

It will be converted to

[source, plantuml]
----
@startuml
Alice --> Bob: Hello
@enduml
----

when this output would be more useful.

[plantuml]
----
@startuml
Alice --> Bob: Hello
@enduml
----
mojavelinux commented 4 years ago

That sounds like a great idea. I hadn't thought of that.

Would you be able to submit a pull request to implement it?

mojavelinux commented 3 years ago

There are so many diagram types, with more on the way, that maintaining a hard-coded list is not sustainable. What I would prefer is to make this an option. When this option is set, the converter will look for diagrams with those names and convert them to a block style in AsciiDoc. Better yet, the option can be a map so that the name in Markdown can be different than the name in AsciiDoc.

I propose the name of the option to be diagram_types. It would look like this:

diagram_types: { 'puml' => 'plantuml', 'mermaid' => 'mermaid' }

Anything not listed would be ignored. We can map this to the CLI option --diagram-types and it can have the form like: puml=plantuml,mermaid. Here we can use a shorthand if the name is the same in both cases.

mojavelinux commented 2 years ago

After giving this further thought, I'd like to use the option name diagram_languages instead of diagram_types. The focus is really on the language. Each language can support many diagram types. What we are doing is stealing languages away from becoming code blocks and turning them into diagram blocks. So the terminology fits better this way.

I propose supporting two languages by default, plantuml and mermaid. These languages can be overridden using the :diagram_languages API option or --diagram-languages CLI option. I think we should keep it simple to start and make these single values. If necessary, we can add name mapping in the future.