aboutsummaryrefslogtreecommitdiff
path: root/main/src/ui/util
diff options
context:
space:
mode:
authorRoberto Santalla <roobre@roobre.es>2019-10-08 16:38:41 +0200
committerfiaxh <git@lightrise.org>2020-02-21 19:05:46 +0100
commit6f77283c2cf3906816fcb315e53fdb237acd9a3c (patch)
tree144da54ea37d55d434816d906e55d630aca5624a /main/src/ui/util
parented71f61422ec0cc03427833771fe2a6a7b4b3fa1 (diff)
downloaddino-6f77283c2cf3906816fcb315e53fdb237acd9a3c.tar.gz
dino-6f77283c2cf3906816fcb315e53fdb237acd9a3c.zip
Format fenced code blocks
Diffstat (limited to 'main/src/ui/util')
-rw-r--r--main/src/ui/util/helper.vala18
1 files changed, 18 insertions, 0 deletions
diff --git a/main/src/ui/util/helper.vala b/main/src/ui/util/helper.vala
index 0f0e6e7b..f936ed4f 100644
--- a/main/src/ui/util/helper.vala
+++ b/main/src/ui/util/helper.vala
@@ -343,6 +343,24 @@ public static string parse_add_markup(string s_, string? highlight_word, bool pa
}
if (parse_text_markup) {
+ // Try to match preformatted code blocks first
+ try {
+ Regex regex = new Regex("(?:^|\n)(```(?:(?!\n\n|```)(?:.|\n))+(?:$|```|\n\n))");
+ MatchInfo match_info;
+ regex.match(s.down().strip(), 0, out match_info);
+ if (match_info.matches()) {
+ int start, end;
+ match_info.fetch_pos(1, out start, out end);
+ return parse_add_markup(s[0:start], highlight_word, parse_links, parse_text_markup, already_escaped) +
+ "<tt>" +
+ s[start:end] +
+ "</tt>" +
+ parse_add_markup(s[end:s.length], highlight_word, parse_links, parse_text_markup, already_escaped);
+ }
+ } catch (RegexError e) {
+ assert_not_reached();
+ }
+
string[] markup_string = new string[]{"`", "_", "*"};
string[] convenience_tag = new string[]{"tt", "i", "b"};