Skip to content

Commit 12cecee

Browse files
committed
Add syntax highlighting example
1 parent 2b6de0d commit 12cecee

File tree

4 files changed

+53
-4
lines changed

4 files changed

+53
-4
lines changed

content/github/getting-started-with-github/access-permissions-on-github.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ A repository owned by a user account has two permission levels: the *repository
1818

1919
### Organization accounts
2020
<!--react-->
21-
<CodeBlock>
21+
<CodeBlock language="javascript">
2222
{`var i;
2323
for (i = 0; i < cars.length; i++) {
2424
text += cars[i] + "<br>";

package-lock.json

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"querystring": "^0.2.0",
7070
"react": "^16.14.0",
7171
"react-dom": "^16.14.0",
72+
"react-syntax-highlighter": "^15.2.1",
7273
"readline-sync": "^1.4.10",
7374
"resolve-url-loader": "^3.1.1",
7475
"rimraf": "^3.0.0",

react/CodeBlock.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
const React = require('react')
22
const ReactDOM = require('react-dom')
3+
const { Prism } = require('react-syntax-highlighter')
4+
const { dark } = require('react-syntax-highlighter/dist/cjs/styles/prism')
35

46
const CodeBlock = (props) => {
57
return (
6-
<pre>
8+
<Prism language={props.language} style={dark}>
79
{props.children}
8-
</pre>
10+
</Prism>
911
)
1012
}
1113

@@ -14,7 +16,8 @@ if (typeof window === 'undefined') {
1416
const componentContainers = document.querySelectorAll('.react-component-codeblock')
1517

1618
for (const componentContainer of componentContainers) {
17-
ReactDOM.render(React.createElement(CodeBlock, {}, componentContainer.children[0].innerText), componentContainer)
19+
// clientside rendering breaks the syntax highlighting so turned it off... since this is not an interactive component
20+
//ReactDOM.render(React.createElement(CodeBlock, {}, componentContainer.children[0].innerText), componentContainer)
1821
}
1922
}
2023

0 commit comments

Comments
 (0)