feat: code highligher

This commit is contained in:
Kieran 2023-04-30 13:48:18 +01:00
parent 3e8f36b3d6
commit 15d9bd5e70
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
3 changed files with 14 additions and 5 deletions

View File

@ -13,6 +13,7 @@
"@types/react-dom": "^18.0.0",
"bech32": "^2.0.0",
"dexie": "^3.2.3",
"highlight.js": "^11.8.0",
"moment": "^2.29.4",
"nostr-relaypool": "^0.6.27",
"parse-diff": "^0.11.1",

View File

@ -1,5 +1,7 @@
import { Chunk, File } from "parse-diff";
import { useLocation } from "react-router-dom"
import { useLocation } from "react-router-dom";
import hljs from "highlight.js";
import 'highlight.js/styles/dark.css';
import "./PatchReview.css";
import { ParsedPatch } from "./Diff";
@ -25,8 +27,9 @@ export default function PatchReview() {
{c.changes.map(v => <div className={`diff ${v.type}`}>
<div>{v.type === "del" || v.type === "normal" ? ++oldY : ""}</div>
<div>{v.type === "add" || v.type === "normal" ? ++newY : ""}</div>
<div>
{v.content}
<div dangerouslySetInnerHTML={{
__html: hljs.highlightAuto(v.content, [""]).value
}}>
</div>
</div>)}
</>
@ -37,14 +40,14 @@ export default function PatchReview() {
return <div className="file" key={k}>
<div className="header">
<div>
{f.from}{f.to && `...${f.to}`}
{f.from}{f.to && f.to !== f.from && `...${f.to}`}
</div>
<div>
<div className="add">
+{f.additions ?? 0}
</div>
<div className="del">
-{f.deleted ?? 0}
-{f.deletions ?? 0}
</div>
</div>
</div>

View File

@ -5279,6 +5279,11 @@ he@^1.2.0:
resolved "https://registry.yarnpkg.com/he/-/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f"
integrity sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==
highlight.js@^11.8.0:
version "11.8.0"
resolved "https://registry.yarnpkg.com/highlight.js/-/highlight.js-11.8.0.tgz#966518ea83257bae2e7c9a48596231856555bb65"
integrity sha512-MedQhoqVdr0U6SSnWPzfiadUcDHfN/Wzq25AkXiQv9oiOO/sG0S7XkvpFIqWBl9Yq1UYyYOOVORs5UW2XlPyzg==
hoopy@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/hoopy/-/hoopy-0.1.4.tgz#609207d661100033a9a9402ad3dea677381c1b1d"