Skip to content

Commit

Permalink
Merge pull request #105 from code-hike/fix-annotation-regex
Browse files Browse the repository at this point in the history
Fix annotation regex
  • Loading branch information
pomber authored Jan 7, 2022
2 parents 8b13e64 + d3f27ad commit ea217c7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/mdx/src/plugin/annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export function extractAnnotationsFromCode(code: Code) {
return [annotations, focusList.join(",")] as const
}

const commentRegex = /\/\/\s+(\w+)(\S*)\s*(.*)/
function getCommentData(line: Code["lines"][0]) {
const comment = line.tokens.find(t =>
t.content.trim().startsWith("//")
Expand All @@ -59,10 +60,13 @@ function getCommentData(line: Code["lines"][0]) {
return {}
}

const commentRegex = /\/\/\s+(\w+)(\S*)\s*(.*)/
const [, key, focusString, data] = commentRegex.exec(
comment
)
const result = commentRegex.exec(comment)

if (!result) {
return {}
}

const [, key, focusString, data] = result

return {
key,
Expand Down
3 changes: 3 additions & 0 deletions packages/playground/content/comment-annotations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ function lorem(ipsum, dolor = 1) {
}

// this comment isn't an annotation
//hello
// 你好
// å
function adipiscing(...elit) {
console.log(elit)
// box[19:36] aqua
Expand Down

0 comments on commit ea217c7

Please sign in to comment.