mikitex70 / plantuml-markdown

PlantUML plugin for Python-Markdown
BSD 2-Clause "Simplified" License
192 stars 55 forks source link

code blocks with plantuml example renders as an img element #45

Closed emmaindal closed 3 years ago

emmaindal commented 3 years ago

Hi,

I'm trying to include examples of plantuml syntax in code blocks and from version 3.1.3 and above this seems to be broken. Instead of render the example snippet it renders the generated img element.

V.3.1.2 Screen Shot 2020-08-03 at 3 20 55 PM

V.3.3.0 Screen Shot 2020-08-03 at 3 34 10 PM

The usage of code block snippet

Screen Shot 2020-08-03 at 4 46 00 PM

There may be another way to use plantuml examples in code blocks that I'm not aware of, feel free to point me in the right direction if so.

Thanks!

mikitex70 commented 3 years ago

What tool are you using, markdown_py, mkdocs, or some other? The fenced_code extension must be enabled (I suppose is already so) and you must change the plantuml plugin priority to be lower than 25 (the priority of fenced_code). For example, using the markdown_py create a config.yml with:

plantuml_markdown:
  priority: 24

then use markdown_py -x plantuml_markdown -c config.py infile.md > outfile.html For mkdocs the configuration goes in mkdocs.yml. Maybe I can modify the default priority to be 20, so this configuration will not be needed. Let me know if this solves your issue.

emmaindal commented 3 years ago

@mikitex70 Thanks for fast response. I'm using mkdocs.

I'll look more into it tomorrow but with this approach, the used syntax above, that actually should render a diagram will not work it seems like. Since the fenced code extension will always have higher priority and thereby render the plantuml snippet as a code block even though it should be rendered as a img. So yes, it will maybe solve the issue for the code block with the plantuml syntax example but it will also open up a new issue for one of the multiple syntax options that one can use.

Would it instead be possible to add a rendering check to this extension that doesn't render the img if it's wrapped by a code block or something similar?

mikitex70 commented 3 years ago

Hi @emmaindal, I can't detect if a diagram is wrapped inside another block because:

The correct way is to adjust the priority option to adapt processing to the used plugins, which is the method intoduced in markdown_py 3 to solve this kind of problems. I can lower the default priority from 30 (actual value) to 20 in the next release, as it make sense that fenced_block needs to be always processed before plantuml_markdown. In the meanwhile you can configure the priority option in the mkdocs plugin configuration using something like:

plugins:
    - plantuml_markdown:
        priority: 20
emmaindal commented 3 years ago

Hi @mikitex70 Thanks for your response. I understand, make sense.

I can confirm lower the priority works. But as mentioned above, this comes with a limitation (as far as I can see) of not being able to use one of the two syntax choices, the "GitLab/GitHub block syntax". This is the one I mainly use, so just need to switch out my diagrams to use the other one ::uml:: ::end-uml::. Might be good to include in any release notes.

I'll keep use the working version 3.1.2 until next release. Thank you!

mikitex70 commented 3 years ago

@emmaindal, can you give me a simple diagram example that isn't rendered correctly with the 3.3.0 release, even with lowered priority? Lowering the priority should fix rendering with the "GitLab/GitHub block syntax"; if so I will decrease the plantuml-markdown plugin priority so it works out of the box without configurations.

mikitex70 commented 3 years ago

Ok, I've found an example which does not work when the priority is lower than fenced_code. I will try to get all working. Thanks for reporting this issue.

mikitex70 commented 3 years ago

Hi @emmaindal , the new version 3.4.0 fixes the issue you reported. Thanks for pointing me to this defect.

emmaindal commented 3 years ago

Hi @mikitex70 Thank you for fixing this issue and even with keeping the option of using the "GitLab/GitHub block syntax", we will give it a try to upgrade to the new version and let you know if we run in to any other issues.

cmdkeen commented 3 years ago

This solution doesn't work if you have multiple fenced blocks on the page mixed in with uml blocks. The combination of _replace_block and the FENCED_CODE_RE regex means it will jump over any intermediate sections that match FENCED_BLOCK_RE.

Example: image

The middle inline block doesn't get picked up for processing because of the second fenced block being found first.

image

(This is a bit of an edge case, I can work around, and generally this library has been brilliant - keep up the good work!)

mikitex70 commented 3 years ago

Thanks @cmdkeen for reporting the issue. Now it should be fixed (at least it passes the test for this kind of error). Try with a pip install -U plantuml_markdown, it should download the 3.4.1 version.

cmdkeen commented 3 years ago

Thanks @mikitex70 for the quick turnaround - happy to confirm that I can no longer reproduce with 3.4.1

mschoettle commented 1 year ago

I am using plantuml-markdown in combination with mkdocs-material and had to wrap it in a code block with six backticks:

``````markdown
```plantuml
Alice -> Bob: Hi!
```
``````

I saw that somewhere but don't remember where it was.

mikitex70 commented 1 year ago

Hi @mschoettle, you must activate the fenced_code plugin to be able to wrap code blocks. From the command line use options like -x fencde_code -x plantuml_markdown, for mkdocs see the documentation. It is not necessary to use 6 backticks, it is enough to use 4 (the number of backticks of the plantuml code block plus 1).

mschoettle commented 1 year ago

fenced_code is already activated. You are correct, anything above 3 backticks works.