Skip to content

Commit

Permalink
🐛 Recognize html as a language (#71)
Browse files Browse the repository at this point in the history
- convert to xml in the renderer
  • Loading branch information
rowanc1 committed May 9, 2023
1 parent 45bf7b5 commit dc9fd53
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/eleven-toes-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'myst-to-react': patch
---

Add html --> xml and md --> markdown conversion in lang syntax
2 changes: 1 addition & 1 deletion packages/myst-demo/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ export function MySTRenderer({
ref={area}
value={text}
className={classnames(
'block p-6 shadow-inner resize-none w-full font-mono bg-slate-50 dark:bg-slate-800 outline-none',
'block p-6 shadow-inner resize-none w-full font-mono bg-slate-50/50 dark:bg-slate-800/50 outline-none',
{ 'h-full': column },
)}
onChange={(e) => setText(e.target.value)}
Expand Down
11 changes: 10 additions & 1 deletion packages/myst-to-react/src/code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ type Props = {
className?: string;
};

function normalizeLanguage(lang?: string): string | undefined {
switch (lang) {
case 'html':
return 'xml';
default:
return lang;
}
}

export function CodeBlock(props: Props) {
const { isLight } = useTheme();
const {
Expand All @@ -45,7 +54,7 @@ export function CodeBlock(props: Props) {
>
{filename && <div className="leading-3 mt-1 p-1">{filename}</div>}
<SyntaxHighlighter
language={lang}
language={normalizeLanguage(lang)}
startingLineNumber={startingLineNumber}
showLineNumbers={showLineNumbers}
style={isLight ? light : dark}
Expand Down
1 change: 1 addition & 0 deletions packages/myst-to-react/src/links/github.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function extToLanguage(ext?: string): string | undefined {
ts: 'typescript',
js: 'javascript',
py: 'python',
md: 'markdown',
}[ext ?? ''] ?? ext
);
}
Expand Down

0 comments on commit dc9fd53

Please sign in to comment.