Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
X
ximper-shell-notification-center
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ximper Linux
ximper-shell-notification-center
Commits
7de2c71b
Unverified
Commit
7de2c71b
authored
Sep 26, 2023
by
Erik Reider
Committed by
GitHub
Sep 26, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test parsing markup without any hacks before using said hacks (#319)
parent
ea66e687
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
14 deletions
+21
-14
notification.vala
src/notification/notification.vala
+21
-14
No files found.
src/notification/notification.vala
View file @
7de2c71b
...
...
@@ -374,22 +374,29 @@ namespace SwayNotificationCenter {
// Markup
try
{
// Escapes all characters
string
escaped
=
Markup
.
escape_text
(
text
);
// Replace all valid tags brackets with <,</,> so that the
// markup parser only parses valid tags
// Ex: <b>BOLD</b> -> <b>BOLD</b>
escaped
=
tag_regex
.
replace
(
escaped
,
escaped
.
length
,
0
,
"<\\1>"
);
// Unescape a few characters that may have been double escaped
// Sending "<" in Discord would result in "&lt;" without this
// &lt; -> <
escaped
=
tag_unescape_regex
.
replace_literal
(
escaped
,
escaped
.
length
,
0
,
"&"
);
// Turns it back to markdown, defaults to original if not valid
Pango
.
AttrList
?
attr
=
null
;
string
?
buf
=
null
;
Pango
.
parse_markup
(
escaped
,
-
1
,
0
,
out
attr
,
out
buf
,
null
);
try
{
// Try parsing without any hacks
Pango
.
parse_markup
(
text
,
-
1
,
0
,
out
attr
,
out
buf
,
null
);
}
catch
(
Error
e
)
{
// Default to hack if the initial markup couldn't be parsed
// Escapes all characters
string
escaped
=
Markup
.
escape_text
(
text
);
// Replace all valid tags brackets with <,</,> so that the
// markup parser only parses valid tags
// Ex: <b>BOLD</b> -> <b>BOLD</b>
escaped
=
tag_regex
.
replace
(
escaped
,
escaped
.
length
,
0
,
"<\\1>"
);
// Unescape a few characters that may have been double escaped
// Sending "<" in Discord would result in "&lt;" without this
// &lt; -> <
escaped
=
tag_unescape_regex
.
replace_literal
(
escaped
,
escaped
.
length
,
0
,
"&"
);
// Turns it back to markup, defaults to original if not valid
Pango
.
parse_markup
(
escaped
,
-
1
,
0
,
out
attr
,
out
buf
,
null
);
}
this
.
body
.
set_text
(
buf
);
if
(
attr
!=
null
)
this
.
body
.
set_attributes
(
attr
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment