2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

MarkdownがHTMLに期待通りに変換されない【react-markdown】

2
Posted at

はじめに

react-markdownというMarkdownをHTMLに変換するライブラリを使おうとしたのですが、うまく変換されませんでした。

問題

import ReactMarkdown from "react-markdown";

const content = `
    # はじめに
    こんにちは!**田中**です
`;

function App() {
  return (
    <>
      <ReactMarkdown>{content}</ReactMarkdown>
    </>
  );
}

解決方法

import ReactMarkdown from "react-markdown";

const content = `
  # はじめに
  こんにちは!**田中**です
`;

function App() {
  return (
    <>
      <ReactMarkdown>{content}</ReactMarkdown>
    </>
  );
}

contentの部分のインデントを減らしました。
半角スペースが4つ以上あるとコードブロックとして認識されるようです。
なので半角スペース二つに変更しました。(三つでもok)

参考文献

おわりに

どうやらこれはreact-markdownではなくマークダウン自体の仕様らしいです。全く知らなかった。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?