Skip to content

Commit

Permalink
fix: only import ts code snippet would need to add @noerror leading line
Browse files Browse the repository at this point in the history
  • Loading branch information
Blackman99 committed Mar 5, 2024
1 parent e5a8c03 commit 21cd863
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
8 changes: 8 additions & 0 deletions .changeset/nervous-eagles-admire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@sveltepress/theme-default": patch
"@sveltepress/vite": patch
"@sveltepress/create": patch
"@sveltepress/twoslash": patch
---

fix: only import ts code snippet would need to add @noError leading line
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,16 @@ title: Vite 插件
:::important[插件顺序]{icon=solar:reorder-outline}
主题提供的 remark 以及 rehype 插件将会在 vite 插件提供的之前调用
例如:
```js title="vite.config.(js|ts)"
```ts title="vite.config.(js|ts)"
import { defineConfig } from 'vite'
import { sveltepress } from '@sveltepress/vite'
import { defaultTheme } from '@sveltepress/theme-default'

export default defineConfig({
plugins: [
sveltepress({
theme: defaultTheme(/* theme options */),
remarkPlugins: [yourRemarkPlugin]
theme: defaultTheme(/* 默认主题选项 */),
remarkPlugins: [/* 你的 remark 插件 */]
})
]
})
Expand Down
4 changes: 2 additions & 2 deletions packages/docs-site/src/routes/reference/vite-plugin/+page.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Read [Rehype plugins](https://github.com/rehypejs/rehype#plugins) for more detai
:::important[Plugins order]{icon=solar:reorder-outline}
The remark and rehype plugins that theme provide would be called before the plugins provide by vite plugin.
For example:
```js title="vite.config.(js|ts)"
```ts title="vite.config.(js|ts)"
import { defineConfig } from 'vite'
import { sveltepress } from '@sveltepress/vite'
import { defaultTheme } from '@sveltepress/theme-default'
Expand All @@ -89,7 +89,7 @@ export default defineConfig({
plugins: [
sveltepress({
theme: defaultTheme(/* theme options */),
remarkPlugins: [yourRemarkPlugin]
remarkPlugins: [/* yourRemarkPlugin */]
})
]
})
Expand Down
5 changes: 4 additions & 1 deletion packages/theme-default/src/markdown/code-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ const codeImport: Plugin<any[], any> = () => {
if (initialBlankNumbers > 0)
valueArr = valueArr.map(line => line.replace(new RegExp(`^ {${initialBlankNumbers}}`), ''))
}
const codeStr = `// @noErrors\n${valueArr.join('\n')}`
if (!valueArr[0].startsWith('// @noErrors') && lang === 'ts')
valueArr.unshift('// @noErrors')

const codeStr = valueArr.join('\n')
const node = {
type: 'code',
lang,
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface ResolvedTheme {
*/
footnoteLabel?: string
}
// @noErrors

export interface SveltepressVitePluginOptions {
theme?: ResolvedTheme
siteConfig?: SiteConfig
Expand Down

0 comments on commit 21cd863

Please sign in to comment.