diff --git a/data/user_workspaces/admin/src/format/test.css b/data/user_workspaces/admin/src/format/test.css new file mode 100644 index 0000000..1f4ed9e --- /dev/null +++ b/data/user_workspaces/admin/src/format/test.css @@ -0,0 +1,319 @@ +/* start icon */ + +@font-face { + font-family: 'icomoon'; + src: url('fonts/icomoon.eot?35cb2z'); + src: url('fonts/icomoon.eot?#iefix35cb2z') format('embedded-opentype'), url('fonts/icomoon.woff?35cb2z') format('woff'), url('fonts/icomoon.ttf?35cb2z') format('truetype'), url('fonts/icomoon.svg?35cb2z#icomoon') format('svg'); + font-weight: normal; + font-style: normal; +} +.font-ico { + font-family: 'icomoon'; + /* Better Font Rendering =========== */ + + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; + color: #666; + cursor: pointer; + font-size: 13px; + line-height: 18px; +} +.font-ico:hover { + color: #333; +} +.ico-play:before { + content: "\e605"; +} +.ico-save:before { + content: "\f0c7"; +} +.ico-max:before { + content: "\f096"; +} +.ico-format:before { + content: "\e60b"; +} +.ico-buildrun:before { + content: "\e607"; +} +.ico-stop:before { + content: "\e608"; +} +.ico-restore:before { + content: "\e60c"; +} +.ico-min:before { + content: "\e60d"; + position: absolute; + right: 5px; +} +.ico-close:before { + content: "\e60a"; +} +/* end ico */ +/* start frame */ + +.frame { + position: absolute; + border: 1px solid #5F5F5F; + background-color: #F8F8F8; + width: 320px; + z-index: 21; + display: none; +} +.frame li { + padding: 0 5px; + line-height: 25px; + cursor: pointer; +} +.frame li.disabled { + color: #999; +} +.frame li:hover { + background-color: #3875D7; + color: #FFF; +} +.frame li.disabled:hover { + background-color: #F8F8F8; + color: #999; +} +.frame a { + color: #000; + text-decoration: none; +} +.frame li:hover a, +.frame a:hover { + color: #FFF; +} +.frame .hr { + background-color: #bdbdbd; + height: 1px; + margin: 0 1px; +} +/* end frame */ +/* start tabs */ + +.tabs { + height: 20px; + overflow: hidden; + width: 100%; + background-color: #E6E6E6; + border-top: 1px solid #A4A4A4; + border-bottom: 1px solid #9D9D9D; +} +.tabs > div { + float: left; + line-height: 18px; + height: 18px; + padding: 0 5px; + cursor: pointer; + background-color: #DDD; + color: #8B8B8B; + border-right: 1px solid #ADADAD; +} +.tabs > div.current { + background-color: #9F9F9F; + color: #FFF; +} +/* end tabs */ +/* start framework */ + +.content { + position: relative; + overflow: hidden; +} +/* end framework */ +/* start menu */ + +.menu { + background-color: #F0F0F0; + height: 24px; +} +.menu > ul > li { + float: left; +} +.menu > ul > li > span { + color: #000; + font-size: 12px; + line-height: 24px; + padding: 5px; + text-decoration: none; + cursor: pointer; +} +/* end menu */ +/* start editor */ + +.edit-panel { + width: 80%; + position: absolute; + left: 20%; + width: 80%; + height: 70%; + overflow: hidden; +} +.edit-panel .tabs > div { + background-color: #d1d1d1; + border-right-color: #9b9b9b; + color: #333; + cursor: auto; +} +.edit-panel .tabs > div.current { + background-color: #F7F7F7; +} +.toolbars { + position: absolute; + right: 5px; + top: 1px; +} +.edit-panel .tabs .ico { + background-image: url("../images/ico-file.png"); + float: left; + height: 16px; + margin: 2px 0 0 -2px; + width: 16px; +} +/* 统一为 static/js/lib/codemirror-4.5/addon/hint/show-hint.css 中的.CodeMirror-hints */ + +.edit-exprinfo { + position: absolute; + z-index: 10; + overflow: hidden; + list-style: none; + margin: 0; + padding: 2px; + -webkit-box-shadow: 2px 3px 5px rgba(0, 0, 0, .2); + -moz-box-shadow: 2px 3px 5px rgba(0, 0, 0, .2); + box-shadow: 2px 3px 5px rgba(0, 0, 0, .2); + border-radius: 3px; + border: 1px solid silver; + background: white; + font-size: 90%; + font-family: Consolas, Courier New, monospace; + max-height: 20em; + overflow-y: auto; +} +.CodeMirror, +.CodeMirror-hints { + font-family: Consolas, Courier New, monospace; +} +.CodeMirror-focused .cm-matchhighlight { + background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAFklEQVQI12NgYGBgkKzc8x9CMDAwAAAmhwSbidEoSQAAAABJRU5ErkJggg==); + background-position: bottom; + background-repeat: repeat-x; +} +.CodeMirror-hint { + padding-right: 18px; + max-width: none; +} +.CodeMirror-hint:hover { + background: #08f; + color: white; +} +/* end editor */ +/* start bottom-window-group */ + +.bottom-window-group { + width: 80%; + position: absolute; + left: 20%; + width: 80%; + height: 30%; + top: 70%; + z-index: 7; + background-color: #fff; +} +.bottom-window-group-max { + height: 100%; + left: 0; + top: 0; + width: 100%; + z-index: 11; +} +.bottom-window-group > div > div { + overflow: auto; +} +.bottom-window-group .output { + font-family: Consolas, Courier New, monospace; + padding: 0 5px; + line-height: 16px; + font-size: 12px; +} +.bottom-window-group .output pre { + margin: 0; +} +.bottom-window-group .output .start-build, +.bottom-window-group .output .start-test, +.bottom-window-group .output .start-install, +.bottom-window-group .output .start-get { + color: #999; +} +.bottom-window-group .output .build-succ, +.bottom-window-group .output .test-succ, +.bottom-window-group .output .install-succ, +.bottom-window-group .output .get-succ { + color: rgb(0, 153, 0); +} +.bottom-window-group .output .build-error, +.bottom-window-group .output .test-error, +.bottom-window-group .output .install-error, +.bottom-window-group .output .get-error { + color: red; +} +.bottom-window-group table { + width: 100%; +} +.bottom-window-group td { + border-bottom: 1px solid #DDD; + line-height: 20px; +} +.bottom-window-group .notification .type, +.bottom-window-group .notification .severity { + width: 50px; + padding: 0 5px; +} +.bottom-window-group .search li { + cursor: pointer; + line-height: 20px; + padding: 0 3px; + word-wrap: normal; + word-break: normal; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} +.bottom-window-group .search li.selected { + background-color: #3875d7; + color: #FFF; +} +.bottom-window-group .search .path { + color: #999; + font-size: 12px; +} +.bottom-window-group .search li.selected .path { + color: #FFF; +} +/* end bottom-window-group */ +/* start footer */ + +.footer { + border-top: 1px solid #919191; + background-color: #F0F0F0; + padding-left: 5px; + height: 19px; + line-height: 18px; +} +.footer .cursor { + cursor: pointer; +} +.notification-count { + float: right; + display: none; + cursor: pointer; + background-color: red; + color: #FFF; + margin: 1px 5px; + padding: 0 2px; + border-radius: 3px; + line-height: 16px; +} +/* end footer */ \ No newline at end of file diff --git a/data/user_workspaces/admin/src/format/test.html b/data/user_workspaces/admin/src/format/test.html new file mode 100644 index 0000000..9525b5d --- /dev/null +++ b/data/user_workspaces/admin/src/format/test.html @@ -0,0 +1,333 @@ + + + + + + {{.i18n.wide}} + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+
+ {{.i18n.file}} +
+
+
+
+
    + +
    +
      +
    • {{.i18n.create_file}}
    • +
    • {{.i18n.create_dir}}
    • +
    • {{.i18n.delete}}
    • +
    +
    + + +
    +
      +
    • {{.i18n.delete}}
    • +
    +
    +
    +
    +
    + +
    +
    + + + + +
    +
    +
    +
    + +
    + +
    +
    + {{.i18n.output}} +
    +
    + {{.i18n.search}} +
    +
    + {{.i18n.notification}} +
    +
    +
    +
    +
    +
    +
    +
    +
    + +
    +
    +
    +
    +
    +
    +
    +
    +
    + + + +
    + {{.i18n.isDelete}} ? +
    +
    +
    +
    + +
    +
    + +
    +
    + +
    +
    + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/data/user_workspaces/admin/src/format/test.json b/data/user_workspaces/admin/src/format/test.json new file mode 100644 index 0000000..5baf1c3 --- /dev/null +++ b/data/user_workspaces/admin/src/format/test.json @@ -0,0 +1,36 @@ +{ + "Server": "{IP}:7070", + "StaticServer": "http://{IP}:7070", + "EditorChannel": "ws://{IP}:7070", + "OutputChannel": "ws://{IP}:7070", + "ShellChannel": "ws://{IP}:7070", + "SessionChannel": "ws://{IP}:7070", + "HTTPSessionMaxAge": 86400, + "StaticResourceVersion": "201410271700", + "MaxProcs": 4, + "RuntimeMode": "dev", + "Pwd": "{pwd}", + "Workspace": "{pwd}/data/workspace", + "Locale": "en_US", + "Users": [{ + "Name": "admin", + "Password": "admin", + "Workspace": "{pwd}/data/user_workspaces/admin", + "Locale": "en_US", + "GoFormat": "gofmt", + "LatestSessionContent": { + "FileTree": [ + "D:\\GoGoGo\\src\\github.com\\b3log\\wide\\data\\user_workspaces\\admin\\src", + "D:\\GoGoGo\\src\\github.com\\b3log\\wide\\data\\user_workspaces\\admin\\src\\format", + "D:\\GoGoGo\\src\\github.com\\b3log\\wide\\data\\user_workspaces\\admin\\src\\gotest", + "D:\\GoGoGo\\src\\github.com\\b3log\\wide\\data\\user_workspaces\\admin\\src\\hello", + "D:\\GoGoGo\\src\\github.com\\b3log\\wide\\data\\user_workspaces\\admin\\src\\time" + ], + "Files": [ + "D:\\GoGoGo\\src\\github.com\\b3log\\wide\\data\\user_workspaces\\admin\\src\\time\\main.go", + "D:\\GoGoGo\\src\\github.com\\b3log\\wide\\data\\user_workspaces\\admin\\src\\format\\index.html" + ], + "CurrentFile": "D:\\GoGoGo\\src\\github.com\\b3log\\wide\\data\\user_workspaces\\admin\\src\\format\\index.html" + } + }] +} \ No newline at end of file diff --git a/editor/formatter.go b/editor/formatter.go index 5e7f283..60f1cb6 100644 --- a/editor/formatter.go +++ b/editor/formatter.go @@ -8,7 +8,6 @@ import ( "runtime" "strings" - "github.com/88250/gohtml" "github.com/b3log/wide/conf" "github.com/b3log/wide/session" "github.com/b3log/wide/util" @@ -88,59 +87,3 @@ func GoFmtHandler(w http.ResponseWriter, r *http.Request) { return } } - -// HTMLFmtHandler handles request of formatting HTML source code. -// FIXME: gohtml has some issues... -func HTMLFmtHandler(w http.ResponseWriter, r *http.Request) { - data := map[string]interface{}{"succ": true} - defer util.RetJSON(w, r, data) - - var args map[string]interface{} - - if err := json.NewDecoder(r.Body).Decode(&args); err != nil { - glog.Error(err) - data["succ"] = false - - return - } - - filePath := args["file"].(string) - - fout, err := os.Create(filePath) - - if nil != err { - glog.Error(err) - data["succ"] = false - - return - } - - code := args["code"].(string) - - fout.WriteString(code) - if err := fout.Close(); nil != err { - glog.Error(err) - data["succ"] = false - - return - } - - output := gohtml.Format(code) - if "" == output { - data["succ"] = false - - return - } - - code = string(output) - data["code"] = code - - fout, err = os.Create(filePath) - fout.WriteString(code) - if err := fout.Close(); nil != err { - glog.Error(err) - data["succ"] = false - - return - } -} diff --git a/main.go b/main.go index 1bdf3e0..747255d 100644 --- a/main.go +++ b/main.go @@ -235,7 +235,6 @@ func main() { http.HandleFunc("/exprinfo", handlerWrapper(editor.GetExprInfoHandler)) http.HandleFunc("/find/decl", handlerWrapper(editor.FindDeclarationHandler)) http.HandleFunc("/find/usages", handlerWrapper(editor.FindUsagesHandler)) - http.HandleFunc("/html/fmt", handlerWrapper(editor.HTMLFmtHandler)) // shell http.HandleFunc("/shell/ws", handlerWrapper(shell.WSHandler)) diff --git a/static/js/wide.js b/static/js/wide.js index 6abfc57..08d1faf 100644 --- a/static/js/wide.js +++ b/static/js/wide.js @@ -706,6 +706,8 @@ var wide = { request.cursorLine = cursor.line; request.cursorCh = cursor.ch; + var formatted = null; + switch (mode) { case "text/x-go": $.ajax({ @@ -718,43 +720,34 @@ var wide = { curEditor.setValue(data.code); curEditor.setCursor(cursor); curEditor.scrollTo(null, scrollInfo.top); + + return; } } }); break; case "text/html": - try { - var content = html_beautify(curEditor.getValue()); - curEditor.setValue(content); - curEditor.setCursor(cursor); - curEditor.scrollTo(null, scrollInfo.top); - - wide._save(); - } catch (e) { - delete e; - } - + formatted = html_beautify(curEditor.getValue()); break; + case "text/javascript": case "application/json": - try { - var json = JSON.parse(curEditor.getValue()); - curEditor.setValue(JSON.stringify(json, "", " ")); - curEditor.setCursor(cursor); - curEditor.scrollTo(null, scrollInfo.top); - - wide._save(); - } catch (e) { - delete e; - } - + formatted = js_beautify(curEditor.getValue()); + break; + case "text/css": + formatted = css_beautify(curEditor.getValue()); break; default : - // TODO: XML 格式化处理 - // 所有文件格式化后都需要进行保存 - wide._save(); break; } + + if (formatted) { + curEditor.setValue(formatted); + curEditor.setCursor(cursor); + curEditor.scrollTo(null, scrollInfo.top); + + wide._save(); + } }, openAbout: function () { $("#dialogAbout").dialog("open");