New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add preprocess support for PlantUML "!include" #75
Conversation
@Mogztter please review the first naive implementation ;) |
src/preprocess.js
Outdated
let vfs = context.vfs | ||
if (typeof vfs === 'undefined' || typeof vfs.read !== 'function') { | ||
vfs = require('./node-fs') | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will try to come up with a solution to hide this idiom
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still use this additionally with exists function
That's a good point but with your current implementation we do not resolve include recursively right? I mean we only resolve the first level of
And we should read PlantUML code to see how they prevent recursive include loop. |
Yes it's not implemented and is a hint for the future. I will add this feature and check how to prevent include loop. |
40f098f
to
145f606
Compare
8012cc4
to
99726cc
Compare
@Mogztter please review the changes :) |
Some tests related to "HTTP client / Adaptive mode" and "Conversion" are now failing and it looks not related to my last commit - i'm sure it worked some hours before ;) |
I've just released and published a new version of Kroki and some images are not exactly the same with the latest version. We need to update the expected output accordingly. |
@danyill just fixed the tests, please rebase on master. |
I've thought about some issues not yet adressed:
--> should we support |
Good catch! I wasn't even aware of these two directives 🤯
Yes, it's not documented but you can give it a try: http://www.plantuml.com/plantuml/uml/ZOz1ImCn48Nl-HLnlQnWDmezUQginwgbwbdIxD0Dp4x2p0JflpSkw2AYU7elWVUzDnjHprecD6UH0fO12gCTLRFSECV-hJj67SkX2718f43QXJIvVGoUX_GG8GEwVhtQeITzkTyw1WGluAvNL_N_jQyX7mcuoxN5djj-RJ-SCJjWITJcMMunUhcqpTOV09jg7hF6H1xj7KZWEB-Q2_E5QyEd-n5zXZ1ImdGy_G5wEed2rCei_sqtUy3lWtzTiI2MEPMm0HhgzUy0
it should be relatively easy, I think that an include directive is only valid if it starts with 0 or more spaces, otherwise it won't get processed. So, the following are valid
But the following are not:
Multi-line comments are more complex to handle because we will need to ignore content when we find
I think it should work, PlantUML will ignore/remove them. I will try to take some time this week to review this great contribution 👍 |
48a7c64
to
630d101
Compare
hm, i've tried all the files i've created for tests with original PlantUML and found that produces error:
no error:
That's should be easy to change... |
Done! |
Tested with original PlantUML and adapted requirement: |
Done! |
From my point of view the important Please review... |
Fixes asciidoctor#49 see: http://plantuml.com/en/preprocessing http://plantuml.com/en/commons implement and test: - [x] `!include local-file-path` (throw an error if file not found) - [x] `!include local-file-path-with-spaces` - [x] `!include ... # comment` - [x] `!include remote-file-url` (skip and warn if url not accessible) - [x] `!include <std/lib/path>` (skip and warn) - [x] `!include file!index` - [x] `!include file!id` - [x] `!includeurl url` (compatibility : same as `!include remote-file-url`) - [x] `!includesub id` (compatibility : includes `!startsub id ... !endsub`) - [x] recursive include - [x] cyclic include loop protection (throw an error if detected) - [x] remove block `/' ... '/` and line `' ... '` comments - [x] `!include_many local-file-or-url` (compatibility : same as normal `!include ...`) - [x] `!include_once local-file-or-url` (throw an error if file included multiple times) - [x] `!include local-file-path-or-url` if included file has `@startuml ... @enduml` block(s) it should include only first block (index 0)
I will probably checkout your branch tomorrow and carefully review the code 👀 |
7a95400
to
698e120
Compare
@anb0s Overall this is really good and I've made only a few tiny changes. The biggest change is that the preprocessor now preserves comments. I think it's important otherwise we will "lose" information if we want to use the encoded format (ie. the URL) as the "source of trust".
If you base directory is Let me know what you think. |
I've also thought first to preserve them, but then decided as not needed and easier to remove instead of "handle". So i'm fine with preserving comments 👍
Yes, that's also good to have it explicitly defined instead of expecting working directory be the same as base directory of the document.
Yes it looks like it's the current working directory if not defined.
I've reviewed the changes and it looks good to me. I can maybe try it tomorrow, but if all tests are green i'm fine with this 💯 Thank You! |
I've checked out the new version and it looks good to me! From my point of view it can be merged ;) |
Let's do this! |
Fixes #49
see:
http://plantuml.com/en/preprocessing
http://plantuml.com/en/commons
implement and test:
!include local-file-path
(throw an error if file not found)!include local-file-path-with-spaces
!include ... # comment
!include remote-file-url
(skip and warn if url not accessible)!include <std/lib/path>
(skip and warn)!include file!index
!include file!id
!includeurl url
(compatibility : same as!include remote-file-url
)!includesub id
(compatibility : includes!startsub id ... !endsub
)/' ... '/
and line' ... '
comments!include_many local-file-or-url
(compatibility : same as normal!include ...
)!include_once local-file-or-url
(throw an error if file included multiple times)!include local-file-path-or-url
if included file has@startuml ... @enduml
block(s) it should include only first block (index 0)