From 4cf881de70f88d8da9144e0d95ab26f8abc83906 Mon Sep 17 00:00:00 2001 From: pheralb Date: Sun, 13 Jul 2025 20:42:54 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9A=99=EF=B8=8F=20Separate=20markdown=20conf?= =?UTF-8?q?ig=20in=20another=20file,=20create=20custom=20config.js=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- markdown.config.js | 51 ++++++++++++++++++++++++++++++++++++++++++++++ svelte.config.js | 51 +++------------------------------------------- 2 files changed, 54 insertions(+), 48 deletions(-) create mode 100644 markdown.config.js diff --git a/markdown.config.js b/markdown.config.js new file mode 100644 index 0000000..00054a0 --- /dev/null +++ b/markdown.config.js @@ -0,0 +1,51 @@ +import { escapeSvelte } from 'mdsvex'; +import { createHighlighter, makeSingletonHighlighter } from 'shiki'; + +// Markdown Plugins +import remarkGfm from 'remark-gfm'; +import rehypeSlug from 'rehype-slug'; +import rehypeAutolinkHeadings from 'rehype-autolink-headings'; + +// Highlighter +const getHighlighter = makeSingletonHighlighter(createHighlighter); + +/** @type {import('mdsvex').MdsvexOptions} */ +const mdsvexOptions = { + remarkPlugins: [[remarkGfm]], + rehypePlugins: [ + [rehypeSlug], + [ + rehypeAutolinkHeadings, + { + behavior: 'wrap', + properties: { + className: [ + `before:content-['#'] before:absolute before:-ml-[1em] before:text-neutral-100/0 hover:before:text-neutral-200/50 pl-[1em] -ml-[1em]` + ] + } + } + ] + ], + extensions: ['.md'], + highlight: { + highlighter: async (code, lang = 'text') => { + const highlighter = await getHighlighter({ + themes: ['github-light', 'github-dark'], + langs: ['javascript', 'typescript', 'bash', 'json'] + }); + await highlighter.loadLanguage('javascript', 'typescript', 'bash'); + const html = escapeSvelte( + highlighter.codeToHtml(code, { + lang, + themes: { + light: 'github-light', + dark: 'github-dark' + } + }) + ); + return `{@html \`${html}\` }`; + } + } +}; + +export { mdsvexOptions }; diff --git a/svelte.config.js b/svelte.config.js index 4d22dda..d030e20 100644 --- a/svelte.config.js +++ b/svelte.config.js @@ -4,55 +4,10 @@ import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'; import adapter from '@sveltejs/adapter-node'; // ๐Ÿ“ฆ Extensions: -import { mdsvex, escapeSvelte } from 'mdsvex'; -import { createHighlighter, makeSingletonHighlighter } from 'shiki'; +import { mdsvex } from 'mdsvex'; -// ๐ŸŽจ Markdown Plugins: -import remarkGfm from 'remark-gfm'; -import rehypeAutolinkHeadings from 'rehype-autolink-headings'; -import rehypeSlug from 'rehype-slug'; - -// ๐Ÿ“„ Markdown config: -const getHighlighter = makeSingletonHighlighter(createHighlighter); - -/** @type {import('mdsvex').MdsvexOptions} */ -const mdsvexOptions = { - remarkPlugins: [[remarkGfm]], - rehypePlugins: [ - [rehypeSlug], - [ - rehypeAutolinkHeadings, - { - behavior: 'wrap', - properties: { - className: [ - `before:content-['#'] before:absolute before:-ml-[1em] before:text-neutral-100/0 hover:before:text-neutral-200/50 pl-[1em] -ml-[1em]` - ] - } - } - ] - ], - extensions: ['.md'], - highlight: { - highlighter: async (code, lang = 'text') => { - const highlighter = await getHighlighter({ - themes: ['github-light', 'github-dark'], - langs: ['javascript', 'typescript', 'bash', 'json'] - }); - await highlighter.loadLanguage('javascript', 'typescript', 'bash'); - const html = escapeSvelte( - highlighter.codeToHtml(code, { - lang, - themes: { - light: 'github-light', - dark: 'github-dark' - } - }) - ); - return `{@html \`${html}\` }`; - } - } -}; +// ๐Ÿ“„ Markdown Config: +import { mdsvexOptions } from './markdown.config.js'; // ๐Ÿงก Svelte config: /** @type {import('@sveltejs/kit').Config} */