Skip to content

Commit

Permalink
support expressive code in docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjennings committed Dec 4, 2023
1 parent 411b61b commit 37eb29e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 62 deletions.
12 changes: 7 additions & 5 deletions docs/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@ export default defineConfig({
},
},
integrations: [
liveExamples({
commonMeta: 'client:only',
wrapper: '/src/layouts/examples/wrappers/WithApp.svelte',
}),
starlight({
title: 'Svelte Pixi',
customCss: ['./src/tailwind.css'],
expressiveCode: false,
expressiveCode: {
themes: [codeTheme],
},
social: {
github: 'https://github.com/mattjennings/svelte-pixi',
},
Expand Down Expand Up @@ -115,6 +113,10 @@ export default defineConfig({
},
],
}),
liveExamples({
commonMeta: 'client:only',
wrapper: '/src/layouts/examples/wrappers/WithApp.svelte',
}),
svelte({
extensions: ['.svelte'],
}),
Expand Down
28 changes: 4 additions & 24 deletions docs/integrations/live-examples/index.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import remark from './remark.mjs'
import vite from './vite.mjs'
import mdx from '@astrojs/mdx'
import recast from 'recast'

/**
Expand Down Expand Up @@ -29,30 +28,11 @@ export default function (options) {
return {
name: 'live-examples',
hooks: {
'astro:config:setup': ({ config, updateConfig }) => {
'astro:config:setup': ({ updateConfig }) => {
updateConfig({
integrations: [
mdx({
syntaxHighlight: 'shiki',
shikiConfig: config.markdown?.shikiConfig,
remarkPlugins: [
[
remark,
{ ...options, theme: config.markdown?.shikiConfig?.theme },
],
],
recmaPlugins: [
() => (tree) => {
// console.log(
// recast.prettyPrint(tree, {
// tabWidth: 2,
// quote: 'single',
// }),
// )
},
],
}),
],
markdown: {
remarkPlugins: [[remark, options]],
},
vite: {
plugins: [vite(options)],
},
Expand Down
39 changes: 6 additions & 33 deletions docs/integrations/live-examples/remark.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default function examples(options) {

if (node.meta && node.meta.split(' ').includes('live')) {
const meta = [options.commonMeta ?? '', node.meta].join(' ')

const src = node.value
const i = examples.length

Expand Down Expand Up @@ -79,6 +80,7 @@ export default function examples(options) {
default: true,
})

const codeNode = { ...node }
const commonProps = [
{
type: 'mdxJsxAttribute',
Expand Down Expand Up @@ -133,7 +135,7 @@ export default function examples(options) {
type: 'ArrayExpression',
elements: meta.split(' ').map((value) => ({
type: 'Literal',
value,
value: value ?? '',
})),
},
},
Expand Down Expand Up @@ -213,38 +215,7 @@ export default function examples(options) {
value: 'code',
},
],
children: [
{
type: 'mdxJsxFlowElement',
name: 'Code',
attributes: [
{
type: 'mdxJsxAttribute',
name: 'code',
value: node.value,
},
{
type: 'mdxJsxAttribute',
name: 'lang',
value: node.lang,
},
...(options.theme
? [
{
type: 'mdxJsxAttribute',
name: 'theme',
value: options.theme,
},
]
: []),
],
children: [],
data: {
_mdxExplicitJsx: true,
_src: node.value,
},
},
],
children: [codeNode],
},
],
}
Expand Down Expand Up @@ -333,6 +304,8 @@ function getWrapperPathFromMeta(meta) {
}

function toPOSIX(path) {
if (!path) return path

return path.replace(/\\/g, '/')
}

Expand Down

0 comments on commit 37eb29e

Please sign in to comment.