mirror of
https://github.com/mindoc-org/mindoc.git
synced 2025-09-19 10:08:03 +08:00
1、实现富文本编辑器
2、实现文档转换为PDF、MOBI、EPUB格式
This commit is contained in:
47
converter/util.go
Normal file
47
converter/util.go
Normal file
@@ -0,0 +1,47 @@
|
||||
//Author:TruthHun
|
||||
//Email:TruthHun@QQ.COM
|
||||
//Date:2018-01-21
|
||||
package converter
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
)
|
||||
|
||||
//media-type
|
||||
var MediaType = map[string]string{
|
||||
".jpeg": "image/jpeg",
|
||||
".png": "image/png",
|
||||
".jpg": "image/jpeg",
|
||||
".gif": "image/gif",
|
||||
".ico": "image/x-icon",
|
||||
".bmp": "image/bmp",
|
||||
".html": "application/xhtml+xml",
|
||||
".xhtml": "application/xhtml+xml",
|
||||
".htm": "application/xhtml+xml",
|
||||
".otf": "application/x-font-opentype",
|
||||
".ttf": "application/x-font-ttf",
|
||||
".js": "application/x-javascript",
|
||||
".ncx": "x-dtbncx+xml",
|
||||
".txt": "text/plain",
|
||||
".xml": "text/xml",
|
||||
".css": "text/css",
|
||||
}
|
||||
|
||||
//根据文件扩展名,获取media-type
|
||||
func GetMediaType(ext string) string {
|
||||
if mt, ok := MediaType[strings.ToLower(ext)]; ok {
|
||||
return mt
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
//解析配置文件
|
||||
func parseConfig(configFile string) (cfg Config, err error) {
|
||||
var b []byte
|
||||
if b, err = ioutil.ReadFile(configFile); err == nil {
|
||||
err = json.Unmarshal(b, &cfg)
|
||||
}
|
||||
return
|
||||
}
|
Reference in New Issue
Block a user