diff --git a/src/components/code/index.js b/src/components/code/index.js new file mode 100644 index 0000000..6628dfe --- /dev/null +++ b/src/components/code/index.js @@ -0,0 +1,30 @@ +import Intact from 'intact'; +import template from './index.vdt'; +import hljs from 'highlight.js/lib/highlight'; +import stylus from 'highlight.js/lib/languages/stylus'; +import js from 'highlight.js/lib/languages/javascript'; +import html from 'highlight.js/lib/languages/xml'; +import 'highlight.js/styles/color-brewer.css'; + +hljs.registerLanguage('stylus', stylus); +hljs.registerLanguage('js', js); +hljs.registerLanguage('html', html); + +export default class Code extends Intact { + @Intact.template() + static template = template; + + defaults() { + return { + language: 'stylus', + }; + } + + _mount() { + this.on('$changed:code', () => { + hljs.highlightBlock(this.refs.code); + }); + hljs.highlightBlock(this.refs.code); + } +} + diff --git a/src/components/code/index.vdt b/src/components/code/index.vdt new file mode 100644 index 0000000..9295def --- /dev/null +++ b/src/components/code/index.vdt @@ -0,0 +1,5 @@ +
+
+ {{ self.get('code') }}
+
+
diff --git a/src/components/codePreview/index.js b/src/components/codePreview/index.js
index e716c33..50d4022 100644
--- a/src/components/codePreview/index.js
+++ b/src/components/codePreview/index.js
@@ -1,29 +1,8 @@
import Intact from 'intact';
import template from './index.vdt';
import './index.styl';
-import hljs from 'highlight.js/lib/highlight';
-import stylus from 'highlight.js/lib/languages/stylus';
-import 'highlight.js/styles/color-brewer.css';
-
-hljs.registerLanguage('stylus', stylus);
-
-class Code extends Intact {
- @Intact.template()
- static template = `{self.get('code')}
`;
-
- _mount() {
- this.on('$changed:code', () => {
- hljs.highlightBlock(this.refs.code);
- });
- hljs.highlightBlock(this.refs.code);
- }
-}
export default class CodePreview extends Intact {
@Intact.template()
static template = template;
-
- _init() {
- this.Code = Code;
- }
}
diff --git a/src/components/codePreview/index.vdt b/src/components/codePreview/index.vdt
index 14bddd7..c007205 100644
--- a/src/components/codePreview/index.vdt
+++ b/src/components/codePreview/index.vdt
@@ -1,6 +1,5 @@
-import {Split } from 'kpc';
-
-const Code = self.Code;
+import {Split} from 'kpc';
+import Code from '../code';
如果你没有通过webpack编译打包,则可以全量引入主题样式,使用index.css替换掉kpc.css即可
+
+ 如果你通过webpack编译打包,则可以配置stylus-loader来按需引入主题样式
+
+