-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change(highlighter) use shiki instead of shikiji (#30)
* change(highlighter) use shiki instead of shikiji * change(docs) markdown highlight * chore: release * feat(gh actions) run test
- Loading branch information
1 parent
2c15b4f
commit 7aec543
Showing
10 changed files
with
133 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ on: | |
types: [submitted] | ||
|
||
jobs: | ||
build: | ||
publish: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
|
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,29 @@ | ||
name: Run Test | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
pull_request: | ||
types: [opened, synchronize] | ||
|
||
pull_request_review: | ||
types: [submitted] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install pnpm | ||
uses: pnpm/[email protected] | ||
|
||
- name: Install dependencies | ||
run: pnpm install | ||
|
||
- name: Run test | ||
run: pnpm test:run |
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"name": "vitepress-theme-openapi", | ||
"type": "module", | ||
"version": "0.0.3-alpha.25", | ||
"version": "0.0.3-alpha.26", | ||
"packageManager": "[email protected]", | ||
"homepage": "https://vitepress-theme-openapi.vercel.app/", | ||
"repository": { | ||
|
@@ -35,7 +35,9 @@ | |
"lint": "eslint src", | ||
"lint:fix": "eslint src --fix", | ||
"docs:dev": "vitepress dev docs", | ||
"docs:build": "npm run build && vitepress build docs" | ||
"docs:build": "npm run build && vitepress build docs", | ||
"test": "vitest", | ||
"test:run": "vitest --run" | ||
}, | ||
"peerDependencies": { | ||
"vue": "^3.4.29" | ||
|
@@ -65,7 +67,7 @@ | |
"prettier": "^3.3.3", | ||
"rimraf": "^6.0.1", | ||
"scule": "^1.3.0", | ||
"shikiji": "0.10.2", | ||
"shiki": "^1.16.1", | ||
"tailwindcss": "^3.4.10", | ||
"typescript": "^5.5.4", | ||
"typescript-eslint": "^8.3.0", | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,47 @@ | ||
import { ref } from 'vue'; | ||
import { createHighlighterCoreSync, createJavaScriptRegexEngine } from 'shiki/core' | ||
import { useTheme } from 'vitepress-theme-openapi/composables/useTheme'; | ||
import { type Highlighter } from 'shiki/bundle/web'; | ||
|
||
import js from 'shiki/langs/javascript.mjs' | ||
import ts from 'shiki/langs/typescript.mjs' | ||
import markdown from 'shiki/langs/markdown.mjs' | ||
import json from 'shiki/langs/json.mjs' | ||
import xml from 'shiki/langs/xml.mjs' | ||
import python from 'shiki/langs/python.mjs' | ||
import bash from 'shiki/langs/bash.mjs' | ||
import php from 'shiki/langs/php.mjs' | ||
|
||
const langs = [js, ts, markdown, json, xml, python, bash, php]; | ||
|
||
let shiki: Highlighter | null = null; | ||
|
||
const loading = ref(true); | ||
const themeConfig = useTheme(); | ||
|
||
export function useShiki() { | ||
const initShiki = () => { | ||
if (shiki) { | ||
return; | ||
} | ||
shiki = createHighlighterCoreSync({ | ||
themes: [themeConfig.highlighterTheme.light, themeConfig.highlighterTheme.dark], | ||
langs, | ||
engine: createJavaScriptRegexEngine() | ||
}) | ||
}; | ||
|
||
const renderShiki = (content: string, { lang, theme }: { lang: string; theme: string }) => { | ||
if (shiki && shiki.getLoadedLanguages().includes(lang)) { | ||
const result = shiki.codeToHtml(content, { | ||
lang, | ||
theme, | ||
}); | ||
return result; | ||
} else { | ||
return `<pre><code>${content}</code></pre>`; | ||
} | ||
}; | ||
|
||
return { loading, renderShiki, initShiki }; | ||
} |
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