Coder Social home page Coder Social logo

vowstar / gitbook-plugin-uml Goto Github PK

View Code? Open in Web Editor NEW
32.0 5.0 14.0 1.22 MB

PlantUml plugin of gitbook/honkit which can draw UML graph in both markdown HTML and PDF

License: Apache License 2.0

JavaScript 100.00%
honkit plantuml gitbook honkit-plugin

gitbook-plugin-uml's Introduction

gitbook-plugin-uml

Build Status Coverage Status NPM Version NPM Downloads

PlantUml Plugin for Honkit and GitBook.

This is a sample plugin for GitBook Honkit and is specially adapted for GitBook Honkit from PlantUML. Gitbook Honkit PlantUml plugin is used to select from markdown uml and converting it into a picture format svg.

Installation

Install honkit instead of gitbook-cli(deprecated).

Install JRE or JDK please. Ensure your system have java.

It will download plantuml jar file automatically, so in some country and region you must install it behind a proxy, or it will download fail.

Gitbook PlantUml plugin can be installed from NPM using:

npm install gitbook-plugin-uml

Add this plugin into book.json.

{
  "plugins": ["uml"]
}

FAQ

Important:

** Please ensure your system have java!!! Or this plugin may not work, and get Error: spawn java ENOENT

** It will download plantuml jar file automatically, so in some country and region you must install it behind a proxy, or it will download fail.

Features

  • Support HTML, PDF, EPUB output(make sure your gitbook support SVG)
  • Support ```flow code block quote
  • Multi code style support

Beautiful UML

ARCHIMATE

WAVEFORM

How to use it

To include a PlantUML diagram, just wrap your definition in a "uml" code block. For example:

UML

Text format uml:

```uml
@startuml

	Class Stage
	Class Timeout {
		+constructor:function(cfg)
		+timeout:function(ctx)
		+overdue:function(ctx)
		+stage: Stage
	}
 	Stage <|-- Timeout

@enduml
```

And what's more, puml and plantuml code block also OK.

```puml
@startuml

	Class Stage
	Class Timeout {
		+constructor:function(cfg)
		+timeout:function(ctx)
		+overdue:function(ctx)
		+stage: Stage
	}
 	Stage <|-- Timeout

@enduml
```

Also you can put in your book block as

{% uml %}
@startuml

	Class Stage
	Class Timeout {
		+constructor:function(cfg)
		+timeout:function(ctx)
		+overdue:function(ctx)
		+stage: Stage
	}
 	Stage &lt;|-- Timeout

@enduml
{% enduml %}

The block syntax also allows for a src attribute to import an external PlantUml file.

{% uml src="test.plantuml" %}{% enduml %}

Of course, you can also pass the parameters like this.

```puml { src="test.plantuml" }
```

Configuration

book.json add the uml options

Configure plugin in book.json.

"pluginsConfig": {
  "uml": {
    "format": "png",
    "nailgun": false
  }
}

Build and serve

This plugin only works in your local machine. You need to play with local gitbook (command-line tool) to pre-compile all uml images.

gitbook serve yourbook

or

gitbook build yourbook

Additional requirements

For Mac OS X users. Install graphviz package.

brew install graphviz

For Linux users, Install graphviz package.

sudo apt install graphviz
sudo yum install graphviz

Debian/Ubuntu users may need install default-jre prevent Error: spawn java ENOENT.

sudo apt-get install default-jre

Thanks

This plugin original from lyhcode/gitbook-plugin-plantuml

See also

These plugins are also available on honkit.

Plugin Description
gitbook-plugin-uml A plug-in that use plantuml to draw beautiful pictures
gitbook-plugin-wavedrom A plug-in that can draw waveforms and register tables
gitbook-plugin-sequence A plug-in that can draw sequence diagrams
gitbook-plugin-flow A plug-in that can draw flowchart.js diagrams
gitbook-plugin-echarts A plug-in that can draw various charts such as bar/pie

gitbook-plugin-uml's People

Contributors

avenue68 avatar dependabot[bot] avatar gislik avatar hirocaster avatar kntmr avatar koppor avatar ronesam avatar sidiandi avatar stasson avatar tsuyoshicho avatar vowstar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

gitbook-plugin-uml's Issues

honkit shows "Could not find the language 'uml'"

Problem

Honkit shows following error if you write markdown code block with language uml / puml / plantuml inserting spaces between ``` and uml / puml / plantuml

could not find the language 'uml', did you forget to load/include a language module?
Error: Unknown language: "uml"

Reproduce process

Building following code reproduces the problem

``` uml
@startuml
actor -> (usecase)
@enduml
```

Plugin is not working with [!include] directive

In our documentation build system we are using Honkit with your plugin.
We tried to use [!include] directive
The files we tested are as follows.

test.md

@startuml
!include test.pu
@enduml

test.pu

@startuml
interface List
List : int size()
List : void clear()
List <|.. ArrayList
@enduml

The generated svg resulted in an error.
934c2c1d74a0fa88cde5f9c34e56afddace63269

I wonder if you still support this plugin and could fix this issue. Or could give us a tip how to fix it.

Ebook generate error occur in current HonKit

see honkit/honkit#142 (comment)

Probably, gitbook-plugin-uml generate *.svg on finish:before.
However, HonKit copy resources on generateAssets.

There seems to be a plan to fix it as follows.

Generate *.svg on page:before and it will fix this issue?

Either way, it seems that the timing must be before generateAssets.

Plugin is not working with relative paths

In our documentation build system we are using Gitbook with your plugin.

Most of the time we worked with embedded UML, which worked as a charm.
Recently we tried to use this approach:

{% uml src="test.plantuml"%}{% enduml %}

and Gitbook failed with the Error: ENOENT: no such file or directory, open 'test.plantuml' which is strange cause file was in the same folder as markdown that used it.

After short investigation I realized that plugin is trying to find this file not in the same folder with markdown file, but in the root of Gitbook working directory. Which is wrong, in my understanding, and changes the standard way of attaching assets in Gitbook.

I wonder if you still support this plugin and could fix this issue. Or could give us a tip how to fix it.

[Bug] Unable to install and bulid the plugin in macos

When I first typed

gitbook install

I got

➜  pedia git:(refactor_tmp) ✗ gitbook install
info: installing 4 plugins using [email protected] 
info:  
info: installing plugin "uml" 
info: install plugin "uml" (*) from NPM with version 1.0.1 
internal/child_process.js:345
    throw errnoException(err, 'spawn');
    ^

Error: spawn E2BIG
    at ChildProcess.spawn (internal/child_process.js:345:11)
    at exports.spawn (child_process.js:521:9)
    at spawn (/Users/lei.wang1/.gitbook/versions/3.2.3/node_modules/npm/lib/utils/spawn.js:7:13)
    at runCmd_ (/Users/lei.wang1/.gitbook/versions/3.2.3/node_modules/npm/lib/utils/lifecycle.js:237:14)
    at runCmd (/Users/lei.wang1/.gitbook/versions/3.2.3/node_modules/npm/lib/utils/lifecycle.js:196:5)
    at runPackageLifecycle (/Users/lei.wang1/.gitbook/versions/3.2.3/node_modules/npm/lib/utils/lifecycle.js:160:3)
    at Array.<anonymous> (/Users/lei.wang1/.gitbook/versions/3.2.3/node_modules/npm/node_modules/slide/lib/bind-actor.js:15:8)
    at LOOP (/Users/lei.wang1/.gitbook/versions/3.2.3/node_modules/npm/node_modules/slide/lib/chain.js:15:14)
    at chain (/Users/lei.wang1/.gitbook/versions/3.2.3/node_modules/npm/node_modules/slide/lib/chain.js:20:5)
    at lifecycle_ (/Users/lei.wang1/.gitbook/versions/3.2.3/node_modules/npm/lib/utils/lifecycle.js:131:3)

after I triggered the command the second time, the error gone. However I got another eror when build pages:

gitbook build ./ --log=debug --debug

➜  pedia git:(refactor_tmp) ✗ gitbook build ./ --log=debug --debug
debug: readme found at README.md 
debug: summary file found at SUMMARY.md 
debug: cleanup folder "/Users/lei.wang1/Github/mold/pedia/_book" 
info: 11 plugins are installed 
info: 10 explicitly listed 
info: loading plugin "uml"... ERROR

PluginError: Error with plugin "uml": Cannot find module 'safe-buffer'
PluginError: Error with plugin "uml": Cannot find module 'safe-buffer'
    at createError (/Users/lei.wang1/.gitbook/versions/3.2.3/node_modules/error/typed.js:31:22)
    at new createError (/Users/lei.wang1/.gitbook/versions/3.2.3/node_modules/error/wrapped.js:88:19)
    at /Users/lei.wang1/.gitbook/versions/3.2.3/lib/plugins/loadPlugin.js:67:23
    at _fulfilled (/Users/lei.wang1/.gitbook/versions/3.2.3/node_modules/q/q.js:834:54)
    at /Users/lei.wang1/.gitbook/versions/3.2.3/node_modules/q/q.js:863:30
    at Promise.promise.promiseDispatch (/Users/lei.wang1/.gitbook/versions/3.2.3/node_modules/q/q.js:796:13)
    at /Users/lei.wang1/.gitbook/versions/3.2.3/node_modules/q/q.js:857:14
    at runSingle (/Users/lei.wang1/.gitbook/versions/3.2.3/node_modules/q/q.js:137:13)
    at flush (/Users/lei.wang1/.gitbook/versions/3.2.3/node_modules/q/q.js:125:13)
    at process._tickCallback (internal/process/next_tick.js:172:11)

Here my gitbook version:

➜  pedia git:(refactor_tmp) ✗ gitbook --version
CLI version: 2.3.0
GitBook version: 3.2.3

MacOS latest
Node latest

The uml is v 1.0.1

All UML image are broken for executing `npm run serve` twice.

Problem

UML diagrams are not shown (seems as broken link) on localhost serving (http://localhost:4000/) by npx honkit serve.
This is happen at the second time to run npx honkit serve, without deleting any generated directories or files.

Reproduce process

In the root dir of some Honkit's contents repository, emulating a "just after cloning" condition.

$ git clean -f
$ npm install
$ npx honkit serve

No problem is found until here. (All UML diagram are shown at http://localhost:4000/ )

Enter CTRL+C to stop serving process, then:

$ npx honkit serve

Access http://localhost:4000/, this problem happens.

Additional Info

  • When the first time to run npx honkit serve, _book/assets/images/uml dir is created and images are copied.
  • When the second time to run npx honkit serve, _book/assets dir is deleted automatically and not created.
  • $repository_root/assets/images/uml dir and the generated images are remains.
  • The same problem are happen for running npx honkit build twice.
  • When I delete $repository_root/assets/images/uml manually and run npx honkit serve, the problem was fixed temporary.

Two or more images in assets/ directory are not copied into _build/

Related to #7

When markdown files contains multiple UML diagram, some image links in built HTML are broken and these diagram image is not shown in HTML.
More details, the link for UML defined in the FIRST position in markdown file is OK, but the others are always broken.

After building I checked the assets/ directory and I confirmed all images are generated, but only ONE image was copied into _build/assets/ directory.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.