mirror of
https://github.com/zoriya/noctalia-shell.git
synced 2026-06-06 20:12:29 +00:00
Enhanced rich text parsing for specific plain text content
This commit is contained in:
@@ -158,7 +158,7 @@ Item {
|
|||||||
const parsed = JSON.parse(lineToParse);
|
const parsed = JSON.parse(lineToParse);
|
||||||
const text = parsed.text || "";
|
const text = parsed.text || "";
|
||||||
const icon = parsed.icon || "";
|
const icon = parsed.icon || "";
|
||||||
const tooltip = parsed.tooltip || "";
|
let tooltip = parsed.tooltip || "";
|
||||||
|
|
||||||
if (checkCollapse(text)) {
|
if (checkCollapse(text)) {
|
||||||
_dynamicText = "";
|
_dynamicText = "";
|
||||||
@@ -169,7 +169,8 @@ Item {
|
|||||||
|
|
||||||
_dynamicText = text;
|
_dynamicText = text;
|
||||||
_dynamicIcon = icon;
|
_dynamicIcon = icon;
|
||||||
_dynamicTooltip = tooltip;
|
|
||||||
|
_dynamicTooltip = toHtml(tooltip);
|
||||||
return;
|
return;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
Logger.w("CustomButton", `Failed to parse JSON. Content: "${lineToParse}"`);
|
Logger.w("CustomButton", `Failed to parse JSON. Content: "${lineToParse}"`);
|
||||||
@@ -185,7 +186,7 @@ Item {
|
|||||||
|
|
||||||
_dynamicText = contentStr;
|
_dynamicText = contentStr;
|
||||||
_dynamicIcon = "";
|
_dynamicIcon = "";
|
||||||
_dynamicTooltip = "";
|
_dynamicTooltip = toHtml(contentStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkCollapse(text) {
|
function checkCollapse(text) {
|
||||||
@@ -244,6 +245,25 @@ Item {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toHtml(str) {
|
||||||
|
const htmlRegex = /<\/?[a-zA-Z][\s\S]*>/;
|
||||||
|
|
||||||
|
if (htmlRegex.test(str)) {
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
const escaped = str
|
||||||
|
.replace(/&/g, "&")
|
||||||
|
.replace(/</g, "<")
|
||||||
|
.replace(/>/g, ">")
|
||||||
|
.replace(/"/g, """)
|
||||||
|
.replace(/'/g, "'");
|
||||||
|
|
||||||
|
const withBreaks = escaped.replace(/\r\n|\r|\n/g, "<br/>");
|
||||||
|
|
||||||
|
return withBreaks;
|
||||||
|
}
|
||||||
|
|
||||||
function runTextCommand() {
|
function runTextCommand() {
|
||||||
if (!textCommand || textCommand.length === 0)
|
if (!textCommand || textCommand.length === 0)
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user