11
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ReactでマークダウンをHTMLに変換する

Last updated at Posted at 2020-03-05

ReactでマークダウンをHTMLに変換する方法について記載

1.react-markdownをインストール

npm install --save react-markdown

2.以下のコードを記載


import React,{Component} from 'react';
import ReactMarkdown from 'react-markdown/with-html';

export default class MarkdownSample extends React.Component {

    constructor(props) {
        super(props)
    }

    getHTMLfromMarkdown(){
        let markdown =
            '# 見出し 1\n' +
            '## 見出し 2\n' +
            '### 見出し 3\n' +
            '#### 見出し 4\n' +
            '---\n' +
            '- リスト 1\n' +
            '- リスト 2\n' +
            '- リスト 2-1\n' +
            '1. 番号付きリスト 1\n' +
            '2. 番号付きリスト 2\n' +
            '3. 番号付きリスト 3\n' +
            '[リンク](http://...)\n' +
            '**強調**\n' +
            '```ruby:filename.rb\n' +
            'コード\n' +
            '```';
        return markdown;
    }

    render() {
        return (
            <div>
                <ReactMarkdown
                    source={this.getHTMLfromMarkdown()}
                    escapeHtml={false}
                />
            </div>
        )
    }
}

以上

参考

11
13
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
11
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?