mirror of
https://github.com/alrayyes/wiki.git
synced 2025-05-01 14:38:14 +00:00
syntax higlighting
This commit is contained in:
parent
42d3a7de17
commit
04eeb2d10c
11 changed files with 198 additions and 44 deletions
|
@ -5,3 +5,4 @@ export { Katex } from './latex'
|
|||
export { Description } from './description'
|
||||
export { ResolveLinks } from './links'
|
||||
export { ObsidianFlavoredMarkdown } from './ofm'
|
||||
export { SyntaxHighlighting } from './syntax'
|
||||
|
|
28
quartz/plugins/transformers/syntax.ts
Normal file
28
quartz/plugins/transformers/syntax.ts
Normal file
|
@ -0,0 +1,28 @@
|
|||
import { PluggableList } from "unified"
|
||||
import { QuartzTransformerPlugin } from "../types"
|
||||
import rehypePrettyCode, { Options as CodeOptions } from "rehype-pretty-code"
|
||||
|
||||
export class SyntaxHighlighting extends QuartzTransformerPlugin {
|
||||
name = "SyntaxHighlighting"
|
||||
|
||||
markdownPlugins(): PluggableList {
|
||||
return []
|
||||
}
|
||||
|
||||
htmlPlugins(): PluggableList {
|
||||
return [[rehypePrettyCode, {
|
||||
theme: 'css-variables',
|
||||
onVisitLine(node) {
|
||||
if (node.children.length === 0) {
|
||||
node.children = [{ type: 'text', value: ' ' }]
|
||||
}
|
||||
},
|
||||
onVisitHighlightedLine(node) {
|
||||
node.properties.className.push('highlighted')
|
||||
},
|
||||
onVisitHighlightedWord(node) {
|
||||
node.properties.className = ['word']
|
||||
},
|
||||
} satisfies Partial<CodeOptions>]]
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue