mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-20 15:59:51 +02:00
fix: clean comments in text in getDiagramFromText API so flowchart works well
This commit is contained in:
@@ -1539,7 +1539,11 @@
|
|||||||
class I bugged_node
|
class I bugged_node
|
||||||
</pre>
|
</pre>
|
||||||
<hr />
|
<hr />
|
||||||
|
<pre class="mermaid">
|
||||||
|
flowchart LR
|
||||||
|
%% this is a comment A -- text --> B{node}
|
||||||
|
A -- text --> B -- text2 --> C
|
||||||
|
</pre>
|
||||||
<h1 id="link-clicked">Anchor for "link-clicked" test</h1>
|
<h1 id="link-clicked">Anchor for "link-clicked" test</h1>
|
||||||
|
|
||||||
<script type="module">
|
<script type="module">
|
||||||
|
@@ -8,6 +8,8 @@ import { encodeEntities } from './utils.js';
|
|||||||
import type { DetailedError } from './utils.js';
|
import type { DetailedError } from './utils.js';
|
||||||
import type { DiagramDefinition, DiagramMetadata } from './diagram-api/types.js';
|
import type { DiagramDefinition, DiagramMetadata } from './diagram-api/types.js';
|
||||||
|
|
||||||
|
import { cleanupComments } from './diagram-api/comments.js';
|
||||||
|
|
||||||
export type ParseErrorFunction = (err: string | DetailedError | unknown, hash?: any) => void;
|
export type ParseErrorFunction = (err: string | DetailedError | unknown, hash?: any) => void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,7 +25,7 @@ export class Diagram {
|
|||||||
|
|
||||||
private detectError?: UnknownDiagramError;
|
private detectError?: UnknownDiagramError;
|
||||||
constructor(public text: string, public metadata: Pick<DiagramMetadata, 'title'> = {}) {
|
constructor(public text: string, public metadata: Pick<DiagramMetadata, 'title'> = {}) {
|
||||||
this.text = encodeEntities(text);
|
this.text = encodeEntities(cleanupComments(text));
|
||||||
this.text += '\n';
|
this.text += '\n';
|
||||||
const cnf = configApi.getConfig();
|
const cnf = configApi.getConfig();
|
||||||
try {
|
try {
|
||||||
@@ -85,6 +87,8 @@ export const getDiagramFromText = async (
|
|||||||
metadata: Pick<DiagramMetadata, 'title'> = {}
|
metadata: Pick<DiagramMetadata, 'title'> = {}
|
||||||
): Promise<Diagram> => {
|
): Promise<Diagram> => {
|
||||||
const type = detectType(text, configApi.getConfig());
|
const type = detectType(text, configApi.getConfig());
|
||||||
|
let title;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Trying to find the diagram
|
// Trying to find the diagram
|
||||||
getDiagram(type);
|
getDiagram(type);
|
||||||
|
Reference in New Issue
Block a user