Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: setup twoslash for codeblocks #2668

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { defineConfigWithTheme } from 'vitepress'
import type { Config as ThemeConfig } from '@vue/theme'
import baseConfig from '@vue/theme/config'
import { headerPlugin } from './headerMdPlugin'
import { transformerTwoslash } from '@shikijs/vitepress-twoslash'
// import { textAdPlugin } from './textAdMdPlugin'

const nav: ThemeConfig['nav'] = [
Expand Down Expand Up @@ -715,12 +716,16 @@ export default defineConfigWithTheme<ThemeConfig>({
config(md) {
md.use(headerPlugin)
// .use(textAdPlugin)
}
},
codeTransformers: [
transformerTwoslash()
]
},

vite: {
define: {
__VUE_OPTIONS_API__: false
// Turn this back off after floating-vue migrated to Composition API
__VUE_OPTIONS_API__: true
},
optimizeDeps: {
include: ['gsap', 'dynamics.js'],
Expand Down
6 changes: 5 additions & 1 deletion .vitepress/theme/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import '@shikijs/vitepress-twoslash/style.css'
import './styles/index.css'
import { h, App } from 'vue'

import { h, App, Plugin } from 'vue'
import { VPTheme } from '@vue/theme'
import twoslashFloatingVue from '@shikijs/vitepress-twoslash/client'
import PreferenceSwitch from './components/PreferenceSwitch.vue'
import {
preferComposition,
Expand All @@ -22,6 +25,7 @@ export default Object.assign({}, VPTheme, {
})
},
enhanceApp({ app }: { app: App }) {
app.use(twoslashFloatingVue as Plugin<[]>)
app.provide('prefer-composition', preferComposition)
app.provide('prefer-sfc', preferSFC)
app.provide('filter-headers', filterHeadersByPreference)
Expand Down
1 change: 1 addition & 0 deletions .vitepress/theme/styles/index.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@import "./pages.css";
@import "./badges.css";
@import "./twoslash.css";
@import "./options-boxes.css";
@import "./inline-demo.css";
@import "./utilities.css";
Expand Down
34 changes: 34 additions & 0 deletions .vitepress/theme/styles/twoslash.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
:root {
--twoslash-border-color: var(--vt-c-divider);
--twoslash-unmatched-color: var(--vt-c-text-2);
}

.twoslash-floating .twoslash-popup-container {
font-family: var(--vt-font-family-mono);
line-height: var(--vt-doc-code-line-height);
font-size: 14px;
color: white;
}

.twoslash-floating .twoslash-popup-docs {
font-family: var(--vt-font-family-base) !important;
font-size: 1em;
}

.twoslash-floating .twoslash-popup-docs-tag-name {
color: var(--vt-c-text-2) !important;
}

.v-popper--theme-twoslash .v-popper__inner {
background: #24292e;
color: white;
border-color: #8885;
}

.v-popper--theme-dropdown .v-popper__arrow-outer {
border-color: #8885;
}

.v-popper--theme-dropdown .v-popper__arrow-inner {
border-color: #24292e;
}
17 changes: 8 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,18 @@
"@vue/repl": "^4.0.1",
"@vue/theme": "^2.2.5",
"dynamics.js": "^1.1.5",
"gsap": "^3.9.0",
"vitepress": "1.0.0-rc.33",
"vue": "^3.4.0"
"floating-vue": "^5.2.2",
"gsap": "^3.12.5",
"vitepress": "1.0.0-rc.44",
"vue": "^3.4.15"
},
"devDependencies": {
"@types/markdown-it": "^12.2.3",
"@types/node": "^20.10.1",
"terser": "^5.14.2"
"@shikijs/vitepress-twoslash": "^1.1.7",
"@types/markdown-it": "^13.0.7",
"@types/node": "^20.11.5",
"terser": "^5.27.0"
},
"pnpm": {
"overrides": {
"@vitejs/plugin-vue": "5.0.0-beta.1"
},
"peerDependencyRules": {
"ignoreMissing": [
"@algolia/client-search",
Expand Down
Loading