mirror of
https://github.com/noctalia-dev/noctalia-shell.git
synced 2026-05-11 17:08:27 +08:00
Enhance custom tooltip parsing
This commit is contained in:
@@ -247,17 +247,25 @@ Item {
|
||||
}
|
||||
|
||||
function toHtml(str) {
|
||||
const htmlRegex = /<\/?[a-zA-Z][\s\S]*>/;
|
||||
const htmlTagRegex = /<\/?[a-zA-Z][^>]*>/g;
|
||||
const placeholders = [];
|
||||
let i = 0;
|
||||
const protectedStr = str.replace(htmlTagRegex, tag => {
|
||||
placeholders.push(tag);
|
||||
return `___HTML_TAG_${i++}___`;
|
||||
});
|
||||
|
||||
if (htmlRegex.test(str)) {
|
||||
return str;
|
||||
}
|
||||
let escaped = protectedStr
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/"/g, """)
|
||||
.replace(/'/g, "'")
|
||||
.replace(/\r\n|\r|\n/g, "<br/>");
|
||||
|
||||
const escaped = str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
||||
escaped = escaped.replace(/___HTML_TAG_(\d+)___/g, (_, index) => placeholders[Number(index)]);
|
||||
|
||||
const withBreaks = escaped.replace(/\r\n|\r|\n/g, "<br/>");
|
||||
|
||||
return withBreaks;
|
||||
return escaped;
|
||||
}
|
||||
|
||||
function runTextCommand() {
|
||||
|
||||
Reference in New Issue
Block a user