mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-10-04 06:39:40 +02:00
docs: added warning and notes
This commit is contained in:
@@ -31,7 +31,7 @@
|
||||
"build:esbuild": "concurrently \"pnpm build:code\" \"pnpm build:types\"",
|
||||
"build": "pnpm clean; pnpm build:esbuild",
|
||||
"dev": "node .esbuild/serve.cjs",
|
||||
"predocs:build": "rimraf docs/.vitepress/dist",
|
||||
"predocs:build": "rimraf docs",
|
||||
"docs:build": "ts-node-esm src/docs.mts",
|
||||
"docs:verify": "pnpm docs:build --verify",
|
||||
"docs:code": "typedoc --plugin typedoc-plugin-markdown --readme none --hideBreadcrumbs --hideInPageTOC --namedAnchors --out src/docs/config/setup --entryPointStrategy expand src/defaultConfig.ts src/config.ts src/mermaidAPI.ts",
|
||||
|
@@ -50,7 +50,9 @@ const MERMAID_MAJOR_VERSION = (
|
||||
const SOURCE_DOCS_DIR = 'src/docs';
|
||||
const FINAL_DOCS_DIR = '../../docs';
|
||||
|
||||
const AUTOGENERATED_TEXT = `# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. Please edit the corresponding file in ${SOURCE_DOCS_DIR}.`;
|
||||
const AUTOGENERATED_TEXT = `> **Warning**
|
||||
> ## THIS IS AN AUTOGENERATED FILE. DO NOT EDIT.
|
||||
> ## Please edit the corresponding file in package/mermaid/src/docs.`;
|
||||
|
||||
const LOGMSG_TRANSFORMED = 'transformed';
|
||||
const LOGMSG_TO_BE_TRANSFORMED = 'to be transformed';
|
||||
@@ -131,6 +133,41 @@ const copyTransformedContents = (filename: string, doCopy = false, transformedCo
|
||||
logWasOrShouldBeTransformed(fileInFinalDocDir, doCopy);
|
||||
};
|
||||
|
||||
const transformAnnotation = (content: string, type: 'warning' | 'tip' | 'note') => {
|
||||
let transformed = content;
|
||||
let regex = /::: note\n[\s\S]+?:::/gm;
|
||||
let text = 'Note';
|
||||
|
||||
switch (type) {
|
||||
case 'note':
|
||||
regex = /::: note\s?\n[\s\S]+?:::/gm;
|
||||
break;
|
||||
case 'tip':
|
||||
regex = /::: tip\s?\n[\s\S]+?:::/gm;
|
||||
text = 'Note';
|
||||
break;
|
||||
case 'warning':
|
||||
regex = /::: warning\s?\n[\s\S]+?:::/gm;
|
||||
text = 'Warning';
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
const matches = content.match(regex);
|
||||
if (matches) {
|
||||
console.log(`found ${matches.length} of ${type}`);
|
||||
|
||||
const formatted = matches.map((element) =>
|
||||
element.replace(`::: ${type}`, `> ${text}`).replace(':::', '>').replace('\n', '\n> ')
|
||||
);
|
||||
let n = 0;
|
||||
for (const match of matches) {
|
||||
transformed = transformed.replace(match, formatted[n++]);
|
||||
}
|
||||
}
|
||||
return transformed;
|
||||
};
|
||||
const readSyncedUTF8file = (filename: string): string => {
|
||||
return readFileSync(filename, 'utf8');
|
||||
};
|
||||
@@ -148,7 +185,12 @@ const readSyncedUTF8file = (filename: string): string => {
|
||||
* @param file {string} name of the file that will be verified
|
||||
*/
|
||||
const transformMarkdown = (file: string) => {
|
||||
const doc = readSyncedUTF8file(file).replace(/<MERMAID_VERSION>/g, MERMAID_MAJOR_VERSION);
|
||||
let doc = readSyncedUTF8file(file).replace(/<MERMAID_VERSION>/g, MERMAID_MAJOR_VERSION);
|
||||
|
||||
doc = transformAnnotation(doc, 'warning');
|
||||
doc = transformAnnotation(doc, 'tip');
|
||||
doc = transformAnnotation(doc, 'note');
|
||||
|
||||
const ast: Root = remark.parse(doc);
|
||||
const out = flatmap(ast, (c: Code) => {
|
||||
if (c.type !== 'code') {
|
||||
|
Reference in New Issue
Block a user