Skip to content

Commit 4164562

Browse files
authored
Merge pull request #97 from code-hike/comments-that-arent-annotations
Stop assuming comment annotations
2 parents 5804e66 + d7dfb85 commit 4164562

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

packages/mdx/src/plugin/annotations.ts

+13-11
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,32 @@ export function extractAnnotationsFromCode(code: Code) {
2424
const focusList = [] as string[]
2525
while (lineNumber <= lines.length) {
2626
const line = lines[lineNumber - 1]
27-
const { key, focus, data } = getCommentData(
28-
line,
29-
lineNumber
30-
)
27+
const { key, focusString, data } = getCommentData(line)
3128

3229
const Component = annotationsMap[key!]
3330

3431
if (Component) {
32+
const focus = relativeToAbsolute(
33+
focusString,
34+
lineNumber
35+
)
3536
lines.splice(lineNumber - 1, 1)
36-
annotations.push({ Component, focus: focus!, data })
37+
annotations.push({ Component, focus, data })
3738
} else if (key === "focus") {
39+
const focus = relativeToAbsolute(
40+
focusString,
41+
lineNumber
42+
)
3843
lines.splice(lineNumber - 1, 1)
39-
focusList.push(focus!)
44+
focusList.push(focus)
4045
} else {
4146
lineNumber++
4247
}
4348
}
4449
return [annotations, focusList.join(",")] as const
4550
}
4651

47-
function getCommentData(
48-
line: Code["lines"][0],
49-
lineNumber: number
50-
) {
52+
function getCommentData(line: Code["lines"][0]) {
5153
const comment = line.tokens.find(t =>
5254
t.content.startsWith("//")
5355
)?.content
@@ -63,7 +65,7 @@ function getCommentData(
6365

6466
return {
6567
key,
66-
focus: relativeToAbsolute(focusString, lineNumber),
68+
focusString,
6769
data,
6870
}
6971
}

packages/playground/content/comment-annotations.mdx

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ function lorem(ipsum, dolor = 1) {
4141
return sit ? consectetur(ipsum) : []
4242
}
4343

44+
// this comment isn't an annotation
4445
function adipiscing(...elit) {
4546
console.log(elit)
4647
// box[19:36] aqua

0 commit comments

Comments
 (0)