-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: consolidate syntax highlighting code into standalone plugin
- Loading branch information
Showing
16 changed files
with
188 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* @prettier | ||
*/ | ||
import SyntaxHighlighter from "react-syntax-highlighter/dist/esm/light" | ||
import js from "react-syntax-highlighter/dist/esm/languages/hljs/javascript" | ||
import json from "react-syntax-highlighter/dist/esm/languages/hljs/json" | ||
import xml from "react-syntax-highlighter/dist/esm/languages/hljs/xml" | ||
import bash from "react-syntax-highlighter/dist/esm/languages/hljs/bash" | ||
import yaml from "react-syntax-highlighter/dist/esm/languages/hljs/yaml" | ||
import http from "react-syntax-highlighter/dist/esm/languages/hljs/http" | ||
import powershell from "react-syntax-highlighter/dist/esm/languages/hljs/powershell" | ||
import javascript from "react-syntax-highlighter/dist/esm/languages/hljs/javascript" | ||
|
||
const afterLoad = () => { | ||
SyntaxHighlighter.registerLanguage("json", json) | ||
SyntaxHighlighter.registerLanguage("js", js) | ||
SyntaxHighlighter.registerLanguage("xml", xml) | ||
SyntaxHighlighter.registerLanguage("yaml", yaml) | ||
SyntaxHighlighter.registerLanguage("http", http) | ||
SyntaxHighlighter.registerLanguage("bash", bash) | ||
SyntaxHighlighter.registerLanguage("powershell", powershell) | ||
SyntaxHighlighter.registerLanguage("javascript", javascript) | ||
} | ||
|
||
export default afterLoad |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/core/plugins/syntax-highlighting/components/SyntaxHighlighter.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* @prettier | ||
*/ | ||
import React from "react" | ||
import PropTypes from "prop-types" | ||
import ReactSyntaxHighlighter from "react-syntax-highlighter/dist/esm/light" | ||
import get from "lodash/get" | ||
|
||
const SyntaxHighlighter = ({ | ||
language, | ||
className = "", | ||
getSystem, | ||
children = null, | ||
}) => { | ||
const system = getSystem() | ||
const configs = system.getConfigs() | ||
const theme = get(configs, "syntaxHighlight.theme") | ||
const { styles, defaultStyle } = system.syntaxHighlighting | ||
const style = styles[theme] ?? defaultStyle | ||
|
||
return ( | ||
<ReactSyntaxHighlighter | ||
language={language} | ||
className={className} | ||
style={style} | ||
> | ||
{children} | ||
</ReactSyntaxHighlighter> | ||
) | ||
} | ||
|
||
SyntaxHighlighter.propTypes = { | ||
language: PropTypes.string.isRequired, | ||
className: PropTypes.string, | ||
getSystem: PropTypes.func.isRequired, | ||
children: PropTypes.node, | ||
} | ||
|
||
export default SyntaxHighlighter |
Oops, something went wrong.