autosnippet 1.2.14 → 1.2.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/install.js +14 -29
- package/package.json +1 -1
package/bin/install.js
CHANGED
|
@@ -35,6 +35,7 @@ function writeSingleSnippet(snippet, template) {
|
|
|
35
35
|
// 这样即使没有缓存也能解析出完整信息
|
|
36
36
|
const headRelativePath = extPlace['{headName}']; // 相对于模块根目录的相对路径
|
|
37
37
|
header = header + ' ' + headRelativePath;
|
|
38
|
+
// ✅ header 是动态生成的(包含 < >),需要转义以匹配 JSON 中的转义格式
|
|
38
39
|
header = escapeString(header);
|
|
39
40
|
|
|
40
41
|
// swift只需要考虑工作空间是否引入
|
|
@@ -74,19 +75,17 @@ function writeSingleSnippet(snippet, template) {
|
|
|
74
75
|
let turnValue = '';
|
|
75
76
|
|
|
76
77
|
for (var index = 0; index < value.length; index++) {
|
|
77
|
-
// ✅
|
|
78
|
-
const unescapedLine = unescapeString(value[index]);
|
|
79
|
-
const escapedLine = escapeString(unescapedLine);
|
|
78
|
+
// ✅ JSON 中已经是转义后的内容(来自 create.js),直接使用,无需再次转义
|
|
80
79
|
if (index === 0) {
|
|
81
|
-
turnValue +=
|
|
80
|
+
turnValue += value[index] + '\n';
|
|
82
81
|
} else {
|
|
83
|
-
turnValue += '\t' +
|
|
82
|
+
turnValue += '\t' + value[index] + '\n';
|
|
84
83
|
}
|
|
85
84
|
}
|
|
86
85
|
value = turnValue;
|
|
87
86
|
} else {
|
|
88
|
-
// ✅
|
|
89
|
-
value
|
|
87
|
+
// ✅ JSON 中已经是转义后的内容(来自 create.js),直接使用,无需再次转义
|
|
88
|
+
// value 已经是转义后的字符串,直接使用
|
|
90
89
|
}
|
|
91
90
|
tempVal = '\t<string>' + value + '</string>\n';
|
|
92
91
|
}
|
|
@@ -177,6 +176,7 @@ function addCodeSnippets(specFile, singleSnippet) {
|
|
|
177
176
|
// 这样即使没有缓存也能解析出完整信息
|
|
178
177
|
const headRelativePath = extPlace['{headName}']; // 相对于模块根目录的相对路径
|
|
179
178
|
header = header + ' ' + headRelativePath;
|
|
179
|
+
// ✅ header 是动态生成的(包含 < >),需要转义以匹配 JSON 中的转义格式
|
|
180
180
|
header = escapeString(header);
|
|
181
181
|
|
|
182
182
|
// swift只需要考虑工作空间是否引入
|
|
@@ -217,19 +217,17 @@ function addCodeSnippets(specFile, singleSnippet) {
|
|
|
217
217
|
let turnValue = '';
|
|
218
218
|
|
|
219
219
|
for (var index = 0; index < value.length; index++) {
|
|
220
|
-
// ✅
|
|
221
|
-
const unescapedLine = unescapeString(value[index]);
|
|
222
|
-
const escapedLine = escapeString(unescapedLine);
|
|
220
|
+
// ✅ JSON 中已经是转义后的内容(来自 create.js),直接使用,无需再次转义
|
|
223
221
|
if (index === 0) {
|
|
224
|
-
turnValue +=
|
|
222
|
+
turnValue += value[index] + '\n';
|
|
225
223
|
} else {
|
|
226
|
-
turnValue += '\t' +
|
|
224
|
+
turnValue += '\t' + value[index] + '\n';
|
|
227
225
|
}
|
|
228
226
|
}
|
|
229
227
|
value = turnValue;
|
|
230
228
|
} else {
|
|
231
|
-
// ✅
|
|
232
|
-
value
|
|
229
|
+
// ✅ JSON 中已经是转义后的内容(来自 create.js),直接使用,无需再次转义
|
|
230
|
+
// value 已经是转义后的字符串,直接使用
|
|
233
231
|
}
|
|
234
232
|
tempVal = '\t<string>' + value + '</string>\n';
|
|
235
233
|
}
|
|
@@ -264,21 +262,8 @@ function addCodeSnippets(specFile, singleSnippet) {
|
|
|
264
262
|
}
|
|
265
263
|
|
|
266
264
|
/**
|
|
267
|
-
*
|
|
268
|
-
|
|
269
|
-
function unescapeString(string) {
|
|
270
|
-
if (typeof string !== 'string') {
|
|
271
|
-
return string;
|
|
272
|
-
}
|
|
273
|
-
// 必须先解码 &,否则会把 &lt; 错误解码
|
|
274
|
-
string = string.replace(/&/g, '&');
|
|
275
|
-
string = string.replace(/</g, '<');
|
|
276
|
-
string = string.replace(/>/g, '>');
|
|
277
|
-
return string;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
/**
|
|
281
|
-
* 转义特殊字符(将 & < > 转为 HTML 实体)
|
|
265
|
+
* 转义特殊字符(仅在动态生成 header 时使用)
|
|
266
|
+
* 注意:从 JSON 读取的内容已经转义过了,不需要再次转义
|
|
282
267
|
*/
|
|
283
268
|
function escapeString(string) {
|
|
284
269
|
if (typeof string !== 'string') {
|