Skip to content

Commit bd03e27

Browse files
committed
Handle Markdown paste result typing: ensure synchronous string return, fallback to null if unexpected promise is encountered.
1 parent 00a1f7e commit bd03e27

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

web/components/editor/paste-markdown.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,8 @@ export const markdownPasteHtml = (data: DataTransfer | null): string | null => {
7171

7272
// `breaks` off: in Markdown a single newline is a soft wrap, and treating it as a hard break
7373
// turns every wrapped paragraph into a run of short lines.
74-
return marked.parse(text, {async: false, gfm: true, breaks: false})
74+
const rendered = marked.parse(text, {async: false, gfm: true, breaks: false})
75+
// `async: false` makes this a string. Older type definitions can't express that, and paste has to
76+
// stay synchronous either way, so narrow rather than cast: a promise means paste as usual.
77+
return typeof rendered === 'string' ? rendered : null
7578
}

0 commit comments

Comments
 (0)