summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-plugin-highlight/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/gitbook-plugin-highlight/src')
-rw-r--r--packages/gitbook-plugin-highlight/src/ALIASES.js12
-rw-r--r--packages/gitbook-plugin-highlight/src/CodeBlock.js15
-rw-r--r--packages/gitbook-plugin-highlight/src/getLanguage.js4
3 files changed, 21 insertions, 10 deletions
diff --git a/packages/gitbook-plugin-highlight/src/ALIASES.js b/packages/gitbook-plugin-highlight/src/ALIASES.js
index 799efef..565de36 100644
--- a/packages/gitbook-plugin-highlight/src/ALIASES.js
+++ b/packages/gitbook-plugin-highlight/src/ALIASES.js
@@ -1,9 +1,13 @@
+/**
+ * Common aliases also recognizes by GitHub.
+ * @type {Object}
+ */
const ALIASES = {
- 'py': 'python',
- 'js': 'javascript',
- 'json': 'javascript',
- 'rb': 'ruby',
+ 'py': 'python',
+ 'js': 'javascript',
+ 'json': 'javascript',
+ 'rb': 'ruby',
'csharp': 'cs'
};
diff --git a/packages/gitbook-plugin-highlight/src/CodeBlock.js b/packages/gitbook-plugin-highlight/src/CodeBlock.js
index a556d36..9e3b70d 100644
--- a/packages/gitbook-plugin-highlight/src/CodeBlock.js
+++ b/packages/gitbook-plugin-highlight/src/CodeBlock.js
@@ -10,7 +10,7 @@ const getLanguage = require('./getLanguage');
* @return {String}
*/
function getChildrenToText(children) {
- return React.Children.map(children, child => {
+ return React.Children.map(children, (child) => {
if (typeof child === 'string') {
return child;
} else {
@@ -20,18 +20,23 @@ function getChildrenToText(children) {
}).join('');
}
+/**
+ * Code block wrapper to highlight the code inside.
+ * @type {ReactClass}
+ */
const CodeBlock = React.createClass({
propTypes: {
children: React.PropTypes.node,
+ theme: React.PropTypes.string.isRequired,
className: React.PropTypes.string
},
render() {
- const { children, className } = this.props;
+ const { children, className, theme } = this.props;
const content = getChildrenToText(children);
const lang = getLanguage(className || '');
- const includeCSS = <GitBook.ImportCSS href="gitbook/highlight/white.css" />;
+ const includeCSS = <GitBook.ImportCSS href={`gitbook/highlight/${theme}.css`} />;
try {
const html = hljs.highlight(lang, content).value;
@@ -52,4 +57,6 @@ const CodeBlock = React.createClass({
}
});
-module.exports = CodeBlock;
+module.exports = GitBook.connect(CodeBlock, ({ config }) => ({
+ theme: config.getForPlugin('highlight').get('theme')
+}));
diff --git a/packages/gitbook-plugin-highlight/src/getLanguage.js b/packages/gitbook-plugin-highlight/src/getLanguage.js
index 7a1bf8e..6a1234f 100644
--- a/packages/gitbook-plugin-highlight/src/getLanguage.js
+++ b/packages/gitbook-plugin-highlight/src/getLanguage.js
@@ -11,7 +11,7 @@ const ALIASES = require('./ALIASES');
*/
function getLanguage(className) {
const lang = List(className.split(' '))
- .map(function(cl) {
+ .map((cl) => {
// Markdown
if (cl.search('lang-') === 0) {
return cl.slice('lang-'.length);
@@ -24,7 +24,7 @@ function getLanguage(className) {
return null;
})
- .find(function(cl) {
+ .find((cl) => {
return Boolean(cl);
});