Skip to content

Commit

Permalink
Remove from annotation second pass
Browse files Browse the repository at this point in the history
  • Loading branch information
pomber committed Jul 9, 2023
1 parent 6becc50 commit 4667c0f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
14 changes: 11 additions & 3 deletions packages/mdx/src/remark/annotations.comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import {
extractLighterAnnotations,
parseLighterAnnotations,
} from "./lighter"
import { annotationsMap } from "../mdx-client/annotations"

const annotationNames = Object.keys(annotationsMap)

export async function splitCodeAndAnnotations(
rawCode: string,
Expand All @@ -15,7 +18,11 @@ export async function splitCodeAndAnnotations(
focus: string
}> {
let { code, annotations } =
await extractLighterAnnotations(rawCode, lang)
await extractLighterAnnotations(rawCode, lang, [
...annotationNames,
"from",
"focus",
])

// import external code if needed and re-run annotations extraction
const fromAnnotations = annotations.filter(
Expand All @@ -29,10 +36,11 @@ export async function splitCodeAndAnnotations(
config.filepath,
range
)
// TODO remove 'from' annotation from the annotation names to avoid loops

const result = await extractLighterAnnotations(
externalFileContent,
lang
lang,
[...annotationNames, "focus"]
)
code = result.code
annotations = result.annotations
Expand Down
13 changes: 4 additions & 9 deletions packages/mdx/src/remark/lighter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,16 @@ import {
Annotation,
LANG_NAMES,
} from "@code-hike/lighter"
import { Code } from "utils"
import { annotationsMap } from "../mdx-client/annotations"
import { Code } from "../utils"
import { CodeAnnotation } from "../smooth-code"
import { annotationsMap } from "../mdx-client/annotations"

export type LighterAnnotation = Annotation

const annotationNames = [
"focus",
"from",
...Object.keys(annotationsMap),
]

export async function extractLighterAnnotations(
codeWithAnnotations: string,
lang: string
lang: string,
annotationNames: string[]
) {
return await extractAnnotations(
codeWithAnnotations,
Expand Down

0 comments on commit 4667c0f

Please sign in to comment.