mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-15 01:55:03 +00:00
Added markdown-like links.
This commit is contained in:
parent
37b6c7926e
commit
8e0ccc6d76
1 changed files with 16 additions and 1 deletions
17
format.c
17
format.c
|
@ -87,7 +87,12 @@ static xs_str *format_line(const char *line, xs_list **attach)
|
||||||
|
|
||||||
/* split by markup */
|
/* split by markup */
|
||||||
xs *sm = xs_regex_split(line,
|
xs *sm = xs_regex_split(line,
|
||||||
"(`[^`]+`|\\*\\*?[^\\*]+\\*?\\*|https?:/" "/[^[:space:]]+)");
|
"("
|
||||||
|
"`[^`]+`" "|"
|
||||||
|
"\\*\\*?[^\\*]+\\*?\\*" "|"
|
||||||
|
"\\[[^]]+\\]\\([^\\)]+\\)" "|"
|
||||||
|
"https?:/" "/[^[:space:]]+"
|
||||||
|
")");
|
||||||
int n = 0;
|
int n = 0;
|
||||||
|
|
||||||
p = sm;
|
p = sm;
|
||||||
|
@ -135,6 +140,16 @@ static xs_str *format_line(const char *line, xs_list **attach)
|
||||||
s = xs_str_cat(s, s1);
|
s = xs_str_cat(s, s1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
if (*v == '[') {
|
||||||
|
/* markdown-like links [label](url) */
|
||||||
|
xs *w = xs_strip_chars_i(xs_dup(v), "[)");
|
||||||
|
xs *l = xs_split(w, "](");
|
||||||
|
xs *link = xs_fmt("<a href=\"%s\">%s</a>",
|
||||||
|
xs_list_get(l, 1), xs_list_get(l, 0));
|
||||||
|
|
||||||
|
s = xs_str_cat(s, link);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
s = xs_str_cat(s, v);
|
s = xs_str_cat(s, v);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue