Skip to content

Commit

Permalink
feat: swtich to shiki for highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Jul 24, 2022
1 parent 0d5a777 commit 1f54679
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 57 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ Mocking up web app with <b>Vitesse</b><sup><em>(speed)</em></sup><br>
- [`unplugin-auto-import`](https://github.com/antfu/unplugin-auto-import) - Directly use Vue Composition API and others without importing
- [`vite-plugin-pwa`](https://github.com/antfu/vite-plugin-pwa) - PWA
- [`vite-plugin-vue-markdown`](https://github.com/antfu/vite-plugin-vue-markdown) - Markdown as components / components in Markdown
- [`markdown-it-prism`](https://github.com/jGleitz/markdown-it-prism) - [Prism](https://prismjs.com/) for syntax highlighting
- [`prism-theme-vars`](https://github.com/antfu/prism-theme-vars) - customizable Prism.js theme using CSS variables
- [`markdown-it-shiki`](https://github.com/antfu/markdown-it-shiki) - [Shiki](https://github.com/shikijs/shiki) for syntax highlighting
- [Vue I18n](https://github.com/intlify/vue-i18n-next) - Internationalization
- [`vite-plugin-vue-i18n`](https://github.com/intlify/vite-plugin-vue-i18n) - Vite plugin for Vue I18n
- [VueUse](https://github.com/antfu/vueuse) - collection of useful composition APIs
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"@vueuse/head": "^0.7.7",
"nprogress": "^0.2.0",
"pinia": "^2.0.16",
"prism-theme-vars": "^0.2.4",
"vue": "^3.2.37",
"vue-demi": "^0.13.5",
"vue-i18n": "^9.1.10",
Expand All @@ -38,8 +37,9 @@
"eslint-plugin-cypress": "^2.12.1",
"https-localhost": "^4.7.1",
"markdown-it-link-attributes": "^4.0.0",
"markdown-it-prism": "^2.2.4",
"markdown-it-shiki": "^0.5.1",
"pnpm": "^7.6.0",
"shiki": "^0.10.1",
"typescript": "^4.7.4",
"unocss": "^0.44.5",
"unplugin-auto-import": "^0.10.0",
Expand Down
96 changes: 96 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/styles/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ body,

html.dark {
background: #121212;
color-scheme: dark;
}

#nprogress {
Expand Down
66 changes: 18 additions & 48 deletions src/styles/markdown.css
Original file line number Diff line number Diff line change
@@ -1,58 +1,28 @@
/* https://github.com/antfu/prism-theme-vars */
@import 'prism-theme-vars/base.css';
.prose pre:not(.shiki) {
padding: 0;
}

.prose {
--prism-font-family: 'DM Mono', monospace;
.prose .shiki {
font-family: 'DM Mono', monospace;
font-size: 1.2em;
line-height: 1.4;
}

.prose img {
width: 100%;
}

html:not(.dark) .prose {
--prism-foreground: #393a34;
--prism-background: #fbfbfb;
--prism-comment: #a0ada0;
--prism-string: #b56959;
--prism-literal: #2f8a89;
--prism-number: #296aa3;
--prism-keyword: #1c6b48;
--prism-function: #6c7834;
--prism-boolean: #1c6b48;
--prism-constant: #a65e2b;
--prism-deleted: #a14f55;
--prism-class: #2993a3;
--prism-builtin: #ab5959;
--prism-property: #b58451;
--prism-namespace: #b05a78;
--prism-punctuation: #8e8f8b;
--prism-decorator: #bd8f8f;
--prism-regex: #ab5e3f;
--prism-json-property: #698c96;
.shiki-light {
background: #f8f8f8 !important;
}
.shiki-dark {
background: #0e0e0e !important;
}

html.dark .shiki-light {
display: none;
}

html.dark .prose {
--prism-foreground: #d4cfbf;
--prism-background: #151515;
--prism-comment: #758575;
--prism-string: #d48372;
--prism-literal: #429988;
--prism-keyword: #4d9375;
--prism-boolean: #1c6b48;
--prism-number: #6394bf;
--prism-variable: #c2b36e;
--prism-function: #a1b567;
--prism-deleted: #a14f55;
--prism-class: #54b1bf;
--prism-builtin: #e0a569;
--prism-property: #dd8e6e;
--prism-namespace: #db889a;
--prism-punctuation: #858585;
--prism-decorator: #bd8f8f;
--prism-regex: #ab5e3f;
--prism-json-property: #6b8b9e;
--prism-line-number: #888888;
--prism-line-number-gutter: #eeeeee;
--prism-line-highlight-background: #444444;
--prism-selection-background: #444444;
html:not(.dark) .shiki-dark {
display: none;
}
13 changes: 8 additions & 5 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ import Markdown from 'vite-plugin-vue-markdown'
import { VitePWA } from 'vite-plugin-pwa'
import VueI18n from '@intlify/vite-plugin-vue-i18n'
import Inspect from 'vite-plugin-inspect'
import Prism from 'markdown-it-prism'
import LinkAttributes from 'markdown-it-link-attributes'
import Unocss from 'unocss/vite'

const markdownWrapperClasses = 'prose prose-sm m-auto text-left'
import Shiki from 'markdown-it-shiki'

export default defineConfig({
resolve: {
Expand Down Expand Up @@ -71,11 +69,16 @@ export default defineConfig({
// https://github.com/antfu/vite-plugin-vue-markdown
// Don't need this? Try vitesse-lite: https://github.com/antfu/vitesse-lite
Markdown({
wrapperClasses: markdownWrapperClasses,
wrapperClasses: 'prose prose-sm m-auto text-left',
headEnabled: true,
markdownItSetup(md) {
// https://prismjs.com/
md.use(Prism)
md.use(Shiki, {
theme: {
light: 'vitesse-light',
dark: 'vitesse-dark',
},
})
md.use(LinkAttributes, {
matcher: (link: string) => /^https?:\/\//.test(link),
attrs: {
Expand Down

0 comments on commit 1f54679

Please sign in to comment.