1
0

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 1 year has passed since last update.

Vue2でマークダウン記法をHTMLに動的に変換

Posted at

Vue2でマークダウン記法をHTMLに動的に変換

■マークダウンのパーサーを導入

今回は、以下の理由でmarkedではなく、markdown-it導入した。

  • 拡張性が高い
  • セキュリティ面を考慮
npm install markdown-it --save

■Vue

MarkdownItをインポートしたら、すぐに使える。

renderの他にも、メソッドが用意されている(調べてみてください)

</template>	
	<p v-html="convertMarkdownToHtml(markdown)"></p>
</template>

<script>
import MarkdownIt from 'markdown-it';

export default {
  methods: {
      convertMarkdownToHtml(markdown) {
          return new MarkdownIt().render(markdown);
      },
  }
};
</script>
1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?