react-diff-viewer 如何实现语法高亮

前言

react-diff-viewer 是一个很好的 diff 展示库,但是也有一些坑点和不完善的地方,本文旨在描述如何在这个库中实现自定义语法高亮。

Syntax highlighting is a bit tricky when combined with diff. Here, React Diff Viewer provides a simple render prop API to handle syntax highlighting. Use renderContent(content: string) => JSX.Element and your favorite syntax highlighting library to achieve this.
仓库地址:https://github.com/praneshr/react-diff-viewer

问题

issue 地址:https://github.com/praneshr/react-diff-viewer/issues/182

如果只是直接引入这个库,你会发现没有代码的语法高亮,看起来会十分难受

于是乎,你按照文档引入了,发现样式会被覆盖掉,两种样式共存会很难看,如下:

解决方案

这个问题发生的原因是因为你自定义的渲染器覆盖了原有样式,只需要把你自定义的渲染属性移除就行,比如 customStyle={{ display: 'inline', padding: 0, background: 'none' }}

完美高效解决问题!

相关推荐
摘星编程4 小时前
React Native for OpenHarmony 实战:Linking 链接处理详解
javascript·react native·react.js
摘星编程4 小时前
React Native for OpenHarmony 实战:DatePickerAndroid 日期选择器详解
android·react native·react.js
胖者是谁4 小时前
EasyPlayerPro的使用方法
前端·javascript·css
EndingCoder4 小时前
索引类型和 keyof 操作符
linux·运维·前端·javascript·ubuntu·typescript
摘星编程5 小时前
React Native for OpenHarmony 实战:ImageBackground 背景图片详解
javascript·react native·react.js
摘星编程6 小时前
React Native for OpenHarmony 实战:Alert 警告提示详解
javascript·react native·react.js
Joe5566 小时前
vue2 + antDesign 下拉框限制只能选择2个
服务器·前端·javascript
WHS-_-20226 小时前
Tx and Rx IQ Imbalance Compensation for JCAS in 5G NR
javascript·算法·5g
摘星编程6 小时前
React Native for OpenHarmony 实战:GestureResponderSystem 手势系统详解
javascript·react native·react.js
lili-felicity6 小时前
React Native for OpenHarmony 实战:加载效果的实现详解
javascript·react native·react.js·harmonyos