mikitex70 / plantuml-markdown

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

Support for sourcing plantuml code in another file? #42

Closed jcravi closed 4 years ago

jcravi commented 4 years ago

Most editors like Intellij and vs code have plugins for locally rendering .puml files, side by side with the code. This allows creating the plantuml diagram while viewing the output simultaneously.

Would you be open to supporting an additional parameter that can take in a source? I sort of got this working locally, but I am not too familiar with Python, so the code is very hacky...

mikitex70 commented 4 years ago

Yes... maybe interesting and I understand the use case. One solution maybe to define in markdown a simple diagram with an include statement (already supported by PlantUML, no code change); this should work when using local PlantUML binary. When using a PlantUML service is not so easy: maybe we could use an option to set the source filename, which will be resolved relative to markdown file path.

jcravi commented 4 years ago

Here's my initial take. https://github.com/mikitex70/plantuml-markdown/pull/43

I was not sure how to get the location of the current file we are dealing with. Also, I was not able to figure out how to first check source and base_dir.

mikitex70 commented 4 years ago

Thanks for your pull request. I've made a small change to let code a bit more readable. I've also added a test to check the diagram inclusion. The code is in the develop branch: give it a try, so I can release it in the master branch.

jcravi commented 4 years ago

Thanks for the quick turnaround! Will test it out!

jcravi commented 4 years ago

Okay, it works. I had to change how I was passing the source value. Initially I was passing source="/dir/abc.puml", since I was doing string concatenation. I changed it to source="dir/abc.puml" and it worked correctly. I do not know if this is common knowledge or it needs to be mentioned in the docs explicitly.

mikitex70 commented 4 years ago

I've used a os.path.join to concatenate path and source, so it works also on Windows. The documentation says that base_dir is a directory where to search files to include, so I think it is sufficiently clear. But I'm open to suggestions.

jcravi commented 4 years ago

Oh, I'm on board with your change. Sorry if that wasn't clear. I was just asking if it makes sense to add any documentation to specify that the source= value follows certain rules.

jcravi commented 4 years ago

To be precise, the reason I am mentioning this is that when I used source="/dir/abc.puml" and base_dir of ., os.path.join('.','/dir/abc.puml') gives the output as /dir/abc.puml, and not ./dir/abc.puml, which is what I expected.

mikitex70 commented 4 years ago

Yes, you are right, but I think gives you more flexibility:

If simply concatenating strings, it would be impossible (with the original code) to access files outside markdown sources directory.

mikitex70 commented 4 years ago

I've released your contribution in version 3.3.0. Thanks for your work.

jcravi commented 4 years ago

You are welcome. Thanks for the library and the fast turnaround!

itopaloglu83 commented 3 years ago

Is is possible to include a source file but also not ignore the inline code?

I'm trying to locally include a theme but PlantUML !include doesn't work with the remote server option.