@@ -2887,24 +2887,30 @@ const commentsTheme = {
2887
2887
// { scope: "comment.block", settings: { foreground: BLOCK_COMMENT } },
2888
2888
],
2889
2889
};
2890
- function extractCommentsFromCode(code, grammar, annotationNames) {
2890
+ function extractCommentsFromCode(code, grammar, lang, annotationNames) {
2891
2891
const lines = !grammar
2892
2892
? highlightText(code)
2893
2893
: highlightTokens(code, grammar, commentsTheme);
2894
2894
const allAnnotations = [];
2895
2895
let lineNumber = 1;
2896
- const cleanLines = lines
2896
+ const newCode = lines
2897
2897
.map((line) => {
2898
2898
const { annotations, lineWithoutComments } = getAnnotationsFromLine(line, annotationNames, lineNumber);
2899
2899
allAnnotations.push(...annotations);
2900
- if (lineWithoutComments) {
2901
- lineNumber++ ;
2900
+ if (! lineWithoutComments) {
2901
+ return null ;
2902
2902
}
2903
- return lineWithoutComments;
2903
+ const lineText = lineWithoutComments.map((t) => t.content).join("");
2904
+ // remove mdx comment wrapper https://github.com/code-hike/lighter/issues/23
2905
+ if (lang === "mdx" &&
2906
+ annotations.length > 0 &&
2907
+ lineText.trim() === "{}") {
2908
+ return null;
2909
+ }
2910
+ lineNumber++;
2911
+ return lineText;
2904
2912
})
2905
- .filter((line) => line !== null);
2906
- const newCode = cleanLines
2907
- .map((line) => line.map((t) => t.content).join(""))
2913
+ .filter((line) => line !== null)
2908
2914
.join(`\n`);
2909
2915
return { newCode, annotations: allAnnotations };
2910
2916
}
@@ -3306,7 +3312,7 @@ async function extractAnnotations(code, lang, annotationNames = []) {
3306
3312
}
3307
3313
await preloadGrammars([lang]);
3308
3314
const { grammar } = getGrammar(lang);
3309
- const { newCode, annotations } = extractCommentsFromCode(code, grammar, annotationNames);
3315
+ const { newCode, annotations } = extractCommentsFromCode(code, grammar, lang, annotationNames);
3310
3316
return { code: newCode, annotations };
3311
3317
}
3312
3318
async function getThemeColors(themeOrThemeName) {
0 commit comments