Skip to content

Commit 29e2da5

Browse files
xdavidwuimolorhe
andauthored
Fix description markdown rendering in completion (#137)
Before this, markdown-rendered HTML from description was rendered as plain text. To test, use the demo with tsconfig.json schema and type a new property `ts` to trigger completion for `ts-node`, which description contains a link. --------- Co-authored-by: Samuel <[email protected]>
1 parent bfbe613 commit 29e2da5

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

.changeset/rich-tables-hug.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"codemirror-json-schema": patch
3+
---
4+
5+
Fix description markdown rendering in completion

src/features/__tests__/__helpers__/completion.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ export async function expectCompletion(
6666
}
6767
const filteredResults = result.options.map((item) => ({
6868
detail: item.detail,
69-
info: item.info,
69+
info:
70+
typeof item.info === "function"
71+
? (item.info(item) as HTMLElement).innerText
72+
: item.info,
7073
label: item.label,
7174
type: item.type,
7275
apply: typeof item.apply === "string" ? item.apply : undefined,

src/features/completion.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
} from "../utils/json-pointers";
3131
import { MODES, TOKENS } from "../constants";
3232
import { JSONMode } from "../types";
33+
import { el } from "../utils/dom";
3334
import { renderMarkdown } from "../utils/markdown";
3435
import { DocumentParser, getDefaultParser } from "../parsers";
3536

@@ -308,7 +309,10 @@ export class JSONCompletion {
308309
),
309310
type: "property",
310311
detail: typeStr,
311-
info: renderMarkdown(description),
312+
info: () =>
313+
el("div", {
314+
inner: renderMarkdown(description),
315+
}),
312316
};
313317
collector.add(this.applySnippetCompletion(completion));
314318
}

0 commit comments

Comments
 (0)