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

Some diagrams doesn't work with rehype-raw plugin #17

Closed
stereobooster opened this issue May 4, 2024 · 2 comments
Closed

Some diagrams doesn't work with rehype-raw plugin #17

stereobooster opened this issue May 4, 2024 · 2 comments

Comments

@stereobooster
Copy link

stereobooster commented May 4, 2024

About issue

This is not a bug in your code. Just want to let you know about it:

import { unified } from "unified";
import remarkParse from "remark-parse";
import remarkRehype from "remark-rehype";
import rehypeMermaid from "rehype-mermaid";
import rehypeRaw from "rehype-raw";
import rehypeStringify from "rehype-stringify";

const markdown = `
\`\`\`mermaid
---
config:
  sankey:
    showValues: false
---
sankey-beta

Agricultural 'waste',Bio-conversion,10
Bio-conversion,Liquid,5
\`\`\`
`;

const file = await unified()
  .use(remarkParse)
  .use(remarkRehype)
  .use(rehypeMermaid)
  .use(rehypeRaw)
  .use(rehypeStringify)
  .process(markdown);

console.log(file.value.match(
  /<g style="mix-blend-mode: multiply;" class="link">(.*?)<\/g>/
));

Without rehype-raw it would generate:

<g style="mix-blend-mode: multiply;" class="link"><linearGradient x2="295" x1="10" gradientUnits="userSpaceOnUse" id="linearGradient-4"><stop stop-color="#4e79a7" offset="0%"></stop><stop stop-color="#f28e2c" offset="100%"></stop></linearGradient><path stroke-width="400" stroke="url(#linearGradient-4)" d="M10,200C152.5,200,152.5,200,295,200"></path></g>

With rehype-raw it would generate:

<g style="mix-blend-mode: multiply;" class="link"><linearGradient x2="295" x1="10" gradientUnits="userSpaceOnUse" id="linearGradient-4"><stop stop-color="#4e79a7" offset="0%"></stop><stop stop-color="#f28e2c" offset="100%"></stop><path stroke-width="400" stroke="url(#linearGradient-4)" d="M10,200C152.5,200,152.5,200,295,200"></path></linearGradient></g>

It changes position of closing tag </linearGradient>. And the second option is wrong.

About strategies

Which makes rehypePlugins: [[rehypeMermaid, { strategy: "img-svg" }]], a bit more reliable choice. But on the other hand it doesn't support css (correct?).

  • inline-svg
    • cons: other CSS from HTML page may conflict (like globally set line-height)
    • cons: may not work with rehype-raw
    • pros : supports css option
    • pros : text is searchable
  • img-svg
    • cons: doesn't support css option
    • pros: supports dark mode
    • pros: no issues with rehype-raw
    • pros: no conflicts with other styles on the page
@stereobooster stereobooster changed the title Some diagrams doesn't work with raw-rehype plugin Some diagrams doesn't work with rehype-raw plugin May 5, 2024
@remcohaszing
Copy link
Owner

Good catch. This is definitely a bug. I reported it upstream, but let’s keep this issue open until this is fixed. In the meantime, you could move rehypeRaw before rehypeMermaid.

@remcohaszing
Copy link
Owner

It’s fixed in [email protected] 🎉

@remcohaszing remcohaszing closed this as not planned Won't fix, can't repro, duplicate, stale May 6, 2024
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