Skip to content

Commit

Permalink
fix: clean comments in text in getDiagramFromText API so flowchart wo…
Browse files Browse the repository at this point in the history
…rks well
  • Loading branch information
ad1992 committed Nov 27, 2023
1 parent 0c0f7a7 commit 1d5378a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion demos/flowchart.html
Original file line number Diff line number Diff line change
Expand Up @@ -1539,7 +1539,11 @@ <h3>flowchart</h3>
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">
Expand Down
6 changes: 5 additions & 1 deletion packages/mermaid/src/Diagram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 1d5378a

Please sign in to comment.