Skip to content
This repository has been archived by the owner on Apr 24, 2023. It is now read-only.

Commit

Permalink
feat(md-enhance): add legacy flowchart
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed May 31, 2022
1 parent cfcd2e3 commit 4adb920
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/md-enhance/src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
tasklist,
vueDemo,
legacyCodeDemo,
legacyFlowchart,
} from "./markdown-it";
import { getPluginConfig } from "./pluginConfig";

Expand Down Expand Up @@ -139,7 +140,10 @@ const mdEnhancePlugin: Plugin<MarkdownEnhanceOptions> = (options, context) => {
if (getStatus("sup")) md.use(sup);
if (getStatus("sub")) md.use(sub);
if (footnoteEnable) md.use(footnote);
if (flowchartEnable) md.use(flowchart);
if (flowchartEnable) {
md.use(flowchart);
md.use(legacyFlowchart);
}
if (getStatus("mark")) md.use(mark);
if (tasklistEnable)
md.use(tasklist, [
Expand Down
24 changes: 24 additions & 0 deletions packages/md-enhance/src/node/markdown-it/flowchart.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import hash = require("hash-sum");
import { uml } from "./uml";

import type { PluginSimple } from "markdown-it";
import type Token = require("markdown-it/lib/token");

Expand Down Expand Up @@ -29,3 +31,25 @@ export const flowchart: PluginSimple = (md) => {

md.renderer.rules["flowchart"] = flowchartRender;
};

/** @deprecated */
export const legacyFlowchart: PluginSimple = (md) => {
uml(md, {
name: "flowchart",
open: "flowstart",
close: "flowend",
render: (tokens, idx): string => {
console.warn(
'"@flowstart ... @flowend" is deprecated, you should use ```flow ... ``` instead.'
);

const token = tokens[idx];
const key = `flowchart_${hash(idx)}`;
const { content, info } = token;

return `<FlowChart id="${key}" code="${encodeURIComponent(
content
)}" preset="${info.trim() || "vue"}"></FlowChart>`;
},
});
};

0 comments on commit 4adb920

Please sign in to comment.