Skip to content
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 more render support #3

Merged
merged 6 commits into from
Oct 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 100 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,113 @@
# hexo-filter-plantuml
## Features

* Generate raw/base64/urlencoded svg at compile time, no external css and js required.
* Privacy guarantee. Support rendering locally or self-hosted server.
* Zero npm dependencies.

## How Does it work

```
1. Your PlantUML string quote with puml
2. Local or service side rendering
3. SVG(XML)
4. inline or external <img src='data:image/xxx'>
```


> Using PlantUML to generate UML Diagram for hexo

## Install

```sh
npm install --save https://github.com/miao1007/hexo-filter-plantuml
```
npm install --save hexo-filter-plantuml

## Configuration

#### Minimum configuration

Use plantuml.com for renderding, and the base64-encoding image will be inlined in html.

```yaml
plantuml:
render: "PlantUMLServer"
```

## Usage
#### Advanced configuration

Server-side

Please keep in mind, if you want more about privacy/safety, please replace your own self-hosted render server.

Define the UML as bellow:
```yaml
plantuml:
# Local or PlantUMLServer.
render: "PlantUMLServer"

# the server,you can change your self-hosted sever for privacy
server: "http://www.plantuml.com/plantuml"
# "inline": <svg>xxx<svg/>
# "inlineUrlEncode": <img src='data:image/svg+xml;>
# "inlineBase64": <img src='data:image/svg+xml;base64>
# "localLink": <img src="/assert/puml/xxxx.svg">
# "externalLink": <img src="http://www.plantuml.com/plantuml/svg/xxx">
link: "inline"

# common options: svg/png
outputFormat: "svg"
```

```puml
@startuml
class A
@enduml
```
Client-side

And it will render as:
```yaml
plantuml:
# Local or PlantUMLServer.
render: "Local"

![](http://www.plantuml.com/plantuml/svg/SoWkIImgAStDuKhEIImkLd3aSaZDIm7o0G00)
# "inline": <svg>xxx<svg/>
# "inlineUrlEncode": <img src='data:image/svg+xml;>
# "inlineBase64": <img src='data:image/svg+xml;base64>
# "localLink": <img src="/assert/puml/xxxx.svg">
link: "inline"

# where your dot binary
GraphvizDotFile: "/usr/local/bin/dot"
# where your jar
PlantJar: "/usr/local/Cellar/plantuml/1.2019.10/libexec/plantuml.jar"

# common options: svg/png
outputFormat: "svg"
```



## How to use it?

```
{% plantuml %}
@startuml
Object <|-- ArrayList
Object : equals()
ArrayList : Object[] elementData
ArrayList : size()
@enduml
{% endplantuml %}
```

> `@startuml` and `@endpuml` are ALWAYS required or the image will fail to be generated.

or

```
​```puml
@startuml
Object <|-- ArrayList
Object : equals()
ArrayList : Object[] elementData
ArrayList : size()
@enduml
​```
```

## Thanks to
Plugin will pick up block body and replace it with generated base64 svg diagram.

- [hexo-filter-flowchart](https://github.com/bubkoo/hexo-filter-flowchart) [@bubkoo](https://github.com/bubkoo)
- [hexo-tag-plantuml](https://github.com/oohcoder/hexo-tag-plantuml) [@oohcoder](https://github.com/oohcoder)
> `puml` and `plantuml` tags both work.
36 changes: 34 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
var renderer = require('./lib/renderer');
const plantumlRender = require("./lib/plantumlRender");

hexo.extend.filter.register('before_post_render', renderer.before, 9);
hexo.config.plantuml = Object.assign(plantumlRender.config, hexo.config.plantuml);

const reg = /(\s*)(```) *(puml|plantuml) *\n?([\s\S]+?)\s*(\2)(\n+|$)/g;

function ignore(data) {
let source = data.source;
let ext = source.substring(source.lastIndexOf('.')).toLowerCase();
return ['.js', '.css', '.html', '.htm'].indexOf(ext) > -1;
}

hexo.extend.tag.register('plantuml', (args, content) => {
var config = hexo.config.plantuml
switch (config.render) {
case "PlantUMLServer":
return plantumlRender.serverSideRendering(config, content);
case "Local":
return plantumlRender.localSideRendering(config, content);
default:
throw new Error('hexo.config.plantuml.render must be PlantUMLServer or Local');
}
},{
async: true,
ends: true
});

hexo.extend.filter.register('before_post_render', (data) => {
if (!ignore(data)) {
data.content = data.content
.replace(reg, (raw, start, startQuote, lang, content, endQuote, end) => {
return start + '{% plantuml %}' + content + '{% endplantuml %}' + end;
});
}
}, 9);
Loading