1

From the most recent remark-gfm documentation, I can see it should support footnotes. However, when I type something like:

Text here. [^1]

Text here. [^2]

[^1]: note 1

[^2]: note 2

This is displayed as text, rather than converted to HTML tags.

My code is:

...
import ReactMarkdown from "react-markdown";                                      
import remarkGfm from "remark-gfm";
...

<ReactMarkdown children={markdown_content_here} remarkPlugins={[remarkGfm]} />
...
yldm
  • 144
  • 3
  • 14
  • 1
    Apparently, you need to configure [remark-rehype](https://github.com/remarkjs/remark-rehype#api). I'm facing the same issue right now, will post an answer when I solve it. – Firmin Martin Nov 10 '21 at 21:30
  • I saw this but I read mixed feedback. Aren't remark-rehype and remark-footnotes legacy and included in remark-gfm? Found this here: https://github.com/remarkjs/remark-footnotes – yldm Nov 10 '21 at 22:13
  • Yes, `remark-footnotes` is legacy, Though you can probably [make it works](https://github.com/remarkjs/remark/discussions/554) if you don't care. I just read the source code of `react-remark`, and it [already uses](https://github.com/remarkjs/react-markdown/blob/626b99ea4b6e6125d0c571de18c10351863ccb08/lib/react-markdown.js#L88) `remark-rehype`... – Firmin Martin Nov 10 '21 at 22:17
  • My first comment was wrong. I was referring `This plugin does not handle how markdown is turned to HTML. That’s done by remark-rehype. If your content is not in English and uses footnotes, you should configure that plugin` in the docs of [remark-gfm](https://github.com/remarkjs/remark-gfm#when-should-i-use-this). BTW, `react-remark` doesn't let us configure `remark-rehype`... I'd have expected that `remark-gfm` work out of the box. Maybe I will figure out using only [unified](https://github.com/unifiedjs/unified). – Firmin Martin Nov 10 '21 at 22:26
  • hmm, but i only use english. perhaps it is interpreting it as not english? – yldm Nov 10 '21 at 22:30
  • Yeah, it's fine for English, it's another problem to look at in my case. – Firmin Martin Nov 10 '21 at 22:34
  • 1
    Hmm, `remark-gfm` does the job as advertised: see [this sandbox](https://codesandbox.io/s/heuristic-snyder-qq9g3?file=/src/index.js) (check the console). But when I `console.log` just after [this line](https://github.com/remarkjs/react-markdown/blob/626b99ea4b6e6125d0c571de18c10351863ccb08/lib/react-markdown.js#L102), it shows that the footnotes is in a `

    ` tag.

    – Firmin Martin Nov 10 '21 at 23:06

1 Answers1

0

I made it works in this codesandbox.

example.md

Text here. [^1]

Text here. [^2]

[^1]: note 1
[^2]: note 2

import "./styles.css";
import markdown from "./example.md";
import { useEffect, useState } from "react";
import ReactMarkdown from "react-markdown";
import remarkGfm from "remark-gfm";

export default function App() {
  const [text, setText] = useState(null);

  useEffect(() => {
    (async () => {
      const response = await fetch(markdown);
      const content = await response.text();
      setText(content);
    })();
  }, []);
  return <ReactMarkdown remarkPlugins={[remarkGfm]} children={text} />;
}

(See also this codesandbox with pure unified + remark-gfm).

Conjecture: why it doesn't work

Having a reproducible working example, it's now simple to observe the difference with my real-word code: for some reason, I have remark-gfm v2 installed. You should upgrade to v3 to make sure that footnotes works.

Firmin Martin
  • 280
  • 3
  • 15
  • 1
    ahh, this is a good point. I think for me it does not work then because to upgrade remark-gfm to v3, i need to upgrade react-markdown to v7. which then leads me to an ESM-only error which i can't really fix on the spot due to other dependencies (the suggested solution for that seems to be to add "type": "module" in package.json – yldm Nov 12 '21 at 16:13