Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

enable syntax highlighting for source plugin #384

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions examples/dev/webpack.dev.babel.js
Expand Up @@ -5,6 +5,7 @@ import CarteBlanche from '../../webpack-plugin/index';
import autoprefixer from 'autoprefixer';

import ReactPlugin from '../../plugins/react/dist/plugin';
import SourcePlugin from '../../plugins/source/plugin';

export default {
devtool: 'inline-source-map',
Expand All @@ -29,6 +30,7 @@ export default {
componentRoot: './src/components/',
plugins: [
new ReactPlugin(),
new SourcePlugin(),
],
}),
],
Expand All @@ -45,6 +47,12 @@ export default {
path.join(__dirname, '../../webpack-plugin'),
path.join(__dirname, '../../plugins'),
],
}, {
test: /highlight.*\.css/,
loader: 'style!css!postcss',
include: [
path.join(__dirname, '../../plugins'),
],
}, {
test: /\.css/,
loader: 'style!css?modules&importLoaders=1&localIdentName=[local]__[path][name]__[hash:base64:5]!postcss-loader', // eslint-disable-line max-len
Expand All @@ -53,6 +61,9 @@ export default {
path.join(__dirname, '../../webpack-plugin'),
path.join(__dirname, '../../plugins'),
],
exclude: [
/highlight.*\.css/,
],
}, {
test: /\.(png|jpg|gif)$/,
loaders: ['url?limit=10000'],
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -119,6 +119,7 @@
"file-loader": "^0.9.0",
"flow-bin": "^0.27.0",
"fs": "0.0.2",
"highlight.js": "^9.5.0",
"html-loader": "^0.4.3",
"html-webpack-plugin": "^2.19.0",
"immutable": "^3.8.1",
Expand Down
12 changes: 11 additions & 1 deletion plugins/source/component.js
@@ -1,5 +1,15 @@
import React from 'react';
import hljs from 'highlight.js';
import 'highlight.js/styles/github-gist.css';

export default function sourceFrontend(frontendData, pluginData) {
return (<pre>{pluginData.source}</pre>);
const { value, language } = hljs.highlightAuto(pluginData.source);
return (
<div style={{ width: '90%', margin: 'auto' }}>
<pre
className={`hljs ${language}`}
dangerouslySetInnerHTML={{ __html: value }}
/>
</div>
);
}
5 changes: 3 additions & 2 deletions plugins/source/package.json
Expand Up @@ -34,7 +34,8 @@
},
"dependencies": {
"carte-blanche": "^0.3.0",
"webpack": ">=1 <3 || ^2.1.0-beta",
"react": "^15.0.1"
"highlight.js": "^9.5.0",
"react": "^15.0.1",
"webpack": ">=1 <3 || ^2.1.0-beta"
}
}