-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
113 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { defineConfig } from "vitepress"; | ||
import { genjiPlugin } from "./genji"; | ||
|
||
export const config = defineConfig({ | ||
markdown: { | ||
config: (md) => { | ||
md.use(genjiPlugin); | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const regexType = /\|\s*([^\s]+)/; | ||
const regexDIV = /(\<div class="[^"]*")/; | ||
|
||
export function genjiPlugin(md) { | ||
const fence = md.renderer.rules.fence; | ||
if (!fence) return; | ||
md.renderer.rules.fence = (...args) => { | ||
const [tokens, idx] = args; | ||
const token = tokens[idx]; | ||
const { info } = token; | ||
const match = info.match(regexType); | ||
const result = match ? match[1] : null; | ||
const lang = info.split(" ")[0]; | ||
if (!result) return fence(...args); | ||
const html = fence(...args); | ||
const newHTML = html.replace( | ||
regexDIV, | ||
`$1 data-genji="${result}" data-lang="${lang}"` | ||
); | ||
return newHTML; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
.genji-cell { | ||
margin: 16px 0px; | ||
margin: 16px 0px 0px 0px; | ||
} | ||
|
||
.genji-cell + div { | ||
margin-top: 0px !important; | ||
} |