diff --git a/src/lib/utils/get-headings.js b/src/lib/utils/get-headings.js deleted file mode 100644 index 420dad0..0000000 --- a/src/lib/utils/get-headings.js +++ /dev/null @@ -1,51 +0,0 @@ -import { toString } from 'mdast-util-to-string'; -import { visit } from 'unist-util-visit'; - -export default () => (tree, vFile) => { - let headers = []; - visit(tree, (node) => { - if (node.type === 'heading') { - if (node.depth !== 1) { - const sanitizedString = toString(node).replace( - /{(.*?)}/, - (_, token) => { - return vFile.data.fm[token] || token; - }, - ); - headers.push({ - title: sanitizedString, - level: node.depth, - slug: node.data.id, - children: [], - }); - } - } - }); - - const stack = []; - const sortedHeaders = []; - - //const sort Header to tree - const sortHeader = (header) => { - while (stack.length !== 0 && header.level <= stack[0].level) { - stack.shift(); - } - - if (stack.length === 0) { - sortedHeaders.push(header); - stack.push(header); - } else { - (stack[0].children ??= []).push(header); - stack.unshift(header); - } - }; - - headers.forEach((_, index) => { - const header = headers[index]; - sortHeader(header); - }); - - if (!vFile.data.fm) vFile.data.fm = {}; - vFile.data.fm.headings = sortedHeaders; - return tree; -}; diff --git a/src/lib/utils/highlight.js b/src/lib/utils/highlight.js deleted file mode 100644 index e0d867b..0000000 --- a/src/lib/utils/highlight.js +++ /dev/null @@ -1,45 +0,0 @@ -import Prism from 'prismjs'; -import 'prismjs/components/prism-docker.min.js'; -import 'prismjs/components/prism-bash.min.js'; -import 'prismjs/components/prism-yaml.min.js'; -import 'prismjs/components/prism-javascript.min.js'; -import 'prismjs/components/prism-json.min.js'; -import 'prismjs/components/prism-markdown.min.js'; -import 'prismjs/components/prism-sql.min.js'; -import 'prismjs/components/prism-toml.min.js'; -import 'prismjs/components/prism-promql.min.js'; -import 'prismjs/components/prism-go.min.js'; -import 'prismjs/components/prism-typescript.min.js'; -import 'prismjs/components/prism-python.min.js'; -import { escapeSvelte } from 'mdsvex'; - -const langMap = { - sh: 'bash', - Dockerfile: 'dockerfile', - YAML: 'yaml', -}; - -/** - * - * @param {string} code the code that gets parsed - * @param {string} lang the language the code is written in - * @param {string} meta meta information for the code fence - * @returns {string} - */ -export function highlightCode(code, lang, meta) { - let title = null; - const _lang = langMap[lang] || lang || ''; - - if (meta) { - title = meta.match(/title="?(.*?)"/)?.[1]; - } - - const highlighted = _lang - ? escapeSvelte(Prism.highlight(code, Prism.languages[_lang], _lang)) - : code; - return ``; -} diff --git a/src/lib/utils/mdsvex-global-components.js b/src/lib/utils/mdsvex-global-components.js deleted file mode 100644 index 58c684a..0000000 --- a/src/lib/utils/mdsvex-global-components.js +++ /dev/null @@ -1,73 +0,0 @@ -/** - * Credit goes to @Xananax for providing this solution within the gist https://gist.github.com/Xananax/5dca3a1dd7070e4fdebe2927e4aeb55b - */ -import { join, basename, extname } from 'path'; - -export const defaults = { - extensions: ['.svelte.md', '.md', '.svx'], - dir: `$lib`, - list: [], -}; - -/** - * Injects global imports in all your mdsvex files - * Specify: - * - the root dir (defaults to `src/lib`) - * - the array list of components (with extension), like `['Component.svelte']` - * - the valid extensions list as an array (defaults to `['.svelte.md', '.md', '.svx']`) - * - * If you want the component name to be different from the file name, you can specify an array - * of arrays: `['Component.svelte', ['Another', 'AnotherComp.svelte'], 'ThirdComp.svelte']` - * - * @param {Object} options options described above - * @returns a preprocessor suitable to plug into the `preprocess` key of the svelte config - */ -export const mdsvexGlobalComponents = (options = {}) => { - const { extensions, dir, list } = { ...defaults, ...options }; - const extensionsRegex = new RegExp( - '(' + extensions.join('|').replace(/\./g, '\\.') + ')$', - 'i', - ); - - if (!list || !list.length || !Array.isArray(list)) { - throw new Error( - `"list" option must be an array and contain at least one element`, - ); - } - - const imports = list - .map((entry) => { - let name = ''; - if (Array.isArray(entry)) { - name = entry[0]; - entry = entry[1]; - } - const ext = extname(entry); - const path = join(dir, entry); - name = name || basename(entry, ext); - return `\nimport ${name} from "${path}"`; - }) - .join('\n'); - - const preprocessor = { - script(thing) { - const { content, filename, attributes, markup } = thing; - if (!filename.match(extensionsRegex)) { - return { code: content }; - } - const hasModuleContext = /^