forked from b3log/lute
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfiletype.go
More file actions
133 lines (112 loc) · 1.79 KB
/
Copy pathfiletype.go
File metadata and controls
133 lines (112 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// Lute - A structured markdown engine.
// Copyright (c) 2019-present, b3log.org
//
// Lute is licensed under the Mulan PSL v1.
// You can use this software according to the terms and conditions of the Mulan PSL v1.
// You may obtain a copy of Mulan PSL v1 at:
// http://license.coscl.org.cn/MulanPSL
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
// PURPOSE.
// See the Mulan PSL v1 for more details.
package lute
import "strings"
func isFileExt(pos, length int, runes *[]rune) bool {
max := pos + maxCommonFileTypeLen
if max > length {
max = length
}
ext := string((*runes)[pos:max])
for j := 0; j < commonFileTypesLen; j++ {
if strings.HasPrefix(ext, commonFileTypes[j]) {
return true
}
}
return false
}
var commonFileTypesLen = len(commonFileTypes)
var maxCommonFileTypeLen = 5 // woff2
// commonFileTypes 列出了常见的文件后缀,主要用于判断是否需要将英文句号.转换为中文句号。
var commonFileTypes = []string{
// 图片
"jpg",
"png",
"gif",
"webp",
"cr2",
"tif",
"bmp",
"heif",
"jxr",
"psd",
"ico",
"dwg",
// 视频
"mp4",
"m4v",
"mkv",
"webm",
"mov",
"avi",
"wmv",
"mpg",
"flv",
"3gp",
// 音频
"mid",
"mp3",
"m4a",
"ogg",
"flac",
"wav",
"amr",
"aac",
// 压缩包
"epub",
"zip",
"tar",
"rar",
"gz",
"bz2",
"7z",
"xz",
"pdf",
"exe",
"swf",
"rtf",
"iso",
"eot",
"ps",
"sqli",
"nes",
"crx",
"cab",
"deb",
"ar",
"Z",
"lz",
"rpm",
"elf",
"dcm",
// 文件
"doc",
"docx",
"xls",
"xlsx",
"ppt",
"pptx",
// 字体
"woff",
"woff2",
"ttf",
"otf",
// 应用程序
"wasm",
"exe",
// 编程语言
"html",
"js",
"css",
"go",
"java",
}