UNPKG

codemirror-languageservice

Version:

Integrate a Language Server Protocol compatible language service into CodeMirror

67 lines 1.84 kB
/** * Process markdown into a DOM. * * @param parent * The container DOM element to append the DOM nodes to. * @param markdown * The markdown to process. * @param options * Additional options. */ async function processMarkdown(parent, markdown, options) { if (!markdown) { return; } const nodes = await options.markdownToDom(markdown); if (!nodes) { return; } if (typeof nodes !== 'string' && Symbol.iterator in nodes) { parent.append(...nodes); } else { parent.append(nodes); } } /** * Convert LSP markup content or a marked string into a DOM. * * @param contents * The LSP contents to process. * @param parent * The container node to append the DOM nodes to. * @param options * Additional options. * @returns * The parent container. */ export async function fromMarkupContent(contents, parent, options) { if (Array.isArray(contents)) { for (const content of contents) { await fromMarkupContent(content, parent, options); } } else if (typeof contents === 'string') { await processMarkdown(parent, contents, options); } else if ('kind' in contents) { if (contents.kind === 'markdown') { await processMarkdown(parent, contents.value, options); } else { const paragraph = document.createElement('p'); paragraph.append(contents.value); parent.append(paragraph); } } else { const pre = document.createElement('pre'); const code = document.createElement('code'); code.classList.add(`language-${contents.language}`); code.append(contents.value); pre.append(code); parent.append(pre); } return parent; } //# sourceMappingURL=markup-content.js.map