add pybutton and pytitle

This commit is contained in:
Fabio Pliger
2022-04-20 15:41:51 -05:00
parent f5b168a45e
commit 3aa3ba02be
5 changed files with 141 additions and 12 deletions

View File

@@ -9,4 +9,29 @@ const getLastPath = function (str) {
return str.split('\\').pop().split('/').pop();
}
export {addClasses, getLastPath}
function htmlDecode(input) {
var doc = new DOMParser().parseFromString(input, "text/html");
return ltrim(doc.documentElement.textContent);
}
function ltrim(code: string): string {
const lines = code.split("\n")
if (lines.length == 0)
return code
const lengths = lines
.filter((line) => line.trim().length != 0)
.map((line) => {
const [prefix] = line.match(/^\s*/)
return prefix.length
})
const k = Math.min(...lengths)
if (k != 0)
return lines.map((line) => line.substring(k)).join("\n")
else
return code
}
export {addClasses, getLastPath, ltrim, htmlDecode}