Don't try and highlight plain text
This commit is contained in:
parent
f1bdfaade9
commit
2bac7f434e
2 changed files with 26 additions and 20 deletions
|
@ -21,9 +21,12 @@ export const group = style({
|
||||||
|
|
||||||
export const line_numbers = style({
|
export const line_numbers = style({
|
||||||
margin: '0',
|
margin: '0',
|
||||||
marginRight: '0.5em',
|
marginRight: '1em',
|
||||||
paddingRight: '0.5em',
|
|
||||||
color: colors.foreground2,
|
color: colors.foreground2,
|
||||||
textAlign: 'right',
|
textAlign: 'right',
|
||||||
userSelect: 'none',
|
userSelect: 'none',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const plain = style({
|
||||||
|
margin: 0,
|
||||||
|
});
|
||||||
|
|
|
@ -38,7 +38,6 @@ const type_map = {
|
||||||
json: 'json',
|
json: 'json',
|
||||||
md: 'markdown',
|
md: 'markdown',
|
||||||
markdown: 'markdown',
|
markdown: 'markdown',
|
||||||
none: 'none',
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function map_to_type(extension?: string) {
|
export function map_to_type(extension?: string) {
|
||||||
|
@ -68,24 +67,28 @@ export default function Text({ language, text, line_numbers }: { language: strin
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log(language, language in type_map);
|
||||||
return <div className={style.group}>
|
return <div className={style.group}>
|
||||||
{line_numbers ? <p className={style.line_numbers}>{lines.map((_, index) => `${index}\n`)}</p> : <></>}
|
{line_numbers ? <p className={style.line_numbers}>{lines.map((_, index) => `${index}\n`)}</p> : <></>}
|
||||||
<Highlight
|
{language in type_map ?
|
||||||
theme={themes[light_theme ? 'nightOwlLight' : 'oneDark']}
|
<Highlight
|
||||||
code={text}
|
theme={themes[light_theme ? 'nightOwlLight' : 'oneDark']}
|
||||||
language={language}
|
code={text}
|
||||||
>
|
language={language}
|
||||||
{({ tokens, getLineProps, getTokenProps }) => (
|
>
|
||||||
<div>
|
{({ tokens, getLineProps, getTokenProps }) => (
|
||||||
{tokens.map((line, i) => (
|
<div>
|
||||||
<div key={i} {...getLineProps({ line })}>
|
{tokens.map((line, i) => (
|
||||||
{line.map((token, key) => (
|
<div key={i} {...getLineProps({ line })}>
|
||||||
<span key={key} {...getTokenProps({ token })} />
|
{line.map((token, key) => (
|
||||||
))}
|
<span key={key} {...getTokenProps({ token })} />
|
||||||
</div>
|
))}
|
||||||
))}
|
</div>
|
||||||
</div>
|
))}
|
||||||
)}
|
</div>
|
||||||
</Highlight>
|
)}
|
||||||
|
</Highlight> :
|
||||||
|
<p className={style.plain}>{text}</p>
|
||||||
|
}
|
||||||
</div>;
|
</div>;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue