HTML 格式化
This commit is contained in:
parent
4440001b69
commit
530837f96a
|
@ -39,7 +39,6 @@ func HTMLFmtHandler(w http.ResponseWriter, r *http.Request) {
|
|||
code := args["code"].(string)
|
||||
|
||||
fout.WriteString(code)
|
||||
|
||||
if err := fout.Close(); nil != err {
|
||||
glog.Error(err)
|
||||
data["succ"] = false
|
||||
|
@ -48,12 +47,21 @@ func HTMLFmtHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
output := gohtml.Format(code)
|
||||
|
||||
if "" == output {
|
||||
data["succ"] = false
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
data["code"] = string(output)
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,16 +2,17 @@ package file
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/b3log/wide/conf"
|
||||
"github.com/b3log/wide/user"
|
||||
"github.com/b3log/wide/util"
|
||||
"github.com/golang/glog"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/b3log/wide/conf"
|
||||
"github.com/b3log/wide/user"
|
||||
"github.com/b3log/wide/util"
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
|
||||
func GetFiles(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -168,6 +169,7 @@ type FileNode struct {
|
|||
Path string `json:"path"`
|
||||
IconSkin string `json:"iconSkin"` // 值的末尾应该有一个空格
|
||||
Type string `json:"type"`
|
||||
Mode string `json:"mode"`
|
||||
FileNodes []*FileNode `json:"children"`
|
||||
}
|
||||
|
||||
|
@ -198,6 +200,7 @@ func walk(path string, info os.FileInfo, node *FileNode) {
|
|||
ext := filepath.Ext(fpath)
|
||||
|
||||
child.IconSkin = getIconSkin(ext)
|
||||
child.Mode = getEditorMode(ext)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -121,15 +121,18 @@ var wide = {
|
|||
});
|
||||
},
|
||||
fmt: function() {
|
||||
var path = wide.curNode.path;
|
||||
var mode = wide.curNode.mode;
|
||||
|
||||
var request = {
|
||||
"file": wide.curNode.path,
|
||||
"file": path,
|
||||
"code": wide.curEditor.getValue(),
|
||||
"cursorLine": wide.curEditor.getCursor().line,
|
||||
"cursorCh": wide.curEditor.getCursor().ch
|
||||
};
|
||||
|
||||
// TODO: HTML/XML/JSON 格式化处理
|
||||
|
||||
switch (mode) {
|
||||
case "text/x-go":
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '/go/fmt',
|
||||
|
@ -141,6 +144,28 @@ var wide = {
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
break;
|
||||
case "text/html":
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '/html/fmt',
|
||||
data: JSON.stringify(request),
|
||||
dataType: "json",
|
||||
success: function(data) {
|
||||
if (data.succ) {
|
||||
wide.curEditor.setValue(data.code);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
break;
|
||||
default :
|
||||
// TODO: XML/JSON 格式化处理
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -93,6 +93,7 @@
|
|||
<script type="text/javascript" src="{{.Wide.StaticServer}}/static/js/lib/jquery-2.1.1.min.js"></script>
|
||||
<script type="text/javascript" src="{{.Wide.StaticServer}}/static/js/lib/reconnecting-websocket.js"></script>
|
||||
<script type="text/javascript" src="{{.Wide.StaticServer}}/static/js/lib/ztree/jquery.ztree.all-3.5.min.js"></script>
|
||||
<script type="text/javascript" src="{{.Wide.StaticServer}}/static/js/lib/underscore.string-2.3.3/underscore.string.min.js"></script>
|
||||
|
||||
<script type="text/javascript" src="{{.Wide.StaticServer}}/static/js/lib/codemirror-4.5/codemirror.js"></script>
|
||||
<script type="text/javascript" src="{{.Wide.StaticServer}}/static/js/lib/codemirror-4.5/addon/lint/lint.js"></script>
|
||||
|
|
Loading…
Reference in New Issue