diff options
Diffstat (limited to 'packages/gitbook-plugin-highlight/src')
-rw-r--r-- | packages/gitbook-plugin-highlight/src/CodeBlock.js | 15 | ||||
-rw-r--r-- | packages/gitbook-plugin-highlight/src/getLanguage.js | 30 | ||||
-rw-r--r-- | packages/gitbook-plugin-highlight/src/index.js | 9 |
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 +}); |