Skip to content

Commit

Permalink
Fixes #354
Browse files Browse the repository at this point in the history
  • Loading branch information
isc-bsaviano committed Oct 21, 2024
1 parent 190fc50 commit 0a46c65
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 16 additions & 21 deletions server/src/utils/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(/&lt;/g,"<").replace(/&gt;/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":
Expand All @@ -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";
Expand Down Expand Up @@ -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("<pre></pre>").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,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
}
newElem.textContent = text;
newElem.setAttribute("language",elem.getAttribute("language") ?? "COS");
newElem.textContent = elem.innerHTML.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
elem.parentNode.exchangeChild(elem,newElem);
}
return turndown.turndown(root.toString());
return turndown.turndown(root.toString().replace(/&/g,"&amp;"));
}

/**
Expand Down

0 comments on commit 0a46c65

Please sign in to comment.