summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-plugin-highlight/src
diff options
context:
space:
mode:
authorSamy Pesse <samypesse@gmail.com>2016-10-04 18:53:58 +0200
committerSamy Pesse <samypesse@gmail.com>2016-10-04 18:53:58 +0200
commita863b55c798b4dc0a177fe1ada9cd428f1a5444d (patch)
tree0a3a41543bfc31527d4f4c19f5473df7afbff0ea /packages/gitbook-plugin-highlight/src
parent16ca48b2c05dad0af4cec600cee69adcafcf255f (diff)
downloadgitbook-a863b55c798b4dc0a177fe1ada9cd428f1a5444d.zip
gitbook-a863b55c798b4dc0a177fe1ada9cd428f1a5444d.tar.gz
gitbook-a863b55c798b4dc0a177fe1ada9cd428f1a5444d.tar.bz2
Start new highlight.js plugin
Diffstat (limited to 'packages/gitbook-plugin-highlight/src')
-rw-r--r--packages/gitbook-plugin-highlight/src/CodeBlock.js15
-rw-r--r--packages/gitbook-plugin-highlight/src/getLanguage.js30
-rw-r--r--packages/gitbook-plugin-highlight/src/index.js9
3 files changed, 54 insertions, 0 deletions
diff --git a/packages/gitbook-plugin-highlight/src/CodeBlock.js b/packages/gitbook-plugin-highlight/src/CodeBlock.js
new file mode 100644
index 0000000..f55524f
--- /dev/null
+++ b/packages/gitbook-plugin-highlight/src/CodeBlock.js
@@ -0,0 +1,15 @@
+const GitBook = require('gitbook-core');
+const { React } = GitBook;
+
+const CodeBlock = React.createClass({
+ propTypes: {
+ children: React.PropTypes.children
+ },
+
+ render() {
+ const { children } = this.props;
+ return <span />;
+ }
+});
+
+module.exports = CodeBlock;
diff --git a/packages/gitbook-plugin-highlight/src/getLanguage.js b/packages/gitbook-plugin-highlight/src/getLanguage.js
new file mode 100644
index 0000000..47b68cf
--- /dev/null
+++ b/packages/gitbook-plugin-highlight/src/getLanguage.js
@@ -0,0 +1,30 @@
+const GitBook = require('gitbook-core');
+const { List } = GitBook.Immutable;
+
+/**
+ * Return language for a code blocks from a list of class names
+ *
+ * @param {Array<String>}
+ * @return {String}
+ */
+function getLanguage(classNames) {
+ return List(classNames)
+ .map(function(cl) {
+ // Markdown
+ if (cl.search('lang-') === 0) {
+ return cl.slice('lang-'.length);
+ }
+
+ // Asciidoc
+ if (cl.search('language-') === 0) {
+ return cl.slice('language-'.length);
+ }
+
+ return null;
+ })
+ .find(function(cl) {
+ return Boolean(cl);
+ });
+}
+
+module.exports = getLanguage;
diff --git a/packages/gitbook-plugin-highlight/src/index.js b/packages/gitbook-plugin-highlight/src/index.js
new file mode 100644
index 0000000..3f17c42
--- /dev/null
+++ b/packages/gitbook-plugin-highlight/src/index.js
@@ -0,0 +1,9 @@
+const GitBook = require('gitbook-core');
+const CodeBlock = require('./CodeBlock');
+
+module.exports = GitBook.createPlugin({
+ activate: (dispatch, getState, { Components }) => {
+ dispatch(Components.registerComponent(CodeBlock, { role: 'html:code' }));
+ },
+ reduce: (state, action) => state
+});