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.
Files changed (2) hide show
  1. package/bin/install.js +14 -29
  2. 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
- // ✅ 先解码 HTML 实体(JSON 中可能已转义),再转义写入 XML
78
- const unescapedLine = unescapeString(value[index]);
79
- const escapedLine = escapeString(unescapedLine);
78
+ // ✅ JSON 中已经是转义后的内容(来自 create.js),直接使用,无需再次转义
80
79
  if (index === 0) {
81
- turnValue += escapedLine + '\n';
80
+ turnValue += value[index] + '\n';
82
81
  } else {
83
- turnValue += '\t' + escapedLine + '\n';
82
+ turnValue += '\t' + value[index] + '\n';
84
83
  }
85
84
  }
86
85
  value = turnValue;
87
86
  } else {
88
- // ✅ 先解码 HTML 实体(JSON 中可能已转义),再转义写入 XML
89
- value = escapeString(unescapeString(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
- // ✅ 先解码 HTML 实体(JSON 中可能已转义),再转义写入 XML
221
- const unescapedLine = unescapeString(value[index]);
222
- const escapedLine = escapeString(unescapedLine);
220
+ // ✅ JSON 中已经是转义后的内容(来自 create.js),直接使用,无需再次转义
223
221
  if (index === 0) {
224
- turnValue += escapedLine + '\n';
222
+ turnValue += value[index] + '\n';
225
223
  } else {
226
- turnValue += '\t' + escapedLine + '\n';
224
+ turnValue += '\t' + value[index] + '\n';
227
225
  }
228
226
  }
229
227
  value = turnValue;
230
228
  } else {
231
- // ✅ 先解码 HTML 实体(JSON 中可能已转义),再转义写入 XML
232
- value = escapeString(unescapeString(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
- * 解码 HTML 实体(将 &amp; &lt; &gt; 转回原始字符)
268
- */
269
- function unescapeString(string) {
270
- if (typeof string !== 'string') {
271
- return string;
272
- }
273
- // 必须先解码 &amp;,否则会把 &amp;lt; 错误解码
274
- string = string.replace(/&amp;/g, '&');
275
- string = string.replace(/&lt;/g, '<');
276
- string = string.replace(/&gt;/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') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autosnippet",
3
- "version": "1.2.14",
3
+ "version": "1.2.15",
4
4
  "description": "A iOS module management tool.",
5
5
  "main": "index.js",
6
6
  "scripts": {