mirror of
https://github.com/Steffo99/bluelib.git
synced 2024-12-22 11:34:21 +00:00
Add a default language context
This commit is contained in:
parent
47ba3e42b1
commit
d38c63da7e
2 changed files with 8 additions and 1 deletions
|
@ -1,10 +1,14 @@
|
|||
import SyntaxHighlighter from 'react-syntax-highlighter'
|
||||
import {monokai} from "react-syntax-highlighter/dist/cjs/styles/hljs";
|
||||
import stripTabs from "../../utils/stripTabs";
|
||||
import {useContext} from "preact/hooks";
|
||||
import CodeDefaultLanguage from "../../contexts/CodeDefaultLanguage";
|
||||
|
||||
export default function(props) {
|
||||
const language = useContext(CodeDefaultLanguage)
|
||||
|
||||
return (
|
||||
<SyntaxHighlighter language={props.language ? props.language : "plaintext"} style={monokai}>
|
||||
<SyntaxHighlighter language={props.language ? props.language : language} style={monokai}>
|
||||
{stripTabs(String(props.children))}
|
||||
</SyntaxHighlighter>
|
||||
)
|
||||
|
|
3
src/contexts/CodeDefaultLanguage.js
Normal file
3
src/contexts/CodeDefaultLanguage.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
import {createContext} from "preact";
|
||||
|
||||
export default createContext("plaintext");
|
Loading…
Reference in a new issue