Skip to content

Commit aa20826

Browse files
committed
feat: support console language option in highlighting (#237)
* feat: support console language with $ handling * fix: hydrate correctly in client entry
1 parent df22132 commit aa20826

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

api/src/bundler/plugins/rehype-code-blocks.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,19 @@ export default function rehypeCodeBlocks(): (ast: Node) => void {
1818
}
1919

2020
const language = getLanguage(node);
21+
2122
const raw = toString(node);
2223

23-
// Raw value of the `code` block - used for copy/paste
24-
parent.properties['raw'] = raw;
25-
parent.properties['html'] = highlighter.codeToHtml(raw, language);
24+
// If the user provides the `console` language, we add the 'shell' language and remove $ from the raw code, for copying purposes.
25+
if (language === 'console') {
26+
const removedDollarSymbol = raw.replace(/^(^ *)\$/g, '');
27+
28+
parent.properties['raw'] = removedDollarSymbol;
29+
parent.properties['html'] = highlighter.codeToHtml(raw, { lang: 'shell' });
30+
} else {
31+
parent.properties['raw'] = raw;
32+
parent.properties['html'] = highlighter.codeToHtml(raw, { lang: language });
33+
}
2634

2735
// Get any metadata from the code block
2836
const meta = (node.data?.meta as string) ?? '';

website/app/entry.client.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,8 @@ if (
1919
delete window.__remixManifest.routes['routes/preview-fetch'];
2020
}
2121

22-
const container = document.getElementById('app');
23-
if (!container) {
24-
throw new Error('No element with id "app" found');
25-
}
26-
2722
hydrateRoot(
28-
container,
23+
document,
2924
<BrowserRouter>
3025
<RemixBrowser />
3126
</BrowserRouter>,

0 commit comments

Comments
 (0)