2023-11-08 22:56:48 +00:00
|
|
|
import { defineMDSveXConfig as defineConfig } from 'mdsvex';
|
2024-04-27 23:13:28 +00:00
|
|
|
import rehypeExternalLinks from 'rehype-external-links';
|
|
|
|
import rehypeAutolinkHeadings from 'rehype-autolink-headings';
|
|
|
|
import readingTime from 'mdsvex-reading-time';
|
2024-02-13 15:42:36 +00:00
|
|
|
import remarkUnwrapImages from 'remark-unwrap-images';
|
2023-11-08 22:56:48 +00:00
|
|
|
import remarkToc from 'remark-toc';
|
2024-02-13 15:42:36 +00:00
|
|
|
import rehypeSlug from 'rehype-slug';
|
2024-04-27 23:13:28 +00:00
|
|
|
import { visit } from 'unist-util-visit';
|
|
|
|
import { toString } from 'mdast-util-to-string';
|
|
|
|
import Slugger from 'github-slugger';
|
|
|
|
import remarkFFF from 'remark-fff';
|
|
|
|
import remarkFootnotes from 'remark-footnotes';
|
|
|
|
// import { shikiTwoslashHighlighter } from '@kitbook/mdsvex-shiki-twoslash';
|
|
|
|
// import createShikiHighlighter from './src/lib/utils/shiki-highlighter.js';
|
|
|
|
// const shiki = await createShikiHighlighter({
|
|
|
|
// theme: 'github-dark-dimmed',
|
|
|
|
// showLineNumbers: (n) => true
|
|
|
|
// });
|
|
|
|
// highlighter
|
|
|
|
import { escapeSvelte } from 'mdsvex';
|
|
|
|
import { lex, parse as parseFence } from 'fenceparser';
|
|
|
|
import { renderCodeToHTML, runTwoSlash, createShikiHighlighter } from 'shiki-twoslash';
|
2023-11-08 22:56:48 +00:00
|
|
|
|
|
|
|
/** @type {import('mdsvex').MdsvexOptions} */
|
|
|
|
const config = defineConfig({
|
|
|
|
extensions: ['.svelte.md', '.md', '.svx'],
|
|
|
|
smartypants: {
|
|
|
|
dashes: 'oldschool'
|
|
|
|
},
|
2024-04-27 23:13:28 +00:00
|
|
|
// layout: {
|
|
|
|
// _: './src/lib/components/blog/Post.svelte'
|
|
|
|
// },
|
|
|
|
highlight: {
|
|
|
|
highlighter: async (code, lang, meta) => {
|
|
|
|
let fence, twoslash;
|
|
|
|
try {
|
|
|
|
fence = parseFence(lex([lang, meta].filter(Boolean).join(' ')));
|
|
|
|
} catch (error) {
|
|
|
|
throw new Error(`Could not parse the codefence for this code sample \n${code}`);
|
|
|
|
}
|
|
|
|
if (fence?.twoslash === true) twoslash = runTwoSlash(code, lang);
|
|
|
|
return `{@html \`${escapeSvelte(
|
|
|
|
renderCodeToHTML(
|
|
|
|
code,
|
|
|
|
lang,
|
|
|
|
fence ?? {},
|
|
|
|
{ themeName: 'github-dark-dimmed' },
|
|
|
|
await createShikiHighlighter({ theme: 'github-dark-dimmed' }),
|
|
|
|
twoslash
|
|
|
|
)
|
|
|
|
)}\` }`;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// highlight: {
|
|
|
|
// highlighter: shiki
|
|
|
|
// },
|
2024-02-13 15:42:36 +00:00
|
|
|
/* Wait for skeleton to implement Prismjs, for now use <CodeBlock /> in .md files */
|
2023-11-08 22:56:48 +00:00
|
|
|
// layout: {
|
|
|
|
// blog: './src/lib/components/blog/_blog-layout.svelte',
|
|
|
|
// project: './src/lib/components/projects/_project-layout.svelte',
|
|
|
|
// _: './src/lib/components/fallback/_layout.svelte'
|
|
|
|
// },
|
2024-02-13 15:42:36 +00:00
|
|
|
/* Plugins */
|
2023-11-08 22:56:48 +00:00
|
|
|
rehypePlugins: [
|
2024-03-16 09:12:50 +00:00
|
|
|
[rehypeSlug],
|
2024-04-27 23:13:28 +00:00
|
|
|
[rehypeAutolinkHeadings, { behavior: 'wrap' }],
|
|
|
|
[
|
|
|
|
rehypeExternalLinks,
|
|
|
|
{
|
|
|
|
rel: ['nofollow', 'noopener', 'noreferrer', 'external'],
|
|
|
|
target: '_blank'
|
|
|
|
}
|
|
|
|
]
|
2024-02-13 15:42:36 +00:00
|
|
|
// [
|
|
|
|
// /** Custom rehype plugin to add loading="lazy" to all images */
|
|
|
|
// () => {
|
|
|
|
// return (tree) => {
|
|
|
|
// visit(tree, 'element', (node) => {
|
|
|
|
// if (node.tagName === 'img') {
|
|
|
|
// node.properties.loading = 'lazy';
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// };
|
|
|
|
// }
|
|
|
|
// ]
|
2023-11-08 22:56:48 +00:00
|
|
|
],
|
|
|
|
remarkPlugins: [
|
2024-02-13 15:42:36 +00:00
|
|
|
[remarkToc, { maxDepth: 3, tight: true }],
|
|
|
|
[
|
2024-04-27 23:13:28 +00:00
|
|
|
remarkFFF,
|
2023-11-08 22:56:48 +00:00
|
|
|
{
|
2024-04-27 23:13:28 +00:00
|
|
|
presets: [],
|
|
|
|
target: 'mdsvex',
|
|
|
|
autofill: {
|
|
|
|
provider: 'fs',
|
|
|
|
path: (path) => path.replace('/src/routes/', '/urara/')
|
|
|
|
},
|
|
|
|
strict: {
|
|
|
|
media: {
|
|
|
|
type: 'string',
|
|
|
|
array: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-11-08 22:56:48 +00:00
|
|
|
],
|
2024-04-27 23:13:28 +00:00
|
|
|
[readingTime, { wpm: 200 }],
|
|
|
|
[remarkFootnotes, { inlineNotes: true }]
|
2024-02-13 15:42:36 +00:00
|
|
|
// [
|
|
|
|
// headings,
|
|
|
|
// {
|
|
|
|
// behavior: 'append',
|
|
|
|
// linkProperties: {},
|
|
|
|
// content: function (node) {
|
|
|
|
// return [
|
|
|
|
// h('span.icon.icon-link header-anchor', {
|
|
|
|
// ariaLabel: toString(node) + ' permalink'
|
|
|
|
// })
|
|
|
|
// ];
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// ],
|
2024-03-16 09:12:50 +00:00
|
|
|
|
2024-02-13 15:42:36 +00:00
|
|
|
// remarkHeadingsPermaLinks,
|
|
|
|
// getHeadings
|
2023-11-08 22:56:48 +00:00
|
|
|
]
|
|
|
|
});
|
|
|
|
|
|
|
|
export default config;
|