mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-08-15 14:29:25 +02:00
fix: support parsing indented mmd YAML from HTML
In order to parse the YAML front-matter in a Mermaid diagram, the YAML seperators **MUST NOT** be indented, e.g.: ````markdown ```mermaid --- title: This is fine. --- ``` ```mermaid --- title: This is not fine, because the `---` are indented. --- ``` ```` However, this makes it very difficult to write nice Mermaid diagrams in HTML code-blocks. This commit uses [`ts-dedent`](https://www.npmjs.com/package/ts-dedent) to automatically remove the indentation from Mermaid diagrams when parsed from HTML. Mermaid diagrams from mermaidAPI.render() are **NOT** dedented, as that API is called from JavaScript code, and therefore users can easily `dedent` their own diagrams.
This commit is contained in:
@@ -64,6 +64,7 @@
|
|||||||
"moment-mini": "^2.24.0",
|
"moment-mini": "^2.24.0",
|
||||||
"non-layered-tidy-tree-layout": "^2.0.2",
|
"non-layered-tidy-tree-layout": "^2.0.2",
|
||||||
"stylis": "^4.1.2",
|
"stylis": "^4.1.2",
|
||||||
|
"ts-dedent": "^2.2.0",
|
||||||
"uuid": "^9.0.0"
|
"uuid": "^9.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
@@ -2,6 +2,8 @@
|
|||||||
* Web page integration module for the mermaid framework. It uses the mermaidAPI for mermaid
|
* Web page integration module for the mermaid framework. It uses the mermaidAPI for mermaid
|
||||||
* functionality and to render the diagrams to svg code!
|
* functionality and to render the diagrams to svg code!
|
||||||
*/
|
*/
|
||||||
|
import dedent from 'ts-dedent';
|
||||||
|
|
||||||
import { MermaidConfig } from './config.type';
|
import { MermaidConfig } from './config.type';
|
||||||
import { log } from './logger';
|
import { log } from './logger';
|
||||||
import utils from './utils';
|
import utils from './utils';
|
||||||
@@ -147,8 +149,7 @@ const initThrowsErrors = function (
|
|||||||
txt = element.innerHTML;
|
txt = element.innerHTML;
|
||||||
|
|
||||||
// transforms the html to pure text
|
// transforms the html to pure text
|
||||||
txt = utils
|
txt = dedent(utils.entityDecode(txt)) // removes indentation, required for YAML parsing
|
||||||
.entityDecode(txt)
|
|
||||||
.trim()
|
.trim()
|
||||||
.replace(/<br\s*\/?>/gi, '<br/>');
|
.replace(/<br\s*\/?>/gi, '<br/>');
|
||||||
|
|
||||||
@@ -288,8 +289,7 @@ const initThrowsErrorsAsync = async function (
|
|||||||
txt = element.innerHTML;
|
txt = element.innerHTML;
|
||||||
|
|
||||||
// transforms the html to pure text
|
// transforms the html to pure text
|
||||||
txt = utils
|
txt = dedent(utils.entityDecode(txt)) // removes indentation, required for YAML parsing
|
||||||
.entityDecode(txt)
|
|
||||||
.trim()
|
.trim()
|
||||||
.replace(/<br\s*\/?>/gi, '<br/>');
|
.replace(/<br\s*\/?>/gi, '<br/>');
|
||||||
|
|
||||||
|
16
pnpm-lock.yaml
generated
16
pnpm-lock.yaml
generated
@@ -211,6 +211,9 @@ importers:
|
|||||||
stylis:
|
stylis:
|
||||||
specifier: ^4.1.2
|
specifier: ^4.1.2
|
||||||
version: 4.1.2
|
version: 4.1.2
|
||||||
|
ts-dedent:
|
||||||
|
specifier: ^2.2.0
|
||||||
|
version: 2.2.0
|
||||||
uuid:
|
uuid:
|
||||||
specifier: ^9.0.0
|
specifier: ^9.0.0
|
||||||
version: 9.0.0
|
version: 9.0.0
|
||||||
@@ -3634,7 +3637,7 @@ packages:
|
|||||||
/axios/0.21.4_debug@4.3.2:
|
/axios/0.21.4_debug@4.3.2:
|
||||||
resolution: {integrity: sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==}
|
resolution: {integrity: sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==}
|
||||||
dependencies:
|
dependencies:
|
||||||
follow-redirects: 1.15.2_debug@4.3.2
|
follow-redirects: 1.15.2
|
||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
- debug
|
- debug
|
||||||
dev: true
|
dev: true
|
||||||
@@ -6309,7 +6312,7 @@ packages:
|
|||||||
resolution: {integrity: sha512-XGozTsMPYkm+6b5QL3Z9wQcJjNYxp0CYn3U1gO7dwD6PAqU1SVWZxI9CCg3z+ml3YfqdPnrBehaBrnH2AGKbNA==}
|
resolution: {integrity: sha512-XGozTsMPYkm+6b5QL3Z9wQcJjNYxp0CYn3U1gO7dwD6PAqU1SVWZxI9CCg3z+ml3YfqdPnrBehaBrnH2AGKbNA==}
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/follow-redirects/1.15.2_debug@4.3.2:
|
/follow-redirects/1.15.2:
|
||||||
resolution: {integrity: sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==}
|
resolution: {integrity: sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==}
|
||||||
engines: {node: '>=4.0'}
|
engines: {node: '>=4.0'}
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
@@ -6317,8 +6320,6 @@ packages:
|
|||||||
peerDependenciesMeta:
|
peerDependenciesMeta:
|
||||||
debug:
|
debug:
|
||||||
optional: true
|
optional: true
|
||||||
dependencies:
|
|
||||||
debug: 4.3.2
|
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/foreground-child/2.0.0:
|
/foreground-child/2.0.0:
|
||||||
@@ -6911,7 +6912,7 @@ packages:
|
|||||||
engines: {node: '>=8.0.0'}
|
engines: {node: '>=8.0.0'}
|
||||||
dependencies:
|
dependencies:
|
||||||
eventemitter3: 4.0.7
|
eventemitter3: 4.0.7
|
||||||
follow-redirects: 1.15.2_debug@4.3.2
|
follow-redirects: 1.15.2
|
||||||
requires-port: 1.0.0
|
requires-port: 1.0.0
|
||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
- debug
|
- debug
|
||||||
@@ -10613,6 +10614,11 @@ packages:
|
|||||||
resolution: {integrity: sha512-AqTiAOLcj85xS7vQ8QkAV41hPDIJ71XJB4RCUrzo/1GM2CQwhkJGaf9Hgr7BOugMRpgGUrqRg/DrBDl4H40+8g==}
|
resolution: {integrity: sha512-AqTiAOLcj85xS7vQ8QkAV41hPDIJ71XJB4RCUrzo/1GM2CQwhkJGaf9Hgr7BOugMRpgGUrqRg/DrBDl4H40+8g==}
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/ts-dedent/2.2.0:
|
||||||
|
resolution: {integrity: sha512-q5W7tVM71e2xjHZTlgfTDoPF/SmqKG5hddq9SzR49CH2hayqRKJtQ4mtRlSxKaJlR/+9rEM+mnBHf7I2/BQcpQ==}
|
||||||
|
engines: {node: '>=6.10'}
|
||||||
|
dev: false
|
||||||
|
|
||||||
/ts-node/10.9.1_cbe7ovvae6zqfnmtgctpgpys54:
|
/ts-node/10.9.1_cbe7ovvae6zqfnmtgctpgpys54:
|
||||||
resolution: {integrity: sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==}
|
resolution: {integrity: sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==}
|
||||||
hasBin: true
|
hasBin: true
|
||||||
|
Reference in New Issue
Block a user