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
7251bb0a
Commit
7251bb0a
authored
May 08, 2022
by
Erik Reider
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplified markdown regex string
parent
19beafa5
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
26 deletions
+4
-26
notification.vala
src/notification/notification.vala
+4
-26
No files found.
src/notification/notification.vala
View file @
7251bb0a
...
@@ -57,7 +57,6 @@ namespace SwayNotificationCenter {
...
@@ -57,7 +57,6 @@ namespace SwayNotificationCenter {
private
int
carousel_empty_widget_index
=
0
;
private
int
carousel_empty_widget_index
=
0
;
private
static
Regex
tag_regex
;
private
static
Regex
tag_regex
;
private
static
Regex
tag_replace_regex
;
private
static
Regex
tag_unescape_regex
;
private
static
Regex
tag_unescape_regex
;
private
const
string
[]
TAGS
=
{
"b"
,
"u"
,
"i"
};
private
const
string
[]
TAGS
=
{
"b"
,
"u"
,
"i"
};
private
const
string
[]
UNESCAPE_CHARS
=
{
private
const
string
[]
UNESCAPE_CHARS
=
{
...
@@ -95,8 +94,7 @@ namespace SwayNotificationCenter {
...
@@ -95,8 +94,7 @@ namespace SwayNotificationCenter {
construct
{
construct
{
try
{
try
{
string
joined_tags
=
string
.
joinv
(
"|"
,
TAGS
);
string
joined_tags
=
string
.
joinv
(
"|"
,
TAGS
);
tag_regex
=
new
Regex
(
"</?(%s)>"
.
printf
(
joined_tags
));
tag_regex
=
new
Regex
(
"<(/?(?:%s))>"
.
printf
(
joined_tags
));
tag_replace_regex
=
new
Regex
(
"</?|>"
);
string
unescaped
=
string
.
joinv
(
"|"
,
UNESCAPE_CHARS
);
string
unescaped
=
string
.
joinv
(
"|"
,
UNESCAPE_CHARS
);
tag_unescape_regex
=
new
Regex
(
"&(?=%s)"
.
printf
(
unescaped
));
tag_unescape_regex
=
new
Regex
(
"&(?=%s)"
.
printf
(
unescaped
));
}
catch
(
Error
e
)
{
}
catch
(
Error
e
)
{
...
@@ -260,11 +258,9 @@ namespace SwayNotificationCenter {
...
@@ -260,11 +258,9 @@ namespace SwayNotificationCenter {
string
escaped
=
Markup
.
escape_text
(
text
);
string
escaped
=
Markup
.
escape_text
(
text
);
// Replace all valid tags brackets with <,</,> so that the
// Replace all valid tags brackets with <,</,> so that the
// markup parser only parses valid tags
// markup parser only parses valid tags
escaped
=
tag_regex
.
replace_eval
(
escaped
,
// Ex: <b>BOLD</b> -> <b>BOLD</b>
escaped
.
length
,
escaped
=
tag_regex
.
replace
(
escaped
,
escaped
.
length
,
0
,
"<\\1>"
);
0
,
RegexMatchFlags
.
NOTEMPTY
,
this
.
regex_tag_eval_cb
);
// Unescape a few characters that may have been double escaped
// Unescape a few characters that may have been double escaped
// Sending "<" in Discord would result in "&lt;" without this
// Sending "<" in Discord would result in "&lt;" without this
// &lt; -> <
// &lt; -> <
...
@@ -285,24 +281,6 @@ namespace SwayNotificationCenter {
...
@@ -285,24 +281,6 @@ namespace SwayNotificationCenter {
}
}
}
}
/**
* 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
()
{
public
void
click_default_action
()
{
action_clicked
(
param
.
default_action
,
true
);
action_clicked
(
param
.
default_action
,
true
);
}
}
...
...
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