Skip to content

Commit

Permalink
support jsonnet and jssm
Browse files Browse the repository at this point in the history
  • Loading branch information
JSerZANP committed Aug 13, 2023
1 parent f94e1bc commit 2ce3f44
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
6 changes: 3 additions & 3 deletions examples/web/components/CodeSnippet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ const ALL_LANGS = [
"json",
"json5",
"jsonc",
// "jsonnet",
// "jssm",
"jsonnet",
"jssm",
// "fsl",
// "jsx",
"julia",
Expand Down Expand Up @@ -303,7 +303,7 @@ export function CodeSnippet({ code: _code }: { code?: string }) {
const [selectedTheme, setTheme] = useState<(typeof themes)[number]>(
themes[0]
);
const [lang, setLang] = useState<shiki.Lang>("jsonc");
const [lang, setLang] = useState<shiki.Lang>("jssm");
const [code, setCode] = useState(_code ?? defaultCode[lang] ?? "");
useEffect(() => {
setCode(defaultCode[lang]);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<pre class="shiki github-light" style="color:#24292e;background-color:#fff"><div class="code-container"><code><div class="line"></div><div class="line"><span style="color: #24292E">{</span></div><div class="line"><span style="color: #24292E"> </span><span style="color: #6A737D">// This is a JSON5 object with comments</span></div><div class="line"><span style="color: #24292E"> </span><span style="color: #032F62">"name"</span><span style="color: #D73A49">:</span><span style="color: #24292E"> </span><span style="color: #032F62">"John"</span><span style="color: #24292E">,</span></div><div class="line dim"><span style="color: #24292E"> </span><span style="color: #032F62">"age"</span><span style="color: #D73A49">:</span><span style="color: #24292E"> </span><span style="color: #005CC5">30</span><span style="color: #24292E">,</span></div><div class="line"><span style="color: #24292E"> </span><span style="color: #032F62">"isStudent"</span><span style="color: #D73A49">:</span><span style="color: #24292E"> </span><span style="color: #005CC5">false</span><span style="color: #24292E">,</span></div><div class="shaku-underline shaku-underline-solid" style="left:3ch"><span class="shaku-underline-line" style="left:0ch">---------</span></div><div class="shaku-callout" style="left:2ch"><span class="shaku-callout-arrow" style="left:1ch"></span><p>Hello World!</p></div><div class="line"><span style="color: #24292E">}</span></div><div class="line"></div></code></div></pre>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<pre class="shiki github-light" style="color:#24292e;background-color:#fff"><div class="code-container"><code><div class="line"></div><div class="line dim"><span style="color: #6A737D">// coffee</span></div><div class="shaku-underline shaku-underline-solid" style="left:3ch"><span class="shaku-underline-line" style="left:0ch">------</span></div><div class="shaku-callout" style="left:3ch"><span class="shaku-callout-arrow" style="left:2ch"></span><p>Hello!</p></div><div class="line"></div></code></div></pre>
19 changes: 19 additions & 0 deletions packages/remark-shaku-code-annotate/src/defaultCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,25 @@ export default function Counter() {
// ^
//[Hello World!]
}
`,
jsonnet: `
{
// This is a JSON5 object with comments
"name": "John",
// @dim
"age": 30,
"isStudent": false,
// ---------
// ^
//[Hello World!]
}
`,
jssm: `
// @dim
// coffee
// ------
// ^
// [Hello!]
`,
julia: `
# @dim
Expand Down
8 changes: 7 additions & 1 deletion packages/remark-shaku-code-annotate/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ function parseComment(
// rather we can just try to trim for each lang?
if (
lang != null &&
["ada", "berry", "elm", "haml", "handlebars", "hlsl"].includes(lang)
["ada", "berry", "elm", "haml", "handlebars", "hlsl", "jssm"].includes(lang)
) {
body = line
.slice(shouldTreatFirstTokenOffset ? 1 : 0)
Expand Down Expand Up @@ -494,6 +494,12 @@ const commentMarkers: Record<string, { head?: RegExp; tail?: RegExp }> = {
json5: {
head: /^\s*\/\//,
},
jsonnet: {
head: /^\s*\/\//,
},
jssm: {
head: /^\s*\/\//,
},
rust: {
head: /^\s*\/\//,
},
Expand Down

1 comment on commit 2ce3f44

@vercel
Copy link

@vercel vercel bot commented on 2ce3f44 Aug 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

shaku-web – ./

shaku-web-git-main-jserzanp.vercel.app
shaku-web.vercel.app
shaku-web-jserzanp.vercel.app

Please sign in to comment.