Skip to content

feat: enable highlighting for json, jsonc, toml, yaml #1399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/site-kit/src/lib/markdown/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,10 @@ async function syntax_highlight({
html = replace_blank_lines(html);
} else {
const highlighted = highlighter.codeToHtml(source, {
lang: SHIKI_LANGUAGE_MAP[language as keyof typeof SHIKI_LANGUAGE_MAP],
// fallback to the passing the language as is if it doesn't exist in our map
// this ensures we get an error if we're using an unsupported language
// rather than silently not highlighting the code block as expected
lang: SHIKI_LANGUAGE_MAP[language as keyof typeof SHIKI_LANGUAGE_MAP] ?? language,
theme
});

Expand Down
8 changes: 7 additions & 1 deletion packages/site-kit/src/lib/markdown/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ import json5 from 'json5';
export const SHIKI_LANGUAGE_MAP = {
bash: 'bash',
env: 'bash',
yaml: 'yaml',
toml: 'toml',
html: 'svelte',
svelte: 'svelte',
sv: 'svelte',
css: 'css',
js: 'javascript',
json: 'javascript',
jsonc: 'javascript',
dts: 'typescript',
css: 'css',
ts: 'typescript',
// TODO: find a highlighter for tree syntax
tree: '',
'': ''
};

Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy