Skip to content

react-markdown with remark-math and rehype-katex can't correctly parse formula contents of type \[\] #875

@hejuting

Description

@hejuting

Initial checklist

Affected package

all

Steps to reproduce

import ReactMarkdown from "react-markdown";
import "katex/dist/katex.min.css";
import RemarkMath from "remark-math";
import RemarkBreaks from "remark-breaks";
import RehypeKatex from "rehype-katex";
import RemarkGfm from "remark-gfm";
import RehypeHighlight from "rehype-highlight";
import rehypeRaw from "rehype-raw";

function TestMarkdown(){

  const content = "\\[\n" +
      "a=b^2" +
      "\n\\]"

  return <ReactMarkdown
      remarkPlugins={[RemarkMath, RemarkGfm, RemarkBreaks]}
      rehypePlugins={[
        RehypeKatex,
        [
          RehypeHighlight,
          {
            detect: false,
            ignoreMissing: true,
          },
        ],
        rehypeRaw,
      ]}
      skipHtml={false}
  >
    {content}
  </ReactMarkdown>
}


Actual behavior

image

Expected behavior

image

Runtime

"react-markdown": "9.0.1", "rehype-highlight": "7.0.1", "rehype-katex": "7.0.1", "rehype-raw": "7.0.0", "remark-breaks": "3.0.2", "remark-gfm": "4.0.0", "remark-math": "6.0.0",

Package manager

No response

Operating system

No response

Build and bundle tools

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions