markdown-it-infographic 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +40 -0
- package/dist/cjs/index.js +58 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -0
- package/dist/esm/index.js +47 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/tsconfig.types.tsbuildinfo +1 -0
- package/docs/.gitkeep +0 -0
- package/package.json +69 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 William Engelmann
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# markdown-it-infographic
|
|
2
|
+
|
|
3
|
+
## Install
|
|
4
|
+
```bash
|
|
5
|
+
npm install @antv/infographic markdown-it-infographic
|
|
6
|
+
```
|
|
7
|
+
|
|
8
|
+
## Usage
|
|
9
|
+
```ts
|
|
10
|
+
const md = require('markdown-it')()
|
|
11
|
+
const infographic = require('markdown-it-infographic')
|
|
12
|
+
|
|
13
|
+
md.use(infographic)
|
|
14
|
+
// md.use(infographic, {
|
|
15
|
+
// padding: 4
|
|
16
|
+
// })
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Input:
|
|
20
|
+
````markdown
|
|
21
|
+
```infographic
|
|
22
|
+
infographic list-row-simple-horizontal-arrow
|
|
23
|
+
data
|
|
24
|
+
items
|
|
25
|
+
- label 步骤 1
|
|
26
|
+
desc 开始
|
|
27
|
+
- label 步骤 2
|
|
28
|
+
desc 进行中
|
|
29
|
+
- label 步骤 3
|
|
30
|
+
desc 完成
|
|
31
|
+
```
|
|
32
|
+
````
|
|
33
|
+
|
|
34
|
+
Output:
|
|
35
|
+
```html
|
|
36
|
+
<div data-infographic="true"><svg>...</svg></div>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Options
|
|
40
|
+
[Infographic](https://github.com/antvis/infographic) options.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
module.exports = infographic;
|
|
15
|
+
var infographic_1 = require("@antv/infographic");
|
|
16
|
+
// Define interface to await readiness of import
|
|
17
|
+
function infographic(md, baseOptions) {
|
|
18
|
+
function getLangName(info) {
|
|
19
|
+
return info.split(/\s+/g)[0];
|
|
20
|
+
}
|
|
21
|
+
// Store reference to original renderer.
|
|
22
|
+
var defaultFenceRenderer = md.renderer.rules.fence;
|
|
23
|
+
// Render custom code types as SVGs, letting the fence parser do all the heavy lifting.
|
|
24
|
+
function customFenceRenderer(tokens, idx, options, env, slf) {
|
|
25
|
+
var token = tokens[idx];
|
|
26
|
+
var info = token.info.trim();
|
|
27
|
+
var langName = info ? getLangName(info) : "";
|
|
28
|
+
if (["infographic", "{infographic}"].indexOf(langName) === -1) {
|
|
29
|
+
if (defaultFenceRenderer !== undefined) {
|
|
30
|
+
return defaultFenceRenderer(tokens, idx, options, env, slf);
|
|
31
|
+
}
|
|
32
|
+
// Missing fence renderer!
|
|
33
|
+
return "";
|
|
34
|
+
}
|
|
35
|
+
var element = document.createElement('div');
|
|
36
|
+
element.dataset.infographic = "true";
|
|
37
|
+
document.body.appendChild(element);
|
|
38
|
+
// Render with Mermaid
|
|
39
|
+
try {
|
|
40
|
+
var instance = new infographic_1.Infographic(__assign({ container: element }, baseOptions));
|
|
41
|
+
instance.render(token.content);
|
|
42
|
+
var svg = element.children[0];
|
|
43
|
+
// Infographic handles the visibility of svg internally through MutationObserver, we may output directly
|
|
44
|
+
// to the nodejs here, so we process the style to make it display by default
|
|
45
|
+
if (svg instanceof SVGElement) {
|
|
46
|
+
svg.style.visibility = '';
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
return "<div class=\"alert alert-danger\">".concat(e, "</div>");
|
|
51
|
+
}
|
|
52
|
+
finally {
|
|
53
|
+
element.remove();
|
|
54
|
+
}
|
|
55
|
+
return element.outerHTML;
|
|
56
|
+
}
|
|
57
|
+
md.renderer.rules.fence = customFenceRenderer;
|
|
58
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["../../src/index.ts"],"version":"5.9.3"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Infographic } from "@antv/infographic";
|
|
2
|
+
// Define interface to await readiness of import
|
|
3
|
+
export default function infographic(md, baseOptions) {
|
|
4
|
+
function getLangName(info) {
|
|
5
|
+
return info.split(/\s+/g)[0];
|
|
6
|
+
}
|
|
7
|
+
// Store reference to original renderer.
|
|
8
|
+
let defaultFenceRenderer = md.renderer.rules.fence;
|
|
9
|
+
// Render custom code types as SVGs, letting the fence parser do all the heavy lifting.
|
|
10
|
+
function customFenceRenderer(tokens, idx, options, env, slf) {
|
|
11
|
+
let token = tokens[idx];
|
|
12
|
+
let info = token.info.trim();
|
|
13
|
+
let langName = info ? getLangName(info) : "";
|
|
14
|
+
if (["infographic", "{infographic}"].indexOf(langName) === -1) {
|
|
15
|
+
if (defaultFenceRenderer !== undefined) {
|
|
16
|
+
return defaultFenceRenderer(tokens, idx, options, env, slf);
|
|
17
|
+
}
|
|
18
|
+
// Missing fence renderer!
|
|
19
|
+
return "";
|
|
20
|
+
}
|
|
21
|
+
const element = document.createElement('div');
|
|
22
|
+
element.dataset.infographic = "true";
|
|
23
|
+
document.body.appendChild(element);
|
|
24
|
+
// Render with Mermaid
|
|
25
|
+
try {
|
|
26
|
+
const instance = new Infographic({
|
|
27
|
+
container: element,
|
|
28
|
+
...baseOptions
|
|
29
|
+
});
|
|
30
|
+
instance.render(token.content);
|
|
31
|
+
const svg = element.children[0];
|
|
32
|
+
// Infographic handles the visibility of svg internally through MutationObserver, we may output directly
|
|
33
|
+
// to the nodejs here, so we process the style to make it display by default
|
|
34
|
+
if (svg instanceof SVGElement) {
|
|
35
|
+
svg.style.visibility = '';
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
return `<div class="alert alert-danger">${e}</div>`;
|
|
40
|
+
}
|
|
41
|
+
finally {
|
|
42
|
+
element.remove();
|
|
43
|
+
}
|
|
44
|
+
return element.outerHTML;
|
|
45
|
+
}
|
|
46
|
+
md.renderer.rules.fence = customFenceRenderer;
|
|
47
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["../../src/index.ts"],"version":"5.9.3"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["../../src/index.ts"],"version":"5.9.3"}
|
package/docs/.gitkeep
ADDED
|
File without changes
|
package/package.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "markdown-it-infographic",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "markdown-it plugin for @antv/Infographic",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/types/index.d.ts",
|
|
9
|
+
"require": "./dist/cjs/index.js",
|
|
10
|
+
"import": "./dist/esm/index.js",
|
|
11
|
+
"default": "./dist/esm/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./*": {
|
|
14
|
+
"types": "./dist/types/*.d.ts",
|
|
15
|
+
"require": "./dist/cjs/*.js",
|
|
16
|
+
"import": "./dist/esm/*.js",
|
|
17
|
+
"default": "./dist/esm/*.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"types": "./dist/types/index.d.ts",
|
|
21
|
+
"main": "./dist/cjs/index.js",
|
|
22
|
+
"scripts": {
|
|
23
|
+
"dev": "vitest",
|
|
24
|
+
"build": "tsc -b ./tsconfig.cjs.json ./tsconfig.esm.json ./tsconfig.types.json && node after-build.js",
|
|
25
|
+
"test": "vitest run",
|
|
26
|
+
"coverage": "vitest run --coverage"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "https://github.com/hcg1023/markdown-it-infographic"
|
|
31
|
+
},
|
|
32
|
+
"author": "hcg1023",
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/hcg1023/markdown-it-infographic/issues"
|
|
36
|
+
},
|
|
37
|
+
"homepage": "https://github.com/hcg1023/markdown-it-infographic",
|
|
38
|
+
"keywords": [
|
|
39
|
+
"markdown",
|
|
40
|
+
"markdown-it",
|
|
41
|
+
"markdown-it-plugin",
|
|
42
|
+
"@antv/infographic"
|
|
43
|
+
],
|
|
44
|
+
"files": [
|
|
45
|
+
"dist",
|
|
46
|
+
"docs",
|
|
47
|
+
"!**/*.spec.*",
|
|
48
|
+
"!test",
|
|
49
|
+
"LICENSE",
|
|
50
|
+
"README.md"
|
|
51
|
+
],
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@antv/infographic": "^0.2.6",
|
|
54
|
+
"@types/js-beautify": "^1.14.3",
|
|
55
|
+
"@types/markdown-it": "latest",
|
|
56
|
+
"eventemitter3": "^5.0.1",
|
|
57
|
+
"happy-dom": "^20.0.11",
|
|
58
|
+
"js-beautify": "^1.15.1",
|
|
59
|
+
"jsdom": "^27.4.0",
|
|
60
|
+
"markdown-it": "latest",
|
|
61
|
+
"typescript": "^5.0.3",
|
|
62
|
+
"vite": "^5.1.6",
|
|
63
|
+
"vite-plugin-dts": "^4.2.2",
|
|
64
|
+
"vitest": "^2.1.1"
|
|
65
|
+
},
|
|
66
|
+
"peerDependencies": {
|
|
67
|
+
"@antv/infographic": ">=0.2"
|
|
68
|
+
}
|
|
69
|
+
}
|