Skip to content

Commit 4667c0f

Browse files
committed
Remove from annotation second pass
1 parent 6becc50 commit 4667c0f

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

Diff for: packages/mdx/src/remark/annotations.comments.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import {
44
extractLighterAnnotations,
55
parseLighterAnnotations,
66
} from "./lighter"
7+
import { annotationsMap } from "../mdx-client/annotations"
8+
9+
const annotationNames = Object.keys(annotationsMap)
710

811
export async function splitCodeAndAnnotations(
912
rawCode: string,
@@ -15,7 +18,11 @@ export async function splitCodeAndAnnotations(
1518
focus: string
1619
}> {
1720
let { code, annotations } =
18-
await extractLighterAnnotations(rawCode, lang)
21+
await extractLighterAnnotations(rawCode, lang, [
22+
...annotationNames,
23+
"from",
24+
"focus",
25+
])
1926

2027
// import external code if needed and re-run annotations extraction
2128
const fromAnnotations = annotations.filter(
@@ -29,10 +36,11 @@ export async function splitCodeAndAnnotations(
2936
config.filepath,
3037
range
3138
)
32-
// TODO remove 'from' annotation from the annotation names to avoid loops
39+
3340
const result = await extractLighterAnnotations(
3441
externalFileContent,
35-
lang
42+
lang,
43+
[...annotationNames, "focus"]
3644
)
3745
code = result.code
3846
annotations = result.annotations

Diff for: packages/mdx/src/remark/lighter.ts

+4-9
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,16 @@ import {
44
Annotation,
55
LANG_NAMES,
66
} from "@code-hike/lighter"
7-
import { Code } from "utils"
8-
import { annotationsMap } from "../mdx-client/annotations"
7+
import { Code } from "../utils"
98
import { CodeAnnotation } from "../smooth-code"
9+
import { annotationsMap } from "../mdx-client/annotations"
1010

1111
export type LighterAnnotation = Annotation
1212

13-
const annotationNames = [
14-
"focus",
15-
"from",
16-
...Object.keys(annotationsMap),
17-
]
18-
1913
export async function extractLighterAnnotations(
2014
codeWithAnnotations: string,
21-
lang: string
15+
lang: string,
16+
annotationNames: string[]
2217
) {
2318
return await extractAnnotations(
2419
codeWithAnnotations,

0 commit comments

Comments
 (0)