Skip to content

Commit bb178b3

Browse files
authored
Merge pull request #1527 from Heinrich-XIAO/master
feat: add underline support
2 parents 641727a + 930f3c1 commit bb178b3

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

core/Util/Util.vala

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1101,10 +1101,15 @@ We hope you’ll enjoy using Planify!""");
11011101
Regex mailto_regex = /(?P<mailto>[a-zA-Z0-9\._\%\+\-]+@[a-zA-Z0-9\-\.]+\.[a-zA-Z]+(\S*))/; // vala-lint=space-before-paren
11021102
Regex url_regex = /(?P<url>(http|https)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]+(\/\S*))/; // vala-lint=space-before-paren
11031103
Regex url_markdown = new Regex ("\\[([^\\]]+)\\]\\(([^\\)]+)\\)");
1104-
1104+
11051105
Regex italic_bold_regex = /\*\*\*(.*?)\*\*\*/; // vala-lint=space-before-paren
11061106
Regex bold_regex = /\*\*(.*?)\*\*/; // vala-lint=space-before-paren
11071107
Regex italic_regex = /\*(.*?)\*/; // vala-lint=space-before-paren
1108+
Regex underline_regex = /_(.*?)_/; // vala-lint=space-before-paren
1109+
1110+
Regex italic_bold_underline_regex = /\*\*\*_([^*]+)_\*\*\*/; // vala-lint=space-before-paren
1111+
Regex bold_underline_regex = /\*\*_([^*]+)_\*\*/; // vala-lint=space-before-paren
1112+
Regex italic_underline_regex = /\*_(.*?)_\*/; // vala-lint=space-before-paren
11081113

11091114
MatchInfo info;
11101115

@@ -1155,6 +1160,34 @@ We hope you’ll enjoy using Planify!""");
11551160
} while (info.next ());
11561161
}
11571162

1163+
Gee.ArrayList<RegexMarkdown> italic_bold_underline = new Gee.ArrayList<RegexMarkdown> ();
1164+
if (italic_bold_underline_regex.match (text, 0, out info)) {
1165+
do {
1166+
italic_bold_underline.add (new RegexMarkdown (info.fetch (0), info.fetch (1)));
1167+
} while (info.next ());
1168+
}
1169+
1170+
Gee.ArrayList<RegexMarkdown> bold_underline = new Gee.ArrayList<RegexMarkdown> ();
1171+
if (bold_underline_regex.match (text, 0, out info)) {
1172+
do {
1173+
bold_underline.add (new RegexMarkdown (info.fetch (0), info.fetch (1)));
1174+
} while (info.next ());
1175+
}
1176+
1177+
Gee.ArrayList<RegexMarkdown> italic_underline = new Gee.ArrayList<RegexMarkdown> ();
1178+
if (italic_underline_regex.match (text, 0, out info)) {
1179+
do {
1180+
italic_underline.add (new RegexMarkdown (info.fetch (0), info.fetch (1)));
1181+
} while (info.next ());
1182+
}
1183+
1184+
Gee.ArrayList<RegexMarkdown> underlines = new Gee.ArrayList<RegexMarkdown> ();
1185+
if (underline_regex.match (text, 0, out info)) {
1186+
do {
1187+
underlines.add (new RegexMarkdown (info.fetch (0), info.fetch (1)));
1188+
} while (info.next ());
1189+
}
1190+
11581191
string converted = text;
11591192

11601193
foreach (RegexMarkdown m in markdown_urls) {
@@ -1173,6 +1206,22 @@ We hope you’ll enjoy using Planify!""");
11731206
converted = converted.replace (email, @"<a href=\"mailto:$email\">$email</a>");
11741207
});
11751208

1209+
foreach (RegexMarkdown m in italic_bold_underline) {
1210+
converted = converted.replace (m.match, "<i><b><u>" + m.text + "</u></b></i>");
1211+
}
1212+
1213+
foreach (RegexMarkdown m in bold_underline) {
1214+
converted = converted.replace (m.match, "<b><u>" + m.text + "</u></b>");
1215+
}
1216+
1217+
foreach (RegexMarkdown m in italic_underline) {
1218+
converted = converted.replace (m.match, "<i><u>" + m.text + "</u></i>");
1219+
}
1220+
1221+
foreach (RegexMarkdown m in underlines) {
1222+
converted = converted.replace (m.match, "<u>" + m.text + "</u>");
1223+
}
1224+
11761225
foreach (RegexMarkdown m in italic_bold) {
11771226
converted = converted.replace (m.match, "<i><b>" + m.text + "</b></i>");
11781227
}

0 commit comments

Comments
 (0)