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

docs: replace sapper docs with shiki docs #615

Merged
merged 5 commits into from
Aug 15, 2024
Merged
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
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"test:filter": "uvu -r ts-node/register",
"release": "pnpm -r build && changeset publish",
"changeset:add": "changeset add",
"changeset:version": "changeset version && pnpm i --lockfile-only"
"changeset:version": "changeset version && pnpm i --lockfile-only",
"site:dev": "pnpm --filter @mdsvex/site dev",
"site:build": "pnpm --filter @mdsvex/site build"
},
"keywords": [
"test",
Expand Down
2 changes: 1 addition & 1 deletion packages/site/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "mdsvex-playground",
"name": "@mdsvex/site",
"description": "Documentation side for mdsvex",
"version": "0.0.1",
"type": "module",
Expand Down
31 changes: 20 additions & 11 deletions packages/site/src/routes/_docs.svtext
Original file line number Diff line number Diff line change
Expand Up @@ -673,21 +673,30 @@ Frontmatter also interacts with layouts, you can find more details in the [Layou

## Integrations

### With Sapper
### With shiki

To use mdsvex with sapper you need to add the mdsvex configuration to both the client and server sections of the rollup or webpack configuration. You will also need to add the CLI argument `--ext '.svelte .svx'` to all of the sapper scripts (`dev`, `build`, and `export`) in order to tell sapper that it should also allow `.svx` files to be page routes.
You can use shiki for highlighting rather than prism by leveraging the `highlighter` option:

Or you can use the templates:
- [Rollup](https://github.com/pngwn/sapper-mdsvex-template)
```js
import { mdsvex, escapeSvelte } from 'mdsvex';
import { createHighlighter } from 'shiki';

```bash
npx degit "pngwn/sapper-mdsvex-template" my-app
```
- [Webpack](https://github.com/shiryel/sapper-mdsvex-template-webpack)
const theme = 'github-dark';
const highlighter = await createHighlighter({
themes: [theme],
langs: ['javascript', 'typescript']
});

```bash
npx degit "shiryel/sapper-mdsvex-template-webpack" my-app
```
/** @type {import('mdsvex').MdsvexOptions} */
const mdsvexOptions = {
highlight: {
highlighter: async (code, lang = 'text') => {
const html = escapeSvelte(highlighter.codeToHtml(code, { lang, theme }));
return `{@html \\`${html}\\` }`;
}
},
}
```

## Limitations

Expand Down
2 changes: 1 addition & 1 deletion packages/site/src/routes/docs/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
[
'Integrations',
'docs#integrations',
[['sapper', 'docs#with-sapper', false]],
[['shiki', 'docs#with-shiki', false]],
],
['Limitations', 'docs#limitations'],
];
Expand Down
24 changes: 12 additions & 12 deletions packages/site/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,32 @@ import link from 'rehype-autolink-headings';
function mdsvex_transform() {
return {
async transform(code, id) {
if (extname(id) !== ".svtext") return;
if (extname(id) !== '.svtext') return;

const c = (
await mdsvex({
highlight: {
alias: {
ts: "typescript",
mdx: "markdown",
svelte: "svelte",
svx: "svx",
mdsvex: "svx",
sig: "ts",
}
ts: 'typescript',
mdx: 'markdown',
svelte: 'svelte',
svx: 'mdx',
mdsvex: 'svx',
sig: 'ts',
},
},
extension: '.svtext',
rehypePlugins: [slug, link]
rehypePlugins: [slug, link],
}).markup({ content: code, filename: id })
).code;
return `export default \`${c.replace(/`/g, "\\`").trim()}\`;`;
}
return `export default \`${c.replace(/`/g, '\\`').trim()}\`;`;
},
};
}

/** @type {import('vite').UserConfig} */
const config = {
plugins: [ mdsvex_transform(), sveltekit() ]
plugins: [mdsvex_transform(), sveltekit()],
};

export default config;