关于markdown:NextJS在Web端实现md文件内容展示

NextJS开发过程中,应用了MateriaUI进行博客网站搭建,对Markdown的语法插件markdown-to-jsx理解不多,并且想要高亮代码块的显示成果。

应用到的组件

npm install --save react-markdown react-syntax-highlighter

1.react-markdown:markdown解析展现组件
2.react-syntax-highlighter:高亮款式组件

应用形式(组件化)

import React from 'react';
import ReactMarkdown from 'react-markdown';
import {Prism as SyntaxHighlighter} from 'react-syntax-highlighter'
import {tomorrow } from 'react-syntax-highlighter/dist/cjs/styles/prism';

const renderers = {
  code: ({language, value}) => {
    return <SyntaxHighlighter style={tomorrow} language={language} children={value} />
  },
}

export default function Markdown(props) {
  return <ReactMarkdown renderers={renderers} options={options} {...props} />;
}
呈现的问题
  1. react-syntax-highlighter报错Unexpected token export

解决形式:款式门路esmcjs 【相干ISSUE】

内容原创,未经自己批准禁止转载

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理