Skip to content

Commit 457b08c

Browse files
committedFeb 18, 2025
fix(transformers): also remove extra newline token, fix #915
1 parent 5546c14 commit 457b08c

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed
 

‎docs/packages/transformers.md

+14
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,13 @@ console.log('Highlighted')
177177
console.log('Highlighted')
178178
console.log('Not highlighted')
179179
```
180+
181+
```ts
182+
console.log('Not highlighted')
183+
// [\!code highlight:1]
184+
console.log('Highlighted')
185+
console.log('Not highlighted')
186+
```
180187
````
181188

182189
Renders:
@@ -188,6 +195,13 @@ console.log('Highlighted')
188195
console.log('Not highlighted')
189196
```
190197

198+
```ts
199+
console.log('Not highlighted')
200+
// [!code highlight:1]
201+
console.log('Highlighted')
202+
console.log('Not highlighted')
203+
```
204+
191205
---
192206

193207
### `transformerNotationWordHighlight`

‎packages/transformers/src/shared/notation-transformer.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,14 @@ export function createCommentNotationTransformer(
9797
}
9898
}
9999

100-
for (const line of linesToRemove)
101-
code.children.splice(code.children.indexOf(line), 1)
100+
for (const line of linesToRemove) {
101+
const index = code.children.indexOf(line)
102+
const nextLine = code.children[index + 1]
103+
let removeLength = 1
104+
if (nextLine?.type === 'text' && nextLine?.value === '\n')
105+
removeLength = 2
106+
code.children.splice(index, removeLength)
107+
}
102108
},
103109
}
104110
}

0 commit comments

Comments
 (0)