-
Notifications
You must be signed in to change notification settings - Fork 138
Add support for PlantUML diagrams #887
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
Conversation
Does your current implementation require the user to already have Java installed? If so it might be problematic to impose installing a JRE / JDK to use this feature. Having looked through <plantuml>
Bob->Alice : hello
</plantuml> Page.prototype.generatePlantuml = function (content) {
const $ = cheerio.load(content);
const plantumlContent = $("plantuml");
...
...
}
Build times is not really a concern (unless it is a significant increase). You should take note on how it affects previewing websites for authors. Manually recording some timings on a test page with different number of diagrams & other components can be a good gauge if it is problematic. Other comments:
Although not fully tested, this seems like it is a great feature addition as I can place the plantuml diagrams within MarkBind components. |
Yeah, PlantUML is supplied as a JAR, there's no way around it. node-plantuml is also a wrapper that runs the JAR which offers an abstracted API.
Currently I'm using markdown-it to parse since it's more convenient. But I think I'll try using cheerio and see if its better. My reservation for not using node-plantuml is because all the extra features are unnecessary, and it presents another potential source of errors. But now I'm encountering a new problem where certain symbols within the PlantUML language are misinterpreted as HTML tags. For now I'll try using cheerio instead and see if it solves this problem |
d1804f6
to
099093b
Compare
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.
Other Comments
- The
.puml
files do not end with an empty line. Might want to change it such that parsers will know that is the EOF? (and have Github stop complaining about it) - The
graphviz not found
bug is fixed after installing the stable version of graphviz 2.38.
// Read diagram file | ||
fs.readFile(src, (err, data) => { | ||
if (err) { | ||
throw err; |
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.
We should log the error with a meaningful message, and continue to generate the website.
Throwing the error would stop the parsing entirely, requiring the user to debug the verbose error on their own.
Since you used error
below, you should use it here instead of err
for consistency.
Likewise for all error catching code below, we should be able to fail gracefully with a meaningful message. Since we can just not generate this specific plant-uml
diagram and continue with parsing.
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.
Ok, good point
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.
As discussed in person:
- Unable to share the same error names as the same name was defined in a higher scope. So we decided to move the verbose error message to the logger file and print out a more meaningful message on the console.
const diagramSrc = src.replace('.puml', '.png'); | ||
const rawDiagramPath = path.resolve(path.dirname(sourcePath), src); | ||
const outputFilePath = path.resolve(rootPath, '_site', path.relative(rootPath, rawDiagramPath)).replace('.puml', '.png'); | ||
// const outputFilePath = path.resolve(diagramSrc); |
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.
Since this PR is still [WIP], remember to remove redundant comments + console logging code below.
try { | ||
fs.mkdirSync(outputDir, { recursive: true }); | ||
// eslint-disable-next-line no-empty | ||
} catch (_e) {} |
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.
Is there a reason to catch this error but not throw it?
@@ -7,6 +7,7 @@ | |||
* [Adding Pages]({{baseUrl}}/userGuide/addingPages.html) | |||
* [MarkBind Syntax Overview]({{baseUrl}}/userGuide/markBindSyntaxOverview.html) | |||
* [Formatting Contents]({{baseUrl}}/userGuide/formattingContents.html) | |||
* [UML]({{baseUrl}}/userGuide/puml.html) |
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.
Inserting PlantUML Diagrams
?
docs/userGuide/puml.md
Outdated
|
||
<span id="overview" class="lead"> | ||
|
||
**MarkBind offers integration with PlantUML in your pages,** allowing you design and write UML diagrams (and more) using PlantUML syntax, which is then compiled and served as images. |
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.
- Add a newline after the bold text?
(and more)
should naturally link to other examples- You should put a warning at the top of this page indicating that authors need to have a JRE/JDK installed, along with the graphviz installer to use this feature.
## PlantUML Test | ||
|
||
### Sequence Diagram | ||
<puml src="diagrams/sequence.puml" /> |
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.
When I generate this page, the src
will be changed to test_site/diagrams/abc.png
when the correct one should be without test_site
.
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.
Seems to be an issue with the <pic>
component, will look into it
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.
For the graceful error handling, there is room for some improvement:
- All errors that result in the diagram not being generated should return immediately.
- All errors should be logged in
logger.debug
, not just replaced with a generic error message. - We should only show 1
logger.error
per diagram (to reduce clutter).
Example
if (criticalErr1) {
logger.debug(criticalErr1);
logger.error("Tell user something went wrong");
return;
}
if (nonCriticalError1) {
logger.debug(nonCriticalError1);
}
if (nonCriticalError2) {
logger.debug(nonCriticalError2);
}
if (criticalError2) {
logger.debug(criticalError2);
logger.error("Tell user smth went wrong);
return;
}
This would ensure we only get 1 console error message per diagram, and all errors that occurred up until the critical error is logged properly.
Use Github's 'draft PR' feature instead of |
Currently it already does this. There are 2 main locations where errors occur - reading the .puml, and running the jar. If an error occurs during the read, the error is logged and the jar is not run. If an error occurs while running the jar, either the |
@damithc there are some issues with Github's draft PR feature, namely not being able to revert back to it or retroactively mark an opened PR as draft |
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.
Other comments:
- You have not initialised the
diagrams
folder within_markbind
duringmarkbind init
. You also have to update theSite.test.js
code since an additional folder is expected on initialisation. All sharable assets between pages (such assite-nav
) should be in the_markbind
folder. - Good that you tried to reduce duplicate processing for the same diagrams using Sets.
docs/userGuide/puml.md
Outdated
|
||
**[Graphviz](https://www.graphviz.org/download/) must be installed to generate diagrams**, with the exception of sequence and activity diagrams. (_tested with v2.38_) | ||
**[<tooltip content="Tested with v2.38">Graphviz</tooltip>](https://www.graphviz.org/download/) must be installed to generate <tooltip content="with the exception of sequence and activity diagrams">diagrams</tooltip>** |
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.
Will there be a case where activity and sequence diagrams don't work if they used a certain syntax for another component (without Graphviz) ?
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.
Honestly, I don't know. What do you mean by a certain syntax for another component?
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.
On a separate note, use tooltips only in cases where you want to supply a definition/explanation of a term. Otherwise, the reader will have to retrieve every tooltip to see if there is something relevant in the tooltip. Use dimmed text to provide unimportant details.
recent version
is not precise enough. Say something like version 8 or later
.
docs/userGuide/puml.md
Outdated
@@ -15,11 +15,11 @@ | |||
|
|||
<box type="warning"> | |||
|
|||
**[Java](https://www.java.com/en/download/) must be installed to use this feature** | |||
**[Java](https://www.java.com/en/download/) must be installed to use this feature**. _(Any recent version should work)_ |
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.
How about "Java must be installed to generate the UML diagrams via a JAR executable"?
To inform the user why is it needed.
docs/userGuide/puml.md
Outdated
</box> | ||
<box type="warning"> | ||
|
||
**[Graphviz](https://www.graphviz.org/download/) must be installed to generate diagrams**, with the exception of sequence and activity diagrams | ||
**[Graphviz](https://www.graphviz.org/download/) must be installed to generate diagrams**, with the exception of sequence and activity diagrams. (_tested with v2.38_) |
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.
"... to generate all PlantUML diagrams"?
The diagram files can be in any folder, not necessarily restricted to the |
@Chng-Zhi-Xuan @damithc I've rephrased the requirements section |
@alyip98 You have not addressed the request above. In addition, since all the diagrams are in <!-- src will search starting from "_markbind/diagrams" -->
<puml src="abc.puml"> |
As discussed in person, since |
Markbind page authors can use diagrams in their sites by linking them in a `<pic>` tag. This is tedious as it requires the author to generate the diagrams using an external tool, and the binary files generated by that tool (e.g. .pptx, .psd) are not version control friendly. Let's support PlantUML, a tool that allows users to write diagrams in a simple and intuitive language. Users can then write their diagrams in a text editor, and Markbind will generate the diagrams using PlantUML, eliminating the need of an external editor.
What is the purpose of this pull request? (put "X" next to an item, remove the rest)
• [x] New feature
Resolves #877
What is the rationale for this request?
PlantUML is a tool written in Java that allows users to write diagrams in a simple and intuitive language. Being able to write (and track) UML diagrams in a text format compared to using tools such as Powerpoint or Photoshop allows better version control and ease of use.
What changes did you make? (Give an overview)
Add ability to include UML diagrams via a
<puml>
tag. The diagram itself is written in PlantUML syntax in a separate file. The page includes the diagram using the following syntax:<puml src="diagrams/example.puml"/>
Is there anything you'd like reviewers to focus on?
Due to limitations of htmlparser2, including UML code inline will cause problems as UML syntax violates HTML specifications (e.g. presence of symbols such as
<--
which are misinterpreted as HTML tags). Fixing this will require cheerio to use a forked version of htmlparser2, discussed in #582, which in itself is an open problem.Testing instructions:
The user guide contains an entry
Proposed commit message: (wrap lines at 72 characters)
Markbind page authors can use diagrams in their sites by linking them
in a
<pic>
tag. This is tedious as it requires the author to generatethe diagrams using an external tool, and the binary files generated by
that tool (e.g. .pptx, .psd) are not version control friendly.
Let's support PlantUML, a tool that allows users to write diagrams in
a simple and intuitive language. Users can then write their diagrams
in a text editor, and Markbind will generate the diagrams using
PlantUML, eliminating the need of an external editor.