@shikijs/transformers 4.1.0 → 4.2.0

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/dist/index.mjs +12 -0
  2. package/package.json +3 -3
package/dist/index.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  //#region src/shared/parse-comments.ts
2
2
  const RE_SPLIT_COMMENT = /(\s+\/\/)/;
3
3
  const RE_V1_END_COMMENT_PREFIX = /(?:\/\/|["'#]|;{1,2}|%{1,2}|--)(\s*)$/;
4
+ const RE_V3_END_COMMENT_PREFIX = /(?:\/\/|#|;{1,2}|%{1,2}|--)(\s*)$/;
4
5
  /**
5
6
  * some comment formats have to be located at the end of line
6
7
  * hence we can skip matching them for other tokens
@@ -136,6 +137,16 @@ function v1ClearEndCommentPrefix(text) {
136
137
  if (match && match[1].trim().length === 0) return text.slice(0, match.index);
137
138
  return text;
138
139
  }
140
+ /**
141
+ * Remove empty comment prefixes at line end, e.g. `// `
142
+ *
143
+ * For matchAlgorithm v3
144
+ */
145
+ function v3ClearEndCommentPrefix(text) {
146
+ const match = text.match(RE_V3_END_COMMENT_PREFIX);
147
+ if (match && match[1].trim().length === 0) return text.slice(0, match.index).trimEnd();
148
+ return text;
149
+ }
139
150
  //#endregion
140
151
  //#region src/shared/notation-transformer.ts
141
152
  function createCommentNotationTransformer(name, regex, onMatch, matchAlgorithm) {
@@ -163,6 +174,7 @@ function createCommentNotationTransformer(name, regex, onMatch, matchAlgorithm)
163
174
  });
164
175
  if (!replaced) continue;
165
176
  if (matchAlgorithm === "v1") comment.info[1] = v1ClearEndCommentPrefix(comment.info[1]);
177
+ else if (matchAlgorithm === "v3") comment.info[1] = v3ClearEndCommentPrefix(comment.info[1]);
166
178
  const isEmpty = comment.info[1].trim().length === 0;
167
179
  if (isEmpty) comment.info[1] = "";
168
180
  if (isEmpty && comment.isLineCommentOnly) linesToRemove.push(comment.line);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shikijs/transformers",
3
3
  "type": "module",
4
- "version": "4.1.0",
4
+ "version": "4.2.0",
5
5
  "description": "Collective of common transformers transformers for Shiki",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -30,8 +30,8 @@
30
30
  "node": ">=20"
31
31
  },
32
32
  "dependencies": {
33
- "@shikijs/types": "4.1.0",
34
- "@shikijs/core": "4.1.0"
33
+ "@shikijs/core": "4.2.0",
34
+ "@shikijs/types": "4.2.0"
35
35
  },
36
36
  "scripts": {
37
37
  "build": "tsdown",