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
b7c94361
Unverified
Commit
b7c94361
authored
May 05, 2022
by
Erik Reider
Committed by
GitHub
May 05, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed markup parsing unofficial tags (#117)
* Fixed markup parsing unofficial tags * Added comments and some small refactoring
parent
042f1e61
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
19 deletions
+52
-19
notiDaemon.vala
src/notiDaemon/notiDaemon.vala
+0
-1
notification.vala
src/notification/notification.vala
+52
-18
No files found.
src/notiDaemon/notiDaemon.vala
View file @
b7c94361
...
...
@@ -106,7 +106,6 @@ namespace SwayNotificationCenter {
"body"
,
"body-markup"
,
"body-images"
,
"body-hyperlinks"
,
"persistence"
,
"synchronous"
,
"private-synchronous"
,
...
...
src/notification/notification.vala
View file @
b7c94361
...
...
@@ -51,6 +51,20 @@ namespace SwayNotificationCenter {
private
int
carousel_empty_widget_index
=
0
;
private
static
Regex
tag_regex
;
private
static
Regex
tag_replace_regex
;
private
const
string
[]
TAGS
=
{
"b"
,
"u"
,
"i"
};
construct
{
try
{
string
joined_tags
=
string
.
joinv
(
"|"
,
TAGS
);
tag_regex
=
new
Regex
(
@"</?($joined_tags)>"
);
tag_replace_regex
=
new
Regex
(
"</?|>"
);
}
catch
(
Error
e
)
{
stderr
.
printf
(
"Invalid regex: %s"
,
e
.
message
);
}
}
public
Notification
(
NotifyParams
param
,
NotiDaemon
notiDaemon
)
{
build_noti
(
param
,
notiDaemon
);
...
...
@@ -184,12 +198,12 @@ namespace SwayNotificationCenter {
var
img
=
img_paths
[
0
];
var
file
=
File
.
new_for_path
(
img
);
if
(
img
.
length
>
0
&&
file
.
query_exists
())
{
const
int
max_width
=
200
;
const
int
max_height
=
100
;
const
int
MAX_WIDTH
=
200
;
const
int
MAX_HEIGHT
=
100
;
var
buf
=
new
Gdk
.
Pixbuf
.
from_file_at_scale
(
file
.
get_path
(),
max_width
,
max_height
,
MAX_WIDTH
,
MAX_HEIGHT
,
true
);
this
.
body_image
.
set_from_pixbuf
(
buf
);
this
.
body_image
.
show
();
...
...
@@ -200,29 +214,49 @@ namespace SwayNotificationCenter {
}
}
// Markup
try
{
// Escapes text just incase it's not escaped yet
text
=
Markup
.
escape_text
(
text
);
// Turns it back to markdown, defaults to escaped if not valid
// Escapes all characters
string
escaped
=
Markup
.
escape_text
(
text
);
// Replace all valid tags brackets with <,</,> so that the
// markup parser only parses valid tags
escaped
=
tag_regex
.
replace_eval
(
escaped
,
escaped
.
length
,
0
,
RegexMatchFlags
.
NOTEMPTY
,
this
.
regex_tag_eval_cb
);
// Turns it back to markdown, defaults to original if not valid
Pango
.
AttrList
?
attr
=
null
;
string
?
buf
=
null
;
Pango
.
parse_markup
(
text
,
-
1
,
0
,
out
attr
,
out
buf
,
null
);
Pango
.
parse_markup
(
escaped
,
-
1
,
0
,
out
attr
,
out
buf
,
null
);
this
.
body
.
set_
markup
(
buf
);
this
.
body
.
set_
text
(
buf
);
if
(
attr
!=
null
)
this
.
body
.
set_attributes
(
attr
);
// Something has gone wrong... Use the escaped text instead
if
(
this
.
body
.
get_text
().
length
==
0
&&
buf
.
length
!=
0
)
{
stderr
.
printf
(
"Could for some reason not set markup. Text: %s\n"
,
text
);
this
.
body
.
set_markup
(
text
);
}
}
catch
(
Error
e
)
{
stderr
.
printf
(
"Could not parse Pango markup %s: %s\n"
,
text
,
e
.
message
);
this
.
body
.
set_markup
(
text
);
// Sets the original text
this
.
body
.
set_text
(
text
);
}
}
/**
* Replaces ">" and "<" with their character counterpart if the
* tag is valid.
*/
private
bool
regex_tag_eval_cb
(
MatchInfo
match_info
,
StringBuilder
result
)
{
try
{
string
tag
=
match_info
.
fetch
(
0
);
// Removes the tag backets: </b> -> b
var
res
=
tag_replace_regex
.
replace
(
tag
,
tag
.
length
,
0
,
""
);
if
(!(
res
in
TAGS
))
return
false
;
result
.
append
(
tag
.
replace
(
"<"
,
"<"
).
replace
(
">"
,
">"
));
}
catch
(
Error
e
)
{
stderr
.
printf
(
"Regex eval error: %s\n"
,
e
.
message
);
}
return
false
;
}
public
void
click_default_action
()
{
...
...
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