diff --git a/CHANGELOG.md b/CHANGELOG.md index 58102bb..6e25a65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## [2.6.3] - 2024-XX-XX - Fix issue [#352](https://github.com/intersystems/language-server/issues/352): Hide Deprecated classes and class members from completion lists by default - Fix issue [#353](https://github.com/intersystems/language-server/issues/353): Fix keyword completion for ClassMethods +- Fix issue [#354](https://github.com/intersystems/language-server/issues/354): Improve conversion of Documatic HTML to Markdown ## [2.6.2] - 2024-10-07 - Fix issue [#345](https://github.com/intersystems/language-server/issues/345): Add intellisense for variables passed by reference as method arguments diff --git a/server/src/utils/functions.ts b/server/src/utils/functions.ts index 788e3fc..52fc811 100644 --- a/server/src/utils/functions.ts +++ b/server/src/utils/functions.ts @@ -19,27 +19,28 @@ const turndown = new TurndownService({ blankReplacement: (content, node: HTMLElement) => node.nodeName == 'SPAN' ? node.outerHTML : '' }); turndown.remove("style"); -turndown.keep(["span", "table", "tr", "td"]); +turndown.keep(["span", "table", "tr", "td", "u"]); turndown.addRule("pre",{ filter: "pre", replacement: function (content: string, node: HTMLElement) { let lang = ""; - content = content.replace(/\\\\/g,"\\").replace(/\\\[/g,"[").replace(/\\\]/g,"]"); + content = content.replace(/\\\\/g,"\\").replace(/\\\[/g,"[").replace(/\\\]/g,"]") + .replace(/&/g,"&").replace(/&/g,"&") + .replace(/</g,"<").replace(/>/g,">"); let attrVal = node.getAttribute("LANGUAGE"); - if (attrVal === null) { + if (attrVal == null) { try { let obj = JSON.parse(content); - if (obj && typeof obj === "object") { + if (typeof obj == "object") { lang = "json"; } - } catch { - lang = "objectscript"; - } + } catch {} } else { - switch (attrVal.toUpperCase()) { + switch (attrVal.split("!").shift().toUpperCase()) { case "OBJECTSCRIPT": case "COS": + case "INT": lang = "objectscript"; break; case "SQL": @@ -55,7 +56,8 @@ turndown.addRule("pre",{ lang = "java"; break; case "JAVASCRIPT": - lang = "javascript"; + case "JS": + lang = attrVal.split("!").pop().toUpperCase() == "JSON" ? "json" : "javascript"; break; case "CSS": lang = "css"; @@ -2278,26 +2280,19 @@ export function findOpenParen(doc: TextDocument, parsed: compressedline[], line: } /** - * Convert a class documentation string as Markdown. + * Convert a class documentation string to Markdown. * - * @param html The class documentation string to convert. + * @param html The class documentation HTML string to convert. */ export function documaticHtmlToMarkdown(html: string): string { let root = parse(html); for (const elem of root.getElementsByTagName("example")) { const newElem = parse("
").getElementsByTagName("pre")[0]; - const lang = elem.getAttribute("language"); - if (lang !== undefined) { - newElem.setAttribute("language",lang); - } - let text = elem.innerText; - if (lang?.toLowerCase() === "html") { - text = elem.innerHTML.replace(/&/g,"&").replace(//g,">"); - } - newElem.textContent = text; + newElem.setAttribute("language",elem.getAttribute("language") ?? "COS"); + newElem.textContent = elem.innerHTML.replace(/&/g,"&").replace(//g,">"); elem.parentNode.exchangeChild(elem,newElem); } - return turndown.turndown(root.toString()); + return turndown.turndown(root.toString().replace(/&/g,"&")); } /**