Skip to content

HTML escape included mermaid files to handle embedded tags #1580

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
HTML escape embded html to fix mermaid rendering
  • Loading branch information
mgranell committed May 27, 2021
commit 07d6d85170b41eeed24c7394eb63a45950f28bd8
8 changes: 7 additions & 1 deletion src/core/render/embed.js
Original file line number Diff line number Diff line change
@@ -63,7 +63,13 @@ function walkFetchEmbed({ embedTokens, compile, fetch }, cb) {
);
} else if (token.embed.type === 'mermaid') {
embedToken = [
{ type: 'html', text: `<div class="mermaid">\n${text}\n</div>` },
{
type: 'html',
text: `<div class="mermaid">\n${text
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/"/g, '&quot;')}\n</div>`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should use a more robust solution like described in the following SO question so that it accounts for other characters, not just those specific ones?

https://stackoverflow.com/questions/18749591/encode-html-entities-in-javascript

},
];
embedToken.links = {};
} else {