feat(notes): render code files with Shikiji syntax highlighting
Non-markdown files opened as stacked notes are now highlighted using the existing markdown-it-shikiji pipeline (4-backtick fence wrapping) with a h1 filename heading. Edit controls are hidden for code files. Adds alloy language grammar and a fileLanguage utility mapping extensions to Shikiji language IDs.
This commit is contained in:
31
src/utils/fileLanguage.ts
Normal file
31
src/utils/fileLanguage.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
const EXT_TO_LANG: Record<string, string> = {
|
||||
sh: "bash",
|
||||
bash: "bash",
|
||||
js: "javascript",
|
||||
mjs: "javascript",
|
||||
cjs: "javascript",
|
||||
ts: "typescript",
|
||||
mts: "typescript",
|
||||
cts: "typescript",
|
||||
md: "markdown",
|
||||
mdx: "markdown",
|
||||
html: "html",
|
||||
htm: "html",
|
||||
css: "css",
|
||||
scss: "css",
|
||||
json: "json",
|
||||
jsonc: "json",
|
||||
als: "alloy"
|
||||
}
|
||||
|
||||
const MARKDOWN_EXTS = new Set(["md", "mdx"])
|
||||
|
||||
export function isMarkdownPath(path: string): boolean {
|
||||
const ext = path.split(".").pop()?.toLowerCase() ?? ""
|
||||
return MARKDOWN_EXTS.has(ext)
|
||||
}
|
||||
|
||||
export function getFileLanguage(path: string): string | null {
|
||||
const ext = path.split(".").pop()?.toLowerCase() ?? ""
|
||||
return EXT_TO_LANG[ext] ?? null
|
||||
}
|
||||
Reference in New Issue
Block a user