updates: fix escaping markup
This commit is contained in:
parent
d46b368606
commit
0e2de54029
1 changed files with 14 additions and 9 deletions
|
|
@ -2,7 +2,7 @@ import Palette from "@/services/palette";
|
||||||
import Updates, { Repo as IRepo, Update as IUpdate } from "@/services/updates";
|
import Updates, { Repo as IRepo, Update as IUpdate } from "@/services/updates";
|
||||||
import { MenuItem } from "@/utils/widgets";
|
import { MenuItem } from "@/utils/widgets";
|
||||||
import PopdownWindow from "@/widgets/popdownwindow";
|
import PopdownWindow from "@/widgets/popdownwindow";
|
||||||
import { bind, execAsync, Variable } from "astal";
|
import { bind, execAsync, GLib, Variable } from "astal";
|
||||||
import { App, Astal, Gtk } from "astal/gtk3";
|
import { App, Astal, Gtk } from "astal/gtk3";
|
||||||
|
|
||||||
const constructItem = (label: string, exec: string, quiet = true) =>
|
const constructItem = (label: string, exec: string, quiet = true) =>
|
||||||
|
|
@ -33,7 +33,12 @@ const Update = (update: IUpdate) => {
|
||||||
xalign={0}
|
xalign={0}
|
||||||
label={bind(Palette.get_default(), "colours").as(
|
label={bind(Palette.get_default(), "colours").as(
|
||||||
c =>
|
c =>
|
||||||
`${update.name} <span foreground="${c.teal}">(${update.version.old} -> ${update.version.new})</span>\n <span foreground="${c.subtext0}">${update.description}</span>`
|
`${update.name} <span foreground="${c.teal}">(${update.version.old} -> ${
|
||||||
|
update.version.new
|
||||||
|
})</span>\n <span foreground="${c.subtext0}">${GLib.markup_escape_text(
|
||||||
|
update.description,
|
||||||
|
update.description.length
|
||||||
|
)}</span>`
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</button>
|
</button>
|
||||||
|
|
@ -69,6 +74,11 @@ const Repo = ({ repo, first }: { repo: IRepo; first?: boolean }) => {
|
||||||
const News = ({ news }: { news: string }) => {
|
const News = ({ news }: { news: string }) => {
|
||||||
const expanded = Variable(true);
|
const expanded = Variable(true);
|
||||||
|
|
||||||
|
news = news
|
||||||
|
.replaceAll("\n\n\x1b", "\n\n") // Remove unopened \x1b[0m after each piece of news
|
||||||
|
.replace(/^([0-9]{4}-[0-9]{2}-[0-9]{2} .+)$/gm, "<b>$1</b>") // Make titles bold
|
||||||
|
.replaceAll("\x1b[0m", "</span>"); // Replace reset code with end span
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<box vertical className="repo">
|
<box vertical className="repo">
|
||||||
<button className="wrapper" cursor="pointer" onClicked={() => expanded.set(!expanded.get())}>
|
<button className="wrapper" cursor="pointer" onClicked={() => expanded.set(!expanded.get())}>
|
||||||
|
|
@ -89,13 +99,8 @@ const News = ({ news }: { news: string }) => {
|
||||||
useMarkup
|
useMarkup
|
||||||
xalign={0}
|
xalign={0}
|
||||||
className="news"
|
className="news"
|
||||||
label={bind(Palette.get_default(), "teal").as(c =>
|
label={bind(Palette.get_default(), "teal").as(
|
||||||
news
|
c => news.replaceAll("\x1b[36m", `<span foreground="${c}">`) // Replace color codes with html spans
|
||||||
.slice(0, news.lastIndexOf("\n")) // Remove last line cause it contains an unopened \x1b[0m
|
|
||||||
.replace(/^([0-9]{4}-[0-9]{2}-[0-9]{2} .+)$/gm, "<b>$1</b>") // Make titles bold
|
|
||||||
// Replace color codes with html spans
|
|
||||||
.replaceAll("\x1b[36m", `<span foreground="${c}">`)
|
|
||||||
.replaceAll("\x1b[0m", "</span>")
|
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</revealer>
|
</revealer>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue