Skip to content
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

Mermaid Support #128

Open
Pasithea0 opened this issue Oct 21, 2024 · 3 comments
Open

Mermaid Support #128

Pasithea0 opened this issue Oct 21, 2024 · 3 comments

Comments

@Pasithea0
Copy link

I'm trying to add mermaid charts to my site, but neither remark-mermaidjs or rehype-mermaid works.

Here is my code, but it does not work:

import rehypeMermaid from "rehype-mermaid";

  const mermaid: Plugin = {
      transformers: [{
          execution: "async",
          type: "rehype",
          transform({ processor }) {
              processor.use(rehypeMermaid, {
                // The default strategy is "inline-svg"
                // strategy: "img-png"
                // strategy: "img-svg"
                // strategy: "inline-svg"
                // strategy: "pre-mermaid"
              })
          }
      }]
  }

Any help is greatly appreciated!

@BearToCode
Copy link
Owner

I tried your example and it works for me:
image

import { Carta, type Plugin } from 'carta-md';
import rehypeMermaid from 'rehype-mermaidjs';

const mermaid: Plugin = {
	transformers: [{
		execution: 'async',
		type: 'rehype',
		transform({ processor }) {
			processor.use(rehypeMermaid);
		}
	}]
};

const carta = new Carta({
	extensions: [mermaid],	
	sanitizer: false
});

If you are also using plugin-code, try moving this plugin first when you provide extensions to carta:

const carta = new Carta({
	extensions: [mermaid, code()],
});

@Pasithea0
Copy link
Author

Pasithea0 commented Oct 25, 2024

  1. The text only appears if I disable the sanitizer.
  2. The mermaid chart disappears for some reason in the Markdown element
Screen.Recording.2024-10-25.at.11.33.11.AM-1.mov

@BearToCode
Copy link
Owner

  1. What sanitizer are you using? I tried dompurify and the text disappears from the boxes. I'm not able to figure out why this happens. You'll have better luck asking for help on the dompurify repo, providing an example of the generated HTML.
  2. This works fine for me (disabling the sanitizer). Try disabling all plugins and see if it still happens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants