Skip to content

Commit

Permalink
Fix description markdown rendering in completion (#137)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
xdavidwu and imolorhe authored Sep 19, 2024
1 parent bfbe613 commit 29e2da5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/rich-tables-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"codemirror-json-schema": patch
---

Fix description markdown rendering in completion
5 changes: 4 additions & 1 deletion src/features/__tests__/__helpers__/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion src/features/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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));
}
Expand Down

0 comments on commit 29e2da5

Please sign in to comment.