// https://github.com/String10/Hakuba/blob/master/package.json
// import { defineMDSveXConfig as defineConfig } from "mdsvex";
// import type { Plugin, Settings } from 'unified';
import remarkGfm from "remark-gfm";
import remarkFrontmatter from "remark-frontmatter";
import remarkWikiLink from "remark-wiki-link";
import remarkMath from "remark-math"
// @ts-ignore
import remarkAbbr from "remark-abbr"
import remarkFootnotes from 'remark-footnotes'
import remarkCallouts from "remark-callouts";
import rehypeKatexSvelte from 'rehype-katex-svelte';
// import github from "remark-github";
import rehypeSlug from 'rehype-slug';
import remarkReadingTime from "remark-reading-time";
// import rehypeToc from '@jsdevtools/rehype-toc';
import { createHighlighter } from "@bitmachina/highlighter";
import { parse, format } from "node:path";
import slugify from 'slugify';
export const NOTE_ICON = '';
export const QUOTE_ICON = '';
export const INFO_ICON = '';
export const ICONS = {
note: NOTE_ICON,
quote: QUOTE_ICON,
info: INFO_ICON,
};
import { globSync } from 'glob'
import { readFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
const projects = globSync('node_modules/Notes/Projects/*.md')
.map((filepath) => {
return parse(filepath)
})
.map((path) => {
return format({
// ...path,
name: slugify(path.name, { lower: true }),
// base: undefined,
// root: "",
// ext: undefined,
// dir: path.dir.replace("/node_modules/Notes/Projects", "")
})
})
/**
* @type {string[]}
*/
const permalinks = projects.map((p) => "/projects/" + p)
// console.log(permalinks)
/**
* @param {string} pageName
* @returns {string[]}
*/
function pageResolver(pageName) {
const slug = slugify(pageName, { lower: true });
return ["/", "/projects/"].map((p) => p + slug);
}
import { grammars } from 'tm-grammars'
// console.log()
/**
* @param {string} name
*/
function getGrammar(name) {
const metadata = grammars.find((grammar) => grammar.name == name)
if (!metadata) {
throw "Grammar not found"
}
return {
...metadata,
id: name,
grammar: JSON.parse(readFileSync(fileURLToPath(import.meta.resolve('tm-grammars/grammars/' + name + '.json')), 'utf8')),
}
}
const hrefTemplate = (/** @type {string} */ permalink) => permalink
// function customizeTOC(toc) {
// // console.log(toc)
// return {
// type: 'root',
// children: [{
// type: "element",
// // tagName: "svelte:component",
// // properties: { this: "{tocComponent}" },
// tagName: "div",
// properties: {},
// children: [toc],
// }]
// };
// }
/**
* @param {{level: number, title: string}[]} headings
*/
function buildNestedHeadings(headings) {
/**
* @type {{level: number, title: string, children: unknown}[]}
*/
const result = [];
const stack = [{ level: 0, children: result }];
for (const heading of headings) {
while (
stack.length > 1 &&
heading.level <= stack[stack.length - 1].level
) {
stack.pop();
}
const parent = stack[stack.length - 1];
const newHeading = {
...heading,
children: [],
level: heading.level,
};
parent.children.push(newHeading);
stack.push(newHeading);
}
return result;
}
import { visit } from 'unist-util-visit';
import { toString as mdast_tree_to_string } from 'mdast-util-to-string'
import GithubSlugger from 'github-slugger'
/**
* @param {{ prefix?: string; }} opts
*/
function add_toc_remark(opts) {
const slugs = new GithubSlugger()
const prefix = opts?.prefix || "";
return async function transformer(tree, vFile) {
slugs.reset()
vFile.data.flattenedHeadings = [];
visit(tree, 'heading', (node) => {
const title = mdast_tree_to_string(node);
vFile.data.flattenedHeadings.push({
level: node.depth,
title,
id: prefix + slugs.slug(title)
});
});
if (!vFile.data.fm) vFile.data.fm = {};
vFile.data.fm.flattenedHeadings = vFile.data.flattenedHeadings;
vFile.data.fm.headings = buildNestedHeadings(vFile.data.flattenedHeadings);
};
}
function add_data_to_fm(_opts) {
return async function transformer(tree, vFile) {
if (!vFile.data.fm) vFile.data.fm = {};
vFile.data.fm.readingTime = vFile.data.readingTime;
};
}
import { toString as hast_tree_to_string } from 'hast-util-to-string'
/**
* Determines whether the given node is an HTML element.
*/
function isHtmlElementNode(node) {
return typeof node === "object" &&
node.type === "element" &&
typeof node.tagName === "string" &&
"properties" in node &&
typeof node.properties === "object";
}
const HEADINGS = ["h1", "h2", "h3", "h4", "h5", "h6"]
/**
* Determines whether the given node is an HTML heading node, according to the specified options
*/
function isHeadingNode(node) {
return isHtmlElementNode(node) && HEADINGS.includes(node.tagName);
}
function add_toc_rehype(self, opts) {
return async function transformer(tree, vFile) {
// console.log(tree)
vFile.data.headings = [];
visit(tree, isHeadingNode, (node) => {
// console.log(node)
vFile.data.headings.push({
level: node.depth,
title: hast_tree_to_string(node),
});
});
if (!vFile.data.fm) vFile.data.fm = {};
vFile.data.fm.headings = vFile.data.headings;
};
}
import toCamel from "just-camel-case";
const RE_SCRIPT_START =
/`,
})
}
};
}
/**
* @type {import("mdsvex").MdsvexOptions}
*/
const config = {
extensions: [".svelte.md", ".md", ".svx"],
// fences: true,
// ruleSpaces: false,
smartypants: {
dashes: "oldschool",
},
layout: {
_: "./src/lib/mdlayouts/default.svelte"
},
highlight: {
// @ts-ignore
highlighter: await createHighlighter({ theme: "github-dark", langs: ["http", "jsx", "javascript", "typescript", "rust"].map(getGrammar) }),
alias: {
ts: "typescript",
mdx: "markdown",
svelte: "svelte",
svx: "svx",
mdsvex: "svx",
sig: "ts",
}
},
remarkPlugins: [
// remarkFrontmatter,
// [github, {repository}],
remarkMath,
remarkAbbr,
[remarkFootnotes, { inlineNotes: true }],
remarkGfm,
[remarkCallouts, {}],
[remarkWikiLink, {
// @ts-ignore
aliasDivider: "|",
permalinks,
pageResolver,
hrefTemplate,
// wikiLinkClassName,
// newClassName,
}],
// [citePlugin, {
// syntax: {
// // see micromark-extension-cite
// enableAltSyntax: false,
// enablePandocSyntax: true,
// },
// toMarkdown: {
// // see mdast-util-cite
// standardizeAltSyntax: false,
// enableAuthorSuppression: true,
// useNodeValue: false,
// },
// }],
// [remarkBibliography, { bibliography }],
// [remarkMermaid, {}]
remarkReadingTime,
add_data_to_fm,
[add_toc_remark, { prefix: "h-" }]
],
rehypePlugins: [
// @ts-ignore
rehypeKatexSvelte,
// @ts-ignore
[rehypeSlug, { prefix: "h-" }],
vite_images_rehype
],
};
export default config;