vliejo / gitbook-plugin-local-plantuml Goto Github PK
View Code? Open in Web Editor NEWGitbook plugin that renders plantuml images locally
License: Apache License 2.0
Gitbook plugin that renders plantuml images locally
License: Apache License 2.0
Hi vliejo,
I am Aleen (https://github.com/aleen42) , and the founder of GitBook Community in Google+: https://plus.google.com/communities/110696788983472771007, which aims to sharing books or plugins of GitBook, talking anything about it as well. Here I am sincerely inviting you to join us. ๐
Ideally, inaddition to this style of plantUML
{% plantuml %}
Class MyStage
Class Timeout {
+constructor:function(cfg)
+timeout:function(ctx)
+overdue:function(ctx)
+stage: Sage
+other_thing: Other Thing
}
Stage <|-- Timespent
{% endplantuml %}
You would be able to include this style
{% plantuml src='sage.puml' %}
{% endplantuml %}
File sage.puml
:
@startuml
Class MyStage
Class Timeout {
+constructor:function(cfg)
+timeout:function(ctx)
+overdue:function(ctx)
+stage: Sage
+other_thing: Other Thing
}
Stage <|-- Timespent
@enduml
This would allow for the use of Plant Uml editor tools that can auto-render PNGs while writing the pum l (I am looking at you, Intellij Plugins)
The text in a PlantUML "block" seems to be HTML escaped/encoded, so when the text is extracted from the block in the plugin, it is passed on to PlantUML changed from what was originally written.
It looks like the Gitbook framework automatically encodes the "block" text. This may not have happened for an ealier version of gitbook.
$ gitbook version
CLI version: 2.3.0
GitBook version: 3.2.0
If I write this in my .md document:
{% plantuml %}
Class MyStage
Class Timeout {
+constructor:function(cfg)
+timeout:function(ctx)
+overdue:function(ctx)
+stage: Sage
+other_thing: Other Thing
}
Stage <|-- Timespent
{% endplantuml %}
This plugin tries to render this text:
Class MyStage
Class Timeout {
+constructor:function\(cfg\)
+timeout:function\(ctx\)
+overdue:function\(ctx\)
+stage: Sage
+other\_thing: Other Thing
}
Stage <\|-- Timespent
The cause of issue is that for this text:
+constructor:function(cfg)
The block
object encodes the text (escaping parentheses, for example), and gives the plantuml.jar
this:
+constructor:function\(cfg\)
Similarly this Stage <\|-- Timespent
gets an html escape of the <
character to a <
and becomes Stage <\|-- Timespent
Here is the problematic section of code (from gitbook-plugin-local-plantuml/index.js
, lines 17-25):
module.exports = {
blocks: {
plantuml: {
process: function (block) {
var imageName = hashedImageName(block.body) + ".png";
this.log.debug("using tempDir ", os.tmpdir());
var imagePath = path.join(os.tmpdir(), imageName);
var umlText = block.body;
The line
var umlText = block.body;
gets text that is already escaped. As far as I can tell, the block
object does not contain any reference to the un-encoded text. It also does not contain any line-numbers, or any other way determine the text which generated the initial block.
The alternate Gitbook PlantUML plugin uses regexes to extract the text, which seems cumbersome, but might be the only way to get ahold of the unchanged text.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.