@diplodoc/mermaid-extension 1.1.2 → 1.2.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/package.json +15 -12
- package/plugin/index.js +2 -12
- package/plugin/index.js.map +3 -3
- package/runtime/index.js +385 -318
- package/runtime/index.js.map +4 -4
package/package.json
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@diplodoc/mermaid-extension",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Mermaid plugin for Diplodoc transformer and builder",
|
|
5
5
|
"main": "plugin/index.js",
|
|
6
6
|
"types": "plugin/index.d.ts",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=18",
|
|
9
|
+
"npm": ">=9.*"
|
|
10
|
+
},
|
|
7
11
|
"exports": {
|
|
8
12
|
".": "./plugin/index.js",
|
|
9
13
|
"./plugin": "./plugin/index.js",
|
|
@@ -15,10 +19,10 @@
|
|
|
15
19
|
"build": "run-p build:*",
|
|
16
20
|
"build:js": "./esbuild/build.js",
|
|
17
21
|
"build:declarations": "tsc --emitDeclarationOnly --outDir .",
|
|
18
|
-
"
|
|
22
|
+
"prepublishOnly": "npm run build",
|
|
19
23
|
"lint": "eslint .",
|
|
20
24
|
"lint:fix": "eslint --fix .",
|
|
21
|
-
"test": "
|
|
25
|
+
"test": "exit 0"
|
|
22
26
|
},
|
|
23
27
|
"keywords": [
|
|
24
28
|
"mermaid",
|
|
@@ -32,6 +36,7 @@
|
|
|
32
36
|
"react"
|
|
33
37
|
],
|
|
34
38
|
"peerDependencies": {
|
|
39
|
+
"markdown-it": "^14.0.0",
|
|
35
40
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
|
|
36
41
|
},
|
|
37
42
|
"peerDependenciesMeta": {
|
|
@@ -42,25 +47,23 @@
|
|
|
42
47
|
"devDependencies": {
|
|
43
48
|
"@diplodoc/eslint-config": "^1.0.14",
|
|
44
49
|
"@diplodoc/prettier-config": "^1.0.0",
|
|
50
|
+
"@diplodoc/transform": "^4.7.2",
|
|
45
51
|
"@diplodoc/tsconfig": "^1.0.2",
|
|
52
|
+
"@gravity-ui/icons": "^2.8.1",
|
|
46
53
|
"@types/d3": "^7.4.0",
|
|
47
|
-
"@types/markdown-it": "^
|
|
54
|
+
"@types/markdown-it": "^13.0.7",
|
|
48
55
|
"@types/node": "^20.3.2",
|
|
49
56
|
"@types/react": "^18.0.35",
|
|
50
|
-
"esbuild": "^0.
|
|
57
|
+
"esbuild": "^0.19.9",
|
|
51
58
|
"esbuild-inline-sass": "^0.4.1",
|
|
52
59
|
"eslint": "^8.51.0",
|
|
53
60
|
"jest": "^29.5.0",
|
|
54
|
-
"markdown-it": "^
|
|
61
|
+
"markdown-it": "^14.0.0",
|
|
62
|
+
"mermaid": "^10.6.1",
|
|
55
63
|
"npm-run-all": "^4.1.5",
|
|
56
64
|
"prettier": "^3.0.3",
|
|
57
65
|
"react": "^18.2.0",
|
|
66
|
+
"ts-dedent": "^2.2.0",
|
|
58
67
|
"typescript": "^5.0.2"
|
|
59
|
-
},
|
|
60
|
-
"dependencies": {
|
|
61
|
-
"@diplodoc/transform": "^4.2.1",
|
|
62
|
-
"@gravity-ui/icons": "^2.3.0",
|
|
63
|
-
"mermaid": "^10.0.2",
|
|
64
|
-
"ts-dedent": "^2.2.0"
|
|
65
68
|
}
|
|
66
69
|
}
|
package/plugin/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
|
|
30
20
|
// src/plugin/index.ts
|
|
@@ -35,7 +25,6 @@ __export(plugin_exports, {
|
|
|
35
25
|
module.exports = __toCommonJS(plugin_exports);
|
|
36
26
|
|
|
37
27
|
// src/plugin/transform.ts
|
|
38
|
-
var import_markdown_it = __toESM(require("markdown-it"));
|
|
39
28
|
function isMermaidBlock(token) {
|
|
40
29
|
return token.type === "fence" && token.info.match(/^\s*mermaid(\s*|$)/);
|
|
41
30
|
}
|
|
@@ -115,7 +104,8 @@ function transform(options = {}) {
|
|
|
115
104
|
};
|
|
116
105
|
Object.assign(plugin, {
|
|
117
106
|
collect(input, { destRoot }) {
|
|
118
|
-
const
|
|
107
|
+
const MdIt = dynrequire("markdown-it");
|
|
108
|
+
const md = new MdIt().use((md2) => {
|
|
119
109
|
registerTransforms(md2, {
|
|
120
110
|
classes,
|
|
121
111
|
runtime,
|
package/plugin/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/plugin/index.ts", "../src/plugin/transform.ts"],
|
|
4
|
-
"sourcesContent": ["export {transform} from './transform';\n", "import MarkdownIt from 'markdown-it';\nimport type {\n MarkdownItPluginCb,\n MarkdownItPluginOpts,\n} from '@diplodoc/transform/lib/plugins/typings';\nimport type ParserCore from 'markdown-it/lib/parser_core';\nimport type Token from 'markdown-it/lib/token';\n\nexport type PluginOptions = {\n runtime: string;\n classes: string;\n bundle: boolean;\n};\n\nfunction isMermaidBlock(token: Token) {\n return token.type === 'fence' && token.info.match(/^\\s*mermaid(\\s*|$)/);\n}\n\nfunction hidden<B extends Record<string | symbol, unknown>, F extends string | symbol, V>(\n box: B,\n field: F,\n value: V,\n) {\n if (!(field in box)) {\n Object.defineProperty(box, field, {\n enumerable: false,\n value: value,\n });\n }\n\n return box as B & {[P in F]: V};\n}\n\nfunction copy(from: string, to: string) {\n const {mkdirSync, copyFileSync} = dynrequire('node:fs');\n const {dirname} = dynrequire('node:path');\n\n mkdirSync(dirname(to), {recursive: true});\n copyFileSync(from, to);\n}\n\n/*\n * Runtime require hidden for builders.\n * Used for nodejs api\n */\nfunction dynrequire(module: string) {\n return eval(`require('${module}')`);\n}\n\nconst registerTransforms = (\n md: MarkdownIt,\n {\n classes,\n runtime,\n bundle,\n output,\n updateTokens,\n }: PluginOptions & {\n output: string;\n updateTokens: boolean;\n },\n) => {\n const applyTransforms: ParserCore.RuleCore = ({tokens, env}) => {\n hidden(env, 'bundled', new Set<string>());\n\n const blocks = tokens.filter(isMermaidBlock);\n\n if (updateTokens && blocks.length) {\n blocks.forEach((token) => {\n token.type = 'mermaid';\n token.attrSet('class', `mermaid ${classes}`);\n });\n }\n\n if (blocks.length) {\n env.meta = env.meta || {};\n env.meta.script = env.meta.script || [];\n env.meta.script.push(runtime);\n\n if (bundle) {\n const {join} = dynrequire('node:path');\n const file = join(PACKAGE, 'runtime');\n if (!env.bundled.has(file)) {\n env.bundled.add(file);\n\n copy(require.resolve(file), join(output, runtime));\n }\n }\n }\n };\n\n try {\n md.core.ruler.after('fence', 'mermaid', applyTransforms);\n } catch (e) {\n md.core.ruler.push('mermaid', applyTransforms);\n }\n};\n\ntype InputOptions = MarkdownItPluginOpts & {\n destRoot: string;\n};\n\nexport function transform(options: Partial<PluginOptions> = {}) {\n const {\n runtime = '_assets/mermaid-extension.js',\n classes = 'yfm-mermaid',\n bundle = true,\n } = options;\n\n const plugin: MarkdownItPluginCb<{output: string}> = function (md: MarkdownIt, {output = '.'}) {\n registerTransforms(md, {\n classes,\n runtime,\n bundle,\n output,\n updateTokens: true,\n });\n\n md.renderer.rules.mermaid = (tokens, idx) => {\n const token = tokens[idx];\n const code = encodeURIComponent(token.content.trim());\n\n return `<div class=\"mermaid\" data-content=\"${code}\"></div>`;\n };\n };\n\n Object.assign(plugin, {\n collect(input: string, {destRoot}: InputOptions) {\n const md = new
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["
|
|
4
|
+
"sourcesContent": ["export {transform} from './transform';\n", "import type MarkdownIt from 'markdown-it';\nimport type {\n MarkdownItPluginCb,\n MarkdownItPluginOpts,\n} from '@diplodoc/transform/lib/plugins/typings';\nimport type ParserCore from 'markdown-it/lib/parser_core';\nimport type Token from 'markdown-it/lib/token';\n\nexport type PluginOptions = {\n runtime: string;\n classes: string;\n bundle: boolean;\n};\n\nfunction isMermaidBlock(token: Token) {\n return token.type === 'fence' && token.info.match(/^\\s*mermaid(\\s*|$)/);\n}\n\nfunction hidden<B extends Record<string | symbol, unknown>, F extends string | symbol, V>(\n box: B,\n field: F,\n value: V,\n) {\n if (!(field in box)) {\n Object.defineProperty(box, field, {\n enumerable: false,\n value: value,\n });\n }\n\n return box as B & {[P in F]: V};\n}\n\nfunction copy(from: string, to: string) {\n const {mkdirSync, copyFileSync} = dynrequire('node:fs');\n const {dirname} = dynrequire('node:path');\n\n mkdirSync(dirname(to), {recursive: true});\n copyFileSync(from, to);\n}\n\n/*\n * Runtime require hidden for builders.\n * Used for nodejs api\n */\nfunction dynrequire(module: string) {\n return eval(`require('${module}')`);\n}\n\nconst registerTransforms = (\n md: MarkdownIt,\n {\n classes,\n runtime,\n bundle,\n output,\n updateTokens,\n }: PluginOptions & {\n output: string;\n updateTokens: boolean;\n },\n) => {\n const applyTransforms: ParserCore.RuleCore = ({tokens, env}) => {\n hidden(env, 'bundled', new Set<string>());\n\n const blocks = tokens.filter(isMermaidBlock);\n\n if (updateTokens && blocks.length) {\n blocks.forEach((token) => {\n token.type = 'mermaid';\n token.attrSet('class', `mermaid ${classes}`);\n });\n }\n\n if (blocks.length) {\n env.meta = env.meta || {};\n env.meta.script = env.meta.script || [];\n env.meta.script.push(runtime);\n\n if (bundle) {\n const {join} = dynrequire('node:path');\n const file = join(PACKAGE, 'runtime');\n if (!env.bundled.has(file)) {\n env.bundled.add(file);\n\n copy(require.resolve(file), join(output, runtime));\n }\n }\n }\n };\n\n try {\n md.core.ruler.after('fence', 'mermaid', applyTransforms);\n } catch (e) {\n md.core.ruler.push('mermaid', applyTransforms);\n }\n};\n\ntype InputOptions = MarkdownItPluginOpts & {\n destRoot: string;\n};\n\nexport function transform(options: Partial<PluginOptions> = {}) {\n const {\n runtime = '_assets/mermaid-extension.js',\n classes = 'yfm-mermaid',\n bundle = true,\n } = options;\n\n const plugin: MarkdownItPluginCb<{output: string}> = function (md: MarkdownIt, {output = '.'}) {\n registerTransforms(md, {\n classes,\n runtime,\n bundle,\n output,\n updateTokens: true,\n });\n\n md.renderer.rules.mermaid = (tokens, idx) => {\n const token = tokens[idx];\n const code = encodeURIComponent(token.content.trim());\n\n return `<div class=\"mermaid\" data-content=\"${code}\"></div>`;\n };\n };\n\n Object.assign(plugin, {\n collect(input: string, {destRoot}: InputOptions) {\n const MdIt = dynrequire('markdown-it');\n const md = new MdIt().use((md: MarkdownIt) => {\n registerTransforms(md, {\n classes,\n runtime,\n bundle,\n output: destRoot,\n updateTokens: false,\n });\n });\n\n md.parse(input, {});\n },\n });\n\n return plugin;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACcA,SAAS,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