fix: clean comments in text in getDiagramFromText API so flowchart works well

This commit is contained in:
Aakansha Doshi 2023-11-27 13:19:31 +05:30
parent 0c0f7a739e
commit 1d5378a4f2
2 changed files with 10 additions and 2 deletions

View File

@ -1539,7 +1539,11 @@
class I bugged_node
</pre>
<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>
<script type="module">

View File

@ -8,6 +8,8 @@ import { encodeEntities } from './utils.js';
import type { DetailedError } from './utils.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;
/**
@ -23,7 +25,7 @@ export class Diagram {
private detectError?: UnknownDiagramError;
constructor(public text: string, public metadata: Pick<DiagramMetadata, 'title'> = {}) {
this.text = encodeEntities(text);
this.text = encodeEntities(cleanupComments(text));
this.text += '\n';
const cnf = configApi.getConfig();
try {
@ -85,6 +87,8 @@ export const getDiagramFromText = async (
metadata: Pick<DiagramMetadata, 'title'> = {}
): Promise<Diagram> => {
const type = detectType(text, configApi.getConfig());
let title;
try {
// Trying to find the diagram
getDiagram(type);