File tree 2 files changed +15
-12
lines changed
2 files changed +15
-12
lines changed Original file line number Diff line number Diff line change 4
4
extractLighterAnnotations ,
5
5
parseLighterAnnotations ,
6
6
} from "./lighter"
7
+ import { annotationsMap } from "../mdx-client/annotations"
8
+
9
+ const annotationNames = Object . keys ( annotationsMap )
7
10
8
11
export async function splitCodeAndAnnotations (
9
12
rawCode : string ,
@@ -15,7 +18,11 @@ export async function splitCodeAndAnnotations(
15
18
focus : string
16
19
} > {
17
20
let { code, annotations } =
18
- await extractLighterAnnotations ( rawCode , lang )
21
+ await extractLighterAnnotations ( rawCode , lang , [
22
+ ...annotationNames ,
23
+ "from" ,
24
+ "focus" ,
25
+ ] )
19
26
20
27
// import external code if needed and re-run annotations extraction
21
28
const fromAnnotations = annotations . filter (
@@ -29,10 +36,11 @@ export async function splitCodeAndAnnotations(
29
36
config . filepath ,
30
37
range
31
38
)
32
- // TODO remove 'from' annotation from the annotation names to avoid loops
39
+
33
40
const result = await extractLighterAnnotations (
34
41
externalFileContent ,
35
- lang
42
+ lang ,
43
+ [ ...annotationNames , "focus" ]
36
44
)
37
45
code = result . code
38
46
annotations = result . annotations
Original file line number Diff line number Diff line change @@ -4,21 +4,16 @@ import {
4
4
Annotation ,
5
5
LANG_NAMES ,
6
6
} from "@code-hike/lighter"
7
- import { Code } from "utils"
8
- import { annotationsMap } from "../mdx-client/annotations"
7
+ import { Code } from "../utils"
9
8
import { CodeAnnotation } from "../smooth-code"
9
+ import { annotationsMap } from "../mdx-client/annotations"
10
10
11
11
export type LighterAnnotation = Annotation
12
12
13
- const annotationNames = [
14
- "focus" ,
15
- "from" ,
16
- ...Object . keys ( annotationsMap ) ,
17
- ]
18
-
19
13
export async function extractLighterAnnotations (
20
14
codeWithAnnotations : string ,
21
- lang : string
15
+ lang : string ,
16
+ annotationNames : string [ ]
22
17
) {
23
18
return await extractAnnotations (
24
19
codeWithAnnotations ,
You can’t perform that action at this time.
0 commit comments