Skip to content

Commit

Permalink
Merge pull request #1527 from Heinrich-XIAO/master
Browse files Browse the repository at this point in the history
feat: add underline support
  • Loading branch information
alainm23 authored Feb 4, 2025
2 parents 641727a + 930f3c1 commit bb178b3
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion core/Util/Util.vala
Original file line number Diff line number Diff line change
Expand Up @@ -1101,10 +1101,15 @@ We hope you’ll enjoy using Planify!""");
Regex mailto_regex = /(?P<mailto>[a-zA-Z0-9\._\%\+\-]+@[a-zA-Z0-9\-\.]+\.[a-zA-Z]+(\S*))/; // vala-lint=space-before-paren
Regex url_regex = /(?P<url>(http|https)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]+(\/\S*))/; // vala-lint=space-before-paren
Regex url_markdown = new Regex ("\\[([^\\]]+)\\]\\(([^\\)]+)\\)");

Regex italic_bold_regex = /\*\*\*(.*?)\*\*\*/; // vala-lint=space-before-paren
Regex bold_regex = /\*\*(.*?)\*\*/; // vala-lint=space-before-paren
Regex italic_regex = /\*(.*?)\*/; // vala-lint=space-before-paren
Regex underline_regex = /_(.*?)_/; // vala-lint=space-before-paren

Regex italic_bold_underline_regex = /\*\*\*_([^*]+)_\*\*\*/; // vala-lint=space-before-paren
Regex bold_underline_regex = /\*\*_([^*]+)_\*\*/; // vala-lint=space-before-paren
Regex italic_underline_regex = /\*_(.*?)_\*/; // vala-lint=space-before-paren

MatchInfo info;

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

Gee.ArrayList<RegexMarkdown> italic_bold_underline = new Gee.ArrayList<RegexMarkdown> ();
if (italic_bold_underline_regex.match (text, 0, out info)) {
do {
italic_bold_underline.add (new RegexMarkdown (info.fetch (0), info.fetch (1)));
} while (info.next ());
}

Gee.ArrayList<RegexMarkdown> bold_underline = new Gee.ArrayList<RegexMarkdown> ();
if (bold_underline_regex.match (text, 0, out info)) {
do {
bold_underline.add (new RegexMarkdown (info.fetch (0), info.fetch (1)));
} while (info.next ());
}

Gee.ArrayList<RegexMarkdown> italic_underline = new Gee.ArrayList<RegexMarkdown> ();
if (italic_underline_regex.match (text, 0, out info)) {
do {
italic_underline.add (new RegexMarkdown (info.fetch (0), info.fetch (1)));
} while (info.next ());
}

Gee.ArrayList<RegexMarkdown> underlines = new Gee.ArrayList<RegexMarkdown> ();
if (underline_regex.match (text, 0, out info)) {
do {
underlines.add (new RegexMarkdown (info.fetch (0), info.fetch (1)));
} while (info.next ());
}

string converted = text;

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

foreach (RegexMarkdown m in italic_bold_underline) {
converted = converted.replace (m.match, "<i><b><u>" + m.text + "</u></b></i>");
}

foreach (RegexMarkdown m in bold_underline) {
converted = converted.replace (m.match, "<b><u>" + m.text + "</u></b>");
}

foreach (RegexMarkdown m in italic_underline) {
converted = converted.replace (m.match, "<i><u>" + m.text + "</u></i>");
}

foreach (RegexMarkdown m in underlines) {
converted = converted.replace (m.match, "<u>" + m.text + "</u>");
}

foreach (RegexMarkdown m in italic_bold) {
converted = converted.replace (m.match, "<i><b>" + m.text + "</b></i>");
}
Expand Down

0 comments on commit bb178b3

Please sign in to comment.