@@ -3,6 +3,8 @@ import Vuex from 'vuex'
33import config from '../scripts/config' ;
44import WxRenderer from '../scripts/renderers/wx-renderer'
55import marked from 'marked'
6+ import prettier from 'prettier/standalone'
7+ import prettierMarkdown from 'prettier/parser-markdown'
68import CodeMirror from 'codemirror/lib/codemirror'
79import DEFAULT_CONTENT from '../scripts/default-content'
810import DEFAULT_CSS_CONTENT from '../scripts/themes/default-theme-css'
@@ -70,15 +72,25 @@ const mutations = {
7072 } ,
7173 initEditorEntity ( state ) {
7274 state . editor = CodeMirror . fromTextArea (
73- document . getElementById ( 'editor' ) ,
75+ document . getElementById ( 'editor' ) ,
7476 {
7577 value : '' ,
7678 mode : 'text/x-markdown' ,
7779 theme : 'xq-light' ,
7880 lineNumbers : false ,
7981 lineWrapping : true ,
8082 styleActiveLine : true ,
81- autoCloseBrackets : true
83+ autoCloseBrackets : true ,
84+ extraKeys : {
85+ 'Ctrl-F' : function autoFormat ( editor ) {
86+ const doc = prettier . format ( editor . getValue ( 0 ) , {
87+ parser : 'markdown' ,
88+ plugins : [ prettierMarkdown ]
89+ } )
90+ localStorage . setItem ( '__editor_content' , doc )
91+ editor . setValue ( doc )
92+ }
93+ }
8294 }
8395 )
8496 // 如果有编辑器内容被保存则读取,否则加载默认内容
@@ -90,7 +102,8 @@ const mutations = {
90102 } ,
91103 initCssEditorEntity ( state ) {
92104 state . cssEditor = CodeMirror . fromTextArea (
93- document . getElementById ( 'cssEditor' ) , {
105+ document . getElementById ( 'cssEditor' ) ,
106+ {
94107 value : '' ,
95108 mode : 'css' ,
96109 theme : 'style-mirror' ,
@@ -99,10 +112,10 @@ const mutations = {
99112 matchBrackets : true ,
100113 autofocus : true ,
101114 extraKeys : {
102- 'Ctrl-F' : function autoFormat ( editor ) {
103- const totalLines = editor . lineCount ( )
115+ 'Ctrl-F' : function autoFormat ( editor ) {
116+ const totalLines = editor . lineCount ( )
104117
105- editor . autoFormatRange ( {
118+ editor . autoFormatRange ( {
106119 line : 0 ,
107120 ch : 0
108121 } , {
0 commit comments