当当当又get到了一个新技能,使用react-markdown来直接解析markdown文件(咳咳,小菜鸟的自娱自乐)

项目中遇到了一个API的那种展示方式,类似于入门手册啥的那种,如果是一个个调用接口,改样式很复杂,所以用了直接解析后台给的markdown文件

首先我们需要安装一个react的网页语法高亮插件,(我最初并没有安装这个,结果导致解析文件是出来了,但是样式还挺丑的)

npm install react-syntax-highlighter --save   //相关介绍在这里https://www.javascriptcn.com/read-43226.html

1.高亮的js  codeBlock.js

import React from 'react';
import SyntaxHighlighter from 'react-syntax-highlighter';
import { tomorrowNightEighties } from 'react-syntax-highlighter/dist/esm/styles/hljs'; //我这边使用的是夜晚模式的css,你也可以在react-syntax-highlighter/dist/esm/styles/hljs里面找你自己喜欢的css,把名字替换就行 eg:
import { monokai } from 'react-syntax-highlighter/dist/esm/styles/hljs';
import { Form } from 'antd'; class CodeBlock extends React.PureComponent { render() { const { value } = this.props; return ( <SyntaxHighlighter language="" style={tomorrowNightEighties}> {value} </SyntaxHighlighter>  ); } } export default Form.create()(CodeBlock);

2.然后解析文件的js

我这边直接从网上找了个.md文件如下

<p align="center">
<a href="https://github.com/uiwjs/react-markdown-editor/issues">
<img src="https://img.shields.io/github/issues/uiwjs/react-markdown-editor.svg">
</a>
<a href="https://github.com/uiwjs/react-markdown-editor/network">
<img src="https://img.shields.io/github/forks/uiwjs/react-markdown-editor.svg">
</a>
<a href="https://github.com/uiwjs/react-markdown-editor/stargazers">
<img src="https://img.shields.io/github/stars/uiwjs/react-markdown-editor.svg">
</a>
<a href="https://github.com/uiwjs/react-markdown-editor/releases">
<img src="https://img.shields.io/github/release/uiwjs/react-markdown-editor.svg">
</a>
<a href="https://www.npmjs.com/package/@uiw/react-markdown-editor">
<img src="https://img.shields.io/npm/v/@uiw/react-markdown-editor.svg">
</a>
</p> <p align="center">
A markdown editor with preview, implemented with React.js and TypeScript.
</p> ## Install ```bash
npm i @uiw/react-markdown-editor
``` ## Document Official document [demo preview](https://uiwjs.github.io/react-markdown-editor/) ([

react解析markdown文件的更多相关文章

  1. 解析Markdown文件生成React组件文档

    前言 最近做的项目使用了微前端框架single-spa. 对于这类微前端框架而言,通常有个utility应用,也就是公共应用,里面是各个子应用之间可以共用的一些公共组件或者方法. 对于一个团队而言,项 ...

  2. 开发一个简单的chrome插件-解析本地markdown文件

    准备软件环境 1. 软件环境 首先,需要使用到的软件和工具环境如下: 一个最新的chrome浏览器 编辑器vscode 2. 使用的js库 代码高亮库:prismjs https://prismjs. ...

  3. 自制 Python小工具 将markdown文件转换成Html文件

    今天看到了一个Python库,名为markdown.瞬间就给了我一个灵感,那就是制作一个将markdown文件转换成html文件的小工具. 我的实验环境 操作系统: Windows 7 64位 旗舰版 ...

  4. 使用Java解析XML文件或XML字符串的例子

    转: 使用Java解析XML文件或XML字符串的例子 2017年09月16日 11:36:18 inter_peng 阅读数:4561 标签: JavaXML-Parserdom4j 更多 个人分类: ...

  5. 使用VS Code编写Markdown文件

    VS Code默认支持Markdown文件文件格式,这里介绍两个比较实用的功能,后续有新发现,可以持续更新. 实时预览 顾名思义,实时编辑,实时预览解析效果. 在VS Code扩展中搜索"M ...

  6. 前端解析Markdown

    目录 前端解析Markdown 1.使用strapdown 1.1.下载 1.2.使用 2.使用marked(配合highlightjs) 2.1.下载 2.2.使用 3.使用mdjs(配合highl ...

  7. python实现解析markdown文档中的图片,并且保存到本地~

    背景 前阵子简书好像说是凉了,搞得我有点小慌,毕竟我的大部分博客都是放在简书上面的,虽然简书提供了打包导出功能,但是只能导出文字,图片的话还是存在简书服务器上面,再加上我一直想要重新做一个个人博客,于 ...

  8. 监听 Markdown 文件并热更新 Next.js 页面

    Next.js 提供了 Fast-Refresh 能力,它可以为您对 React 组件所做的编辑提供即时反馈. 但是,当你通过 Markdown 文件提供网站内容时,由于 Markdown 不是 Re ...

  9. Android 解析XML文件和生成XML文件

    解析XML文件 public static void initXML(Context context) { //can't create in /data/media/0 because permis ...

随机推荐

  1. springboot进入html

    话不多说,转载 https://blog.csdn.net/sinat_33889619/article/details/78339042 这个博客写的真好

  2. MySQL 57安装部署(Zip版)(Windows版)

    1. 在<MYSQL>的根目录下新建一个my.ini写入以下内容 [mysqld] port = 3306 basedir=D:\mysql\mysql-5.7.22-winx64 # M ...

  3. JavaScript调用mysql查询bigint数据精度失真解决方案

    最近我遇上了如题这个问题,后端用node.js写了一个读取mysql数据的接口,之前使用了很久都没发现什么问题,在查询订单表的订单ID时返回的值却是错的 正确的值是 19102818002800002 ...

  4. oracle xmltype + blob + clob

    oracle varchar2最大存储长度为4000,所以当字段长度超限时可尝试存储为blob或xmltype格式 xmltype --1.创建xml表 Create TABLE testxml( i ...

  5. Statements、PreparedStatement及CallableStatement(三)

    当获得了与数据库的连接后,就可以与数据库进行交互了.JDBC Statement,CallableStatement和PreparedStatement接口定义了可用于发送SQL或PL/SQL命令,并 ...

  6. POI2008 CLO-Toll

    [POI2008]CLO-Toll 题意描述 Byteotia城市有n个 towns m条双向roads. 每条 road 连接 两个不同的 towns ,没有重复的road. 你要把其中一些road ...

  7. Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) F2. Wrong Answer on test 233 (Hard Version) dp 数学

    F2. Wrong Answer on test 233 (Hard Version) Your program fails again. This time it gets "Wrong ...

  8. springboot+jpa分库分表项目实例

    分库分表场景 关系型数据库本身比较容易成为系统瓶颈,单机存储容量.连接数.处理能力都有限.当单表的数据量达到1000W或100G以后,由于查询维度较多,即使添加从库.优化索引,做很多操作时性能仍下降严 ...

  9. centos安装nodejs并配置生产环境,基于pm2

    安装nodejs和yarn的命令: curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum. ...

  10. React: React脚手架

    一.简言 React开发目前已经非常流行,对于如何实现对React项目的管理和维护,React生态圈出现了大量可用的开发工具,例如Browserify.Gulp.Grunt.webpack等.其中,w ...