react解析markdown文件
当当当又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文件的更多相关文章
- 解析Markdown文件生成React组件文档
前言 最近做的项目使用了微前端框架single-spa. 对于这类微前端框架而言,通常有个utility应用,也就是公共应用,里面是各个子应用之间可以共用的一些公共组件或者方法. 对于一个团队而言,项 ...
- 开发一个简单的chrome插件-解析本地markdown文件
准备软件环境 1. 软件环境 首先,需要使用到的软件和工具环境如下: 一个最新的chrome浏览器 编辑器vscode 2. 使用的js库 代码高亮库:prismjs https://prismjs. ...
- 自制 Python小工具 将markdown文件转换成Html文件
今天看到了一个Python库,名为markdown.瞬间就给了我一个灵感,那就是制作一个将markdown文件转换成html文件的小工具. 我的实验环境 操作系统: Windows 7 64位 旗舰版 ...
- 使用Java解析XML文件或XML字符串的例子
转: 使用Java解析XML文件或XML字符串的例子 2017年09月16日 11:36:18 inter_peng 阅读数:4561 标签: JavaXML-Parserdom4j 更多 个人分类: ...
- 使用VS Code编写Markdown文件
VS Code默认支持Markdown文件文件格式,这里介绍两个比较实用的功能,后续有新发现,可以持续更新. 实时预览 顾名思义,实时编辑,实时预览解析效果. 在VS Code扩展中搜索"M ...
- 前端解析Markdown
目录 前端解析Markdown 1.使用strapdown 1.1.下载 1.2.使用 2.使用marked(配合highlightjs) 2.1.下载 2.2.使用 3.使用mdjs(配合highl ...
- python实现解析markdown文档中的图片,并且保存到本地~
背景 前阵子简书好像说是凉了,搞得我有点小慌,毕竟我的大部分博客都是放在简书上面的,虽然简书提供了打包导出功能,但是只能导出文字,图片的话还是存在简书服务器上面,再加上我一直想要重新做一个个人博客,于 ...
- 监听 Markdown 文件并热更新 Next.js 页面
Next.js 提供了 Fast-Refresh 能力,它可以为您对 React 组件所做的编辑提供即时反馈. 但是,当你通过 Markdown 文件提供网站内容时,由于 Markdown 不是 Re ...
- Android 解析XML文件和生成XML文件
解析XML文件 public static void initXML(Context context) { //can't create in /data/media/0 because permis ...
随机推荐
- [PHP] 解决php中上传大文件的错误
修改nginx配置文件,下面这个参数client_max_body_size 110M; 修改php配置文件中下面两个参数在php.ini中找到下面两个配置,配置项给改大,如果找不到php.ini的位 ...
- Docker启动守护式容器
目录 启动守护式容器 查看容器日志 docker后台运行 查看容器内运行的进程 查看容器内部细节 进入正在运行的容器并以命令行交互 重新进入 上述两个区别 从容器内拷贝文件到主机上 启动守护式容器 ...
- TOMCAT修改默认端口(8080端口)
在工作中,有可能需要在一台服务器上同时部署两个或两个以上的tomcat(服务器性能够好), 那么就需要修改其中的一个的端口号才能使得两个同时工作,总共需要修改3个地方: 1.首先到安装目录(或者解压目 ...
- 201777010217-金云馨《面向对象程序设计(Java)》第二周学习总结
项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://www.cnblogs.com/nwnu-daizh/p ...
- poj 2456 Aggressive cows 二分 题解《挑战程序设计竞赛》
地址 http://poj.org/problem?id=2456 解法 使用二分逐个尝试间隔距离 能否满足要求 检验是否满足要求的函数 使用的思想是贪心 第一个点放一头牛 后面大于等于尝试的距离才放 ...
- (day57)九、多对多创建的三种方式、Forms组件
目录 一.多对多三种创建方式 (一)全自动 (二)纯手撸(基本不用) (三)半自动(推荐使用) 二.forms组件 (一)校验数据 (1)常用内置字段及参数 (2)内置的校验器 (3)HOOK方法 ( ...
- Apriori关联分析详解
------------恢复内容开始------------ 一. Apriori关联分析概述 选择物品之间的关联规则也就是要找出物品之间的关系,要找到这种关系有两步 找出频繁一起出现的物品集的集合, ...
- LeetCode解题笔记 - 1. Two Sum
1. Two Sum Given an array of integers, return indices of the two numbers such that they add up to a ...
- Repair Microsoft.VisualStudio.MinShell.Msi.Resources 2203 error And visual studio 2019 key
1. Go to the properties of "My computer" 2. Go to advanced settings of the system 3. Go to ...
- Note | 北航《网络安全》复习笔记
目录 1. 引言 2. 计算机网络基础 基础知识 考点 3. Internet协议的安全性 基础知识 考点 4. 单钥密码体制 基础知识 考点 5. 双钥密码体制 基础知识 考点 6. 消息认证与杂凑 ...