Skip to content

Commit f619e05

Browse files
authored
fix: alert token also need line offset since it is based on blockquote (#16)
1 parent f2661f9 commit f619e05

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

lib/common/utils.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,14 +290,27 @@ function normalizeReference(str) {
290290
}
291291

292292
function getLineOffset(state) {
293-
if (state.env.parentToken.parentType === 'blockquote') {
293+
if (isInBlockquote(state)) {
294294
const blockState = state.env.state_block;
295295
return blockState.lineOffsets[state.currentLine] ?? 0;
296296
} else {
297297
return 0;
298298
}
299299
}
300300

301+
function isInBlockquote(state) {
302+
let count = 0;
303+
for (let i = state.env.parentTokenIndex; i >= 0; i--) {
304+
const token = state.env.parentState.tokens[i];
305+
if (token.type === 'blockquote_open' || token.type === 'alert_open') {
306+
count++;
307+
} else if (token.type === 'blockquote_close' || token.type === 'alert_close') {
308+
count--;
309+
}
310+
}
311+
return count > 0;
312+
}
313+
301314
function trimLeftOffset(str) {
302315
return str.length - str.trimLeft().length;
303316
}

0 commit comments

Comments
 (0)