From 6f709338709435b2cf651e807ee1984370797243 Mon Sep 17 00:00:00 2001 From: Heinrich-XIAO <74563446+Heinrich-XIAO@users.noreply.github.com> Date: Tue, 4 Feb 2025 00:10:14 +0000 Subject: [PATCH] feat: add underline support --- core/Util/Util.vala | 63 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 55 insertions(+), 8 deletions(-) diff --git a/core/Util/Util.vala b/core/Util/Util.vala index de769896d..3f33eee62 100644 --- a/core/Util/Util.vala +++ b/core/Util/Util.vala @@ -1098,13 +1098,18 @@ We hope you’ll enjoy using Planify!"""); var text = escape_text (_text); try { - Regex mailto_regex = /(?P[a-zA-Z0-9\._\%\+\-]+@[a-zA-Z0-9\-\.]+\.[a-zA-Z]+(\S*))/; // vala-lint=space-before-paren - Regex url_regex = /(?P(http|https)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]+(\/\S*))/; // vala-lint=space-before-paren + Regex mailto_regex = /(?P[a-zA-Z0-9\._\%\+\-]+@[a-zA-Z0-9\-\.]+\.[a-zA-Z]+(\S*))/; + Regex url_regex = /(?P(http|https)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]+(\/\S*))/; 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 italic_bold_regex = /\*\*\*(.*?)\*\*\*/; + Regex bold_regex = /\*\*(.*?)\*\*/; + Regex italic_regex = /\*(.*?)\*/; + Regex underline_regex = /_(.*?)_/; + + Regex italic_bold_underline_regex = /\*\*\*_([^*]+)_\*\*\*/; + Regex bold_underline_regex = /\*\*_([^*]+)_\*\*/; + Regex italic_underline_regex = /\*_(.*?)_\*/; MatchInfo info; @@ -1127,7 +1132,6 @@ We hope you’ll enjoy using Planify!"""); if (url_regex.match (text, 0, out info)) { do { var url = info.fetch_named ("url"); - if (!url_exists (url, markdown_urls)) { urls.append (url); } @@ -1155,12 +1159,39 @@ We hope you’ll enjoy using Planify!"""); } while (info.next ()); } + Gee.ArrayList italic_bold_underline = new Gee.ArrayList (); + 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 bold_underline = new Gee.ArrayList (); + 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 italic_underline = new Gee.ArrayList (); + 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 underlines = new Gee.ArrayList (); + 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) { string markdown_text = m.text; string markdown_link = m.extra; - string urlAsLink = @"$markdown_text"; converted = converted.replace (m.match, urlAsLink); } @@ -1173,6 +1204,22 @@ We hope you’ll enjoy using Planify!"""); converted = converted.replace (email, @"$email"); }); + foreach (RegexMarkdown m in italic_bold_underline) { + converted = converted.replace (m.match, "" + m.text + ""); + } + + foreach (RegexMarkdown m in bold_underline) { + converted = converted.replace (m.match, "" + m.text + ""); + } + + foreach (RegexMarkdown m in italic_underline) { + converted = converted.replace (m.match, "" + m.text + ""); + } + + foreach (RegexMarkdown m in underlines) { + converted = converted.replace (m.match, "" + m.text + ""); + } + foreach (RegexMarkdown m in italic_bold) { converted = converted.replace (m.match, "" + m.text + ""); }