@@ -241,51 +241,51 @@ type为`code`时content类型为字符串,直接传入文本或代码即可
241241
242242code类型消息支持 ` highlight.js ` 高亮显示
243243
244- 首先你需要配置 ** Highlight.js**
244+ 首先你需要配置 ** Highlight.js** ,在main.js入口安装,详细配置见 [ https://www.npmjs.com/package/highlight.js ] ( https://www.npmjs.com/package/highlight.js )
245245
246246``` js
247- import Hljs from ' highlight.js' ;
248- import ' highlight.js/styles/tomorrow-night-bright.css' ;
249-
250- let Highlight = {};
251- Highlight .install = function (Vue ) {
252- Vue .directive (' highlight' , {
253- inserted : function (el ) {
254- let blocks = el .querySelectorAll (' pre code' );
255- blocks .forEach (block => {
256- let ul = document .createElement (" ul" );
257- let rowCount = block .outerHTML .split (' \n ' ).length ;
258- for (let i = 1 ; i <= rowCount; i++ ) {
259- let li = document .createElement (" li" )
260- let text = document .createTextNode (i)
261- li .appendChild (text)
262- ul .appendChild (li)
263- }
264- ul .className = ' pre-numbering'
265- block .parentNode .appendChild (ul)
266- Hljs .highlightBlock (block)
267- })
268- },
269- componentUpdated : function (el ) {
270- let blocks = el .querySelectorAll (' pre code' );
271- for (let i = 0 ; i < blocks .length ; i++ ) {
272- Hljs .highlightBlock (blocks[i]);
273- }
274- }
275- })
276- };
247+ import Terminal from ' vue-web-terminal'
248+ import hljs from ' highlight.js'
249+ import java from ' highlight.js/lib/languages/java'
250+ import vuePlugin from " @highlightjs/vue-plugin"
251+ import ' highlight.js/styles/tomorrow-night-bright.css'
277252
278- export default Highlight ;
253+ hljs .registerLanguage (' java' , java)
254+ Vue .use (vuePlugin)
255+ Vue .use (Terminal, {highlight: true })
279256```
280257
281- 然后在载入 Terminal 的入口修改配置就可以高亮显示了
258+ vue2版本推荐
259+ ``` json
260+ {
261+ "@highlightjs/vue-plugin" : " ^1.0.2" ,
262+ "highlight.js" : " ^10.7.3"
263+ }
264+ ```
282265
283- ``` js
284- import Terminal from ' vue-web-terminal'
285- import Hljs from ' @/Highlight.js'
266+ #### codemirror 代码高亮
286267
287- Vue .use (Hljs)
288- Vue .use (Terminal, {highlight: true })
268+ code类型消息也支持 ` codemirror ` 高亮显示,详细配置见[ https://www.npmjs.com/package/vue-codemirror ] ( https://www.npmjs.com/package/vue-codemirror )
269+
270+ 同样只需要在main.js入口安装即可,版本推荐:` "vue-codemirror": "^4.0.6" `
271+ ``` js
272+ import VueCodemirror from ' vue-codemirror'
273+ import ' codemirror/lib/codemirror.css'
274+ import ' codemirror/theme/darcula.css'
275+ import ' codemirror/mode/clike/clike.js'
276+ import ' codemirror/addon/edit/closebrackets.js'
277+
278+ Vue .use (VueCodemirror)
279+ Vue .use (Terminal, {
280+ codemirror: {
281+ tabSize: 4 ,
282+ mode: ' text/x-java' ,
283+ theme: " darcula" ,
284+ lineNumbers: true ,
285+ line: true ,
286+ smartIndent: true
287+ }
288+ })
289289```
290290
291291### table
0 commit comments