Skip to content

Commit 0a46c65

Browse files
committed
Fixes #354
1 parent 190fc50 commit 0a46c65

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## [2.6.3] - 2024-XX-XX
44
- Fix issue [#352](https://github.com/intersystems/language-server/issues/352): Hide Deprecated classes and class members from completion lists by default
55
- Fix issue [#353](https://github.com/intersystems/language-server/issues/353): Fix keyword completion for ClassMethods
6+
- Fix issue [#354](https://github.com/intersystems/language-server/issues/354): Improve conversion of Documatic HTML to Markdown
67

78
## [2.6.2] - 2024-10-07
89
- Fix issue [#345](https://github.com/intersystems/language-server/issues/345): Add intellisense for variables passed by reference as method arguments

server/src/utils/functions.ts

+16-21
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,28 @@ const turndown = new TurndownService({
1919
blankReplacement: (content, node: HTMLElement) => node.nodeName == 'SPAN' ? node.outerHTML : ''
2020
});
2121
turndown.remove("style");
22-
turndown.keep(["span", "table", "tr", "td"]);
22+
turndown.keep(["span", "table", "tr", "td", "u"]);
2323
turndown.addRule("pre",{
2424
filter: "pre",
2525
replacement: function (content: string, node: HTMLElement) {
2626
let lang = "";
27-
content = content.replace(/\\\\/g,"\\").replace(/\\\[/g,"[").replace(/\\\]/g,"]");
27+
content = content.replace(/\\\\/g,"\\").replace(/\\\[/g,"[").replace(/\\\]/g,"]")
28+
.replace(/&/g,"&").replace(/&/g,"&")
29+
.replace(/&lt;/g,"<").replace(/&gt;/g,">");
2830
let attrVal = node.getAttribute("LANGUAGE");
29-
if (attrVal === null) {
31+
if (attrVal == null) {
3032
try {
3133
let obj = JSON.parse(content);
32-
if (obj && typeof obj === "object") {
34+
if (typeof obj == "object") {
3335
lang = "json";
3436
}
35-
} catch {
36-
lang = "objectscript";
37-
}
37+
} catch {}
3838
}
3939
else {
40-
switch (attrVal.toUpperCase()) {
40+
switch (attrVal.split("!").shift().toUpperCase()) {
4141
case "OBJECTSCRIPT":
4242
case "COS":
43+
case "INT":
4344
lang = "objectscript";
4445
break;
4546
case "SQL":
@@ -55,7 +56,8 @@ turndown.addRule("pre",{
5556
lang = "java";
5657
break;
5758
case "JAVASCRIPT":
58-
lang = "javascript";
59+
case "JS":
60+
lang = attrVal.split("!").pop().toUpperCase() == "JSON" ? "json" : "javascript";
5961
break;
6062
case "CSS":
6163
lang = "css";
@@ -2278,26 +2280,19 @@ export function findOpenParen(doc: TextDocument, parsed: compressedline[], line:
22782280
}
22792281

22802282
/**
2281-
* Convert a class documentation string as Markdown.
2283+
* Convert a class documentation string to Markdown.
22822284
*
2283-
* @param html The class documentation string to convert.
2285+
* @param html The class documentation HTML string to convert.
22842286
*/
22852287
export function documaticHtmlToMarkdown(html: string): string {
22862288
let root = parse(html);
22872289
for (const elem of root.getElementsByTagName("example")) {
22882290
const newElem = parse("<pre></pre>").getElementsByTagName("pre")[0];
2289-
const lang = elem.getAttribute("language");
2290-
if (lang !== undefined) {
2291-
newElem.setAttribute("language",lang);
2292-
}
2293-
let text = elem.innerText;
2294-
if (lang?.toLowerCase() === "html") {
2295-
text = elem.innerHTML.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
2296-
}
2297-
newElem.textContent = text;
2291+
newElem.setAttribute("language",elem.getAttribute("language") ?? "COS");
2292+
newElem.textContent = elem.innerHTML.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
22982293
elem.parentNode.exchangeChild(elem,newElem);
22992294
}
2300-
return turndown.turndown(root.toString());
2295+
return turndown.turndown(root.toString().replace(/&/g,"&amp;"));
23012296
}
23022297

23032298
/**

0 commit comments

Comments
 (0)