From 5973820ce65a0f730338d5294997586170303bd5 Mon Sep 17 00:00:00 2001 From: Pinghao Wu Date: Thu, 1 Aug 2024 20:03:13 +0800 Subject: [PATCH 1/3] completion: fix markdown rendering CodeMirror takes info as raw text if string, a function that returns dom is needed for HTML. --- src/features/completion.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/features/completion.ts b/src/features/completion.ts index 9c5f2d1..860316d 100644 --- a/src/features/completion.ts +++ b/src/features/completion.ts @@ -30,6 +30,7 @@ import { } from "../utils/json-pointers"; import { MODES, TOKENS } from "../constants"; import { JSONMode } from "../types"; +import { el } from "../utils/dom"; import { renderMarkdown } from "../utils/markdown"; import { DocumentParser, getDefaultParser } from "../parsers"; @@ -308,7 +309,10 @@ export class JSONCompletion { ), type: "property", detail: typeStr, - info: renderMarkdown(description), + info: () => + el("div", { + inner: renderMarkdown(description), + }), }; collector.add(this.applySnippetCompletion(completion)); } From a8ab63e8e02fd6a9512966d5f26a9ed5081c0567 Mon Sep 17 00:00:00 2001 From: Pinghao Wu Date: Thu, 1 Aug 2024 20:05:26 +0800 Subject: [PATCH 2/3] tests: completion: support rendering function at info --- src/features/__tests__/__helpers__/completion.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/features/__tests__/__helpers__/completion.ts b/src/features/__tests__/__helpers__/completion.ts index fc4ff78..1292b44 100644 --- a/src/features/__tests__/__helpers__/completion.ts +++ b/src/features/__tests__/__helpers__/completion.ts @@ -66,7 +66,10 @@ export async function expectCompletion( } const filteredResults = result.options.map((item) => ({ detail: item.detail, - info: item.info, + info: + typeof item.info === "function" + ? (item.info(item) as HTMLElement).innerText + : item.info, label: item.label, type: item.type, apply: typeof item.apply === "string" ? item.apply : undefined, From af8869b5735627104d73024ae60f61ab285d9f37 Mon Sep 17 00:00:00 2001 From: Pinghao Wu Date: Thu, 1 Aug 2024 20:34:22 +0800 Subject: [PATCH 3/3] .changeset: add for completion markdown rendering fix --- .changeset/rich-tables-hug.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/rich-tables-hug.md diff --git a/.changeset/rich-tables-hug.md b/.changeset/rich-tables-hug.md new file mode 100644 index 0000000..b1e3475 --- /dev/null +++ b/.changeset/rich-tables-hug.md @@ -0,0 +1,5 @@ +--- +"codemirror-json-schema": patch +--- + +Fix description markdown rendering in completion