Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add underline support #1527

Merged
merged 3 commits into from
Feb 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading