diff options
Diffstat (limited to 'packages/gitbook-plugin-highlight')
-rw-r--r-- | packages/gitbook-plugin-highlight/.gitignore | 31 | ||||
-rw-r--r-- | packages/gitbook-plugin-highlight/.npmignore | 2 | ||||
-rw-r--r-- | packages/gitbook-plugin-highlight/index.js | 10 | ||||
-rw-r--r-- | packages/gitbook-plugin-highlight/package.json | 28 | ||||
-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 |
7 files changed, 125 insertions, 0 deletions
diff --git a/packages/gitbook-plugin-highlight/.gitignore b/packages/gitbook-plugin-highlight/.gitignore new file mode 100644 index 0000000..ef47881 --- /dev/null +++ b/packages/gitbook-plugin-highlight/.gitignore @@ -0,0 +1,31 @@ +# Logs +logs +*.log + +# Runtime data +pids +*.pid +*.seed + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directory +# Deployed apps should consider commenting this line out: +# see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git +node_modules + +# vim swapfile +*.swp + +# Plugin assets +_assets/plugin.js diff --git a/packages/gitbook-plugin-highlight/.npmignore b/packages/gitbook-plugin-highlight/.npmignore new file mode 100644 index 0000000..a0e53cf --- /dev/null +++ b/packages/gitbook-plugin-highlight/.npmignore @@ -0,0 +1,2 @@ +# Publish assets on NPM +!_assets/plugin.js diff --git a/packages/gitbook-plugin-highlight/index.js b/packages/gitbook-plugin-highlight/index.js new file mode 100644 index 0000000..e542ae8 --- /dev/null +++ b/packages/gitbook-plugin-highlight/index.js @@ -0,0 +1,10 @@ + +module.exports = { + blocks: { + + }, + + hooks: { + + } +}; diff --git a/packages/gitbook-plugin-highlight/package.json b/packages/gitbook-plugin-highlight/package.json new file mode 100644 index 0000000..c366194 --- /dev/null +++ b/packages/gitbook-plugin-highlight/package.json @@ -0,0 +1,28 @@ +{ + "name": "gitbook-plugin-highlight", + "description": "Syntax highlighter for Gitbook", + "main": "index.js", + "browser": "./_assets/plugin.js", + "version": "2.0.2", + "dependencies": { + "gitbook-core": "^0.0.0" + }, + "devDependencies": { + "gitbook-plugin": "*" + }, + "engines": { + "gitbook": ">=3.0.0" + }, + "scripts": { + "build-js": "gitbook-plugin build ./src/index.js ./_assets/plugin.js", + "prepublish": "npm run build-js" + }, + "homepage": "https://github.com/GitbookIO/gitbook", + "repository": { + "type": "git", + "url": "https://github.com/GitbookIO/gitbook.git" + }, + "bugs": { + "url": "https://github.com/GitbookIO/gitbook/issues" + } +} 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 +}); |