@shikijs/transformers 3.16.0 → 3.17.1

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 +47 -3
  2. package/package.json +3 -3
package/dist/index.mjs CHANGED
@@ -60,7 +60,32 @@ function parseComments(lines, jsx, matchAlgorithm) {
60
60
  if (head?.type !== "text")
61
61
  continue;
62
62
  const isLast = i === elements.length - 1;
63
- const match = matchToken(head.value, isLast);
63
+ let match = matchToken(head.value, isLast);
64
+ let additionalTokens;
65
+ if (!match && i > 0 && head.value.trim().startsWith("[!code")) {
66
+ const prevToken = elements[i - 1];
67
+ if (prevToken?.type === "element") {
68
+ const prevHead = prevToken.children.at(0);
69
+ if (prevHead?.type === "text" && prevHead.value.includes("//")) {
70
+ const combinedValue = prevHead.value + head.value;
71
+ const combinedMatch = matchToken(combinedValue, isLast);
72
+ if (combinedMatch) {
73
+ match = combinedMatch;
74
+ out.push({
75
+ info: combinedMatch,
76
+ line,
77
+ token: prevToken,
78
+ // Use the previous token as the main token
79
+ isLineCommentOnly: elements.length === 2 && prevToken.children.length === 1 && token.children.length === 1,
80
+ isJsxStyle: false,
81
+ additionalTokens: [token]
82
+ // Current token is the additional one
83
+ });
84
+ continue;
85
+ }
86
+ }
87
+ }
88
+ }
64
89
  if (!match)
65
90
  continue;
66
91
  if (jsx && !isLast && i !== 0) {
@@ -70,7 +95,8 @@ function parseComments(lines, jsx, matchAlgorithm) {
70
95
  line,
71
96
  token,
72
97
  isLineCommentOnly: elements.length === 3 && token.children.length === 1,
73
- isJsxStyle
98
+ isJsxStyle,
99
+ additionalTokens
74
100
  });
75
101
  } else {
76
102
  out.push({
@@ -78,7 +104,8 @@ function parseComments(lines, jsx, matchAlgorithm) {
78
104
  line,
79
105
  token,
80
106
  isLineCommentOnly: elements.length === 1 && token.children.length === 1,
81
- isJsxStyle: false
107
+ isJsxStyle: false,
108
+ additionalTokens
82
109
  });
83
110
  }
84
111
  }
@@ -158,11 +185,28 @@ function createCommentNotationTransformer(name, regex, onMatch, matchAlgorithm)
158
185
  } else if (isEmpty && comment.isJsxStyle) {
159
186
  comment.line.children.splice(comment.line.children.indexOf(comment.token) - 1, 3);
160
187
  } else if (isEmpty) {
188
+ if (comment.additionalTokens) {
189
+ for (let j = comment.additionalTokens.length - 1; j >= 0; j--) {
190
+ const additionalToken = comment.additionalTokens[j];
191
+ const tokenIndex = comment.line.children.indexOf(additionalToken);
192
+ if (tokenIndex !== -1) {
193
+ comment.line.children.splice(tokenIndex, 1);
194
+ }
195
+ }
196
+ }
161
197
  comment.line.children.splice(comment.line.children.indexOf(comment.token), 1);
162
198
  } else {
163
199
  const head = comment.token.children[0];
164
200
  if (head.type === "text") {
165
201
  head.value = comment.info.join("");
202
+ if (comment.additionalTokens) {
203
+ for (const additionalToken of comment.additionalTokens) {
204
+ const additionalHead = additionalToken.children[0];
205
+ if (additionalHead?.type === "text") {
206
+ additionalHead.value = "";
207
+ }
208
+ }
209
+ }
166
210
  }
167
211
  }
168
212
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shikijs/transformers",
3
3
  "type": "module",
4
- "version": "3.16.0",
4
+ "version": "3.17.1",
5
5
  "description": "Collective of common transformers transformers for Shiki",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -27,8 +27,8 @@
27
27
  "dist"
28
28
  ],
29
29
  "dependencies": {
30
- "@shikijs/core": "3.16.0",
31
- "@shikijs/types": "3.16.0"
30
+ "@shikijs/core": "3.17.1",
31
+ "@shikijs/types": "3.17.1"
32
32
  },
33
33
  "scripts": {
34
34
  "build": "unbuild",