Skip to content

Commit

Permalink
feat: inital commit with first working version (#1)
Browse files Browse the repository at this point in the history
* include all but travis

* add plantuml.jar version v1.2023.10

* wip

* wip

* remove unused dep

* update packages

* try fix tests

* fixes

* remove not needed file

* fix test

* node 16

* wip
  • Loading branch information
mstroppel authored Aug 20, 2023
1 parent 94ce18d commit 2d4ab6a
Show file tree
Hide file tree
Showing 14 changed files with 5,001 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"node": true
},
"extends": ["eslint:recommended", "plugin:prettier/recommended"],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018
},
"rules": {}
}
30 changes: 30 additions & 0 deletions .github/workflows/npmpublish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Node.js Package

on:
release:
types: [created]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 16
- run: npm ci
- run: npm test

publish-npm:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 16
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
106 changes: 106 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# ========================================
# Generated by gibo
#
# See details about gibo:
# https://github.com/simonwhitaker/gibo
# ========================================

### node

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# next.js build output
.next

# nuxt.js build output
.nuxt

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/


### visualstudiocode

.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
3 changes: 3 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"spec": "test/**/*.js"
}
5 changes: 5 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"useTabs": false,
"printWidth": 120,
"tabWidth": 2
}
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"streetsidesoftware.code-spell-checker"
]
}
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"cSpell.words": [
"plantuml"
]
}
83 changes: 83 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@

# Remark Simple PlantUML Plugin with local Rendering

TODO: build status

`remark-local-plantuml` is a simple plugin for [remarkjs](https://github.com/remarkjs/remark) that converts PlantUML code locally int inline html image nodes.

## Installing

```bash
npm install --save @mstroppel/remark-local-plantuml
```

## Example

You can use this plugin like following

### Markdown

````markdown
# Your markdown including PlantUML code block

```plantuml Your title
class SimplePlantUMLPlugin {
+ transform(syntaxTree: AST): AST
}
```
````

### JavaScript

```javascript
const remark = require("remark");
const simplePlantUML = require("@mstroppel/remark-local-plantuml");
const fs = require("fs");
const path = require("path");

const input = fs.readFileSync(path.resolve(__dirname, "./your-markdown.md")).toString();
const output = remark().use(simplePlantUML).processSync(input).toString();

console.log(output);
// will be
// > # Your markdown including PlantUML code block
// >
// > ![Your title](https://www.plantuml.com/plantuml/png/Iyv9B2vM2CxCBSX93SX9p2i9zVK9o2bDpynJgEPI009jXPAYnBpYjFoYN8tYohoIn8gGejHKAmN7u11DCCbL2m00)
```

## Plugin Options

You can use specific PlantUML server by the option 'baseUrl'.
(The default is `https://www.plantuml.com/plantuml/png`)

If you want to use SVG, you can configure like following.

```javascript
remark().use(simplePlantUML, { baseUrl: "https://www.plantuml.com/plantuml/svg" }).processSync(input);
```

## Integration

You can use this plugin in any frameworks support remarkjs.

If you want to use in the classic preset of [Docusaurus 2](https://v2.docusaurus.io/), like me, set configuration in your `docusaurus.config.js` like following.

```javascript
const simplePlantUML = require("@mstroppel/remark-local-plantuml");

// your configurations...

presets: [
[
"@docusaurus/preset-classic",
{
docs: {
sidebarPath: require.resolve("./sidebars.js"),
remarkPlugins: [simplePlantUML]
}
}
]
],

//...
```
46 changes: 46 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const visit = require("unist-util-visit");
const plantuml = require("node-plantuml");

/**
* Plugin for remark-js
*
* See details about plugin API:
* https://github.com/unifiedjs/unified#plugin
*/
function remarkSimplePlantumlPlugin() {
return async function transformer(syntaxTree) {
const nodes = [];
visit(syntaxTree, "code", node => {
let { lang, value } = node;
if (lang && value && lang === "plantuml") {
nodes.push(node);
}
});

let promises = [];
for (const node of nodes) {
let { value, alt } = node;
let svgString = "";
const plantumlGenerator = plantuml.generate(value, { format: "svg" });

let promise = new Promise(resolve => {
plantumlGenerator.out.on("data", data => {
svgString += data.toString("utf8");
});

plantumlGenerator.out.on("end", () => {
node.type = "html";
node.value = `<div class="plantuml-diagram">${svgString}</div>`;
node.alt = alt;
node.meat = undefined;
resolve();
});
});
promises.push(promise);
}

await Promise.all(promises);
};
}

module.exports = remarkSimplePlantumlPlugin;
Loading

0 comments on commit 2d4ab6a

Please sign in to comment.