From 01743cee551f84c81db00714a59d6897418ba06a Mon Sep 17 00:00:00 2001 From: default Date: Sun, 6 Nov 2022 06:55:06 +0100 Subject: [PATCH] More tweaks to not_really_markdown() to avoid ambiguities. --- format.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/format.c b/format.c index ae2b731..93080fe 100644 --- a/format.c +++ b/format.c @@ -44,9 +44,12 @@ d_char *not_really_markdown(char *content, d_char **f_content) char *p, *v; xs *wrk = xs_str_new(NULL); + /* some preparation to avoid writing very kludgy code */ + xs *p_content = xs_replace(content, "```", "@pre@"); + { /* split by special markup */ - xs *sm = xs_regex_split(content, + xs *sm = xs_regex_split(p_content, "(`[^`]+`|\\*\\*?[^\\*]+\\*?\\*|https?:/" "/[^[:space:]]+)"); int n = 0; @@ -54,7 +57,7 @@ d_char *not_really_markdown(char *content, d_char **f_content) while (xs_list_iter(&p, &v)) { if ((n & 0x1)) { /* markup */ - if (xs_startswith(v, "`") && v[1] != '\n') { + if (xs_startswith(v, "`")) { xs *s1 = xs_crop(xs_dup(v), 1, -1); xs *s2 = xs_fmt("%s", s1); wrk = xs_str_cat(wrk, s2); @@ -95,7 +98,7 @@ d_char *not_really_markdown(char *content, d_char **f_content) while (xs_list_iter(&p, &v)) { xs *ss = xs_strip(xs_dup(v)); - if (xs_startswith(ss, "```")) { + if (xs_startswith(ss, "@pre@")) { if (!in_pre) s = xs_str_cat(s, "
");
             else