mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-09 19:50:26 +03:00
More tweaks to not_really_markdown() to avoid ambiguities.
This commit is contained in:
parent
7992563532
commit
01743cee55
9
format.c
9
format.c
@ -44,9 +44,12 @@ d_char *not_really_markdown(char *content, d_char **f_content)
|
|||||||
char *p, *v;
|
char *p, *v;
|
||||||
xs *wrk = xs_str_new(NULL);
|
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 */
|
/* split by special markup */
|
||||||
xs *sm = xs_regex_split(content,
|
xs *sm = xs_regex_split(p_content,
|
||||||
"(`[^`]+`|\\*\\*?[^\\*]+\\*?\\*|https?:/" "/[^[:space:]]+)");
|
"(`[^`]+`|\\*\\*?[^\\*]+\\*?\\*|https?:/" "/[^[:space:]]+)");
|
||||||
int n = 0;
|
int n = 0;
|
||||||
|
|
||||||
@ -54,7 +57,7 @@ d_char *not_really_markdown(char *content, d_char **f_content)
|
|||||||
while (xs_list_iter(&p, &v)) {
|
while (xs_list_iter(&p, &v)) {
|
||||||
if ((n & 0x1)) {
|
if ((n & 0x1)) {
|
||||||
/* markup */
|
/* markup */
|
||||||
if (xs_startswith(v, "`") && v[1] != '\n') {
|
if (xs_startswith(v, "`")) {
|
||||||
xs *s1 = xs_crop(xs_dup(v), 1, -1);
|
xs *s1 = xs_crop(xs_dup(v), 1, -1);
|
||||||
xs *s2 = xs_fmt("<code>%s</code>", s1);
|
xs *s2 = xs_fmt("<code>%s</code>", s1);
|
||||||
wrk = xs_str_cat(wrk, s2);
|
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)) {
|
while (xs_list_iter(&p, &v)) {
|
||||||
xs *ss = xs_strip(xs_dup(v));
|
xs *ss = xs_strip(xs_dup(v));
|
||||||
|
|
||||||
if (xs_startswith(ss, "```")) {
|
if (xs_startswith(ss, "@pre@")) {
|
||||||
if (!in_pre)
|
if (!in_pre)
|
||||||
s = xs_str_cat(s, "<pre>");
|
s = xs_str_cat(s, "<pre>");
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user