summaryrefslogtreecommitdiff
path: root/html.c
diff options
context:
space:
mode:
authorGravatar default2022-09-27 10:51:50 +0200
committerGravatar default2022-09-27 10:51:57 +0200
commit4f3b70d9979b22cfc1a789b14602a12ee5c896c7 (patch)
tree289541acdb3fa7b38783a2e3ce9f10047ea05e05 /html.c
parentFixed bug in xs_replace_i(). (diff)
downloadpenes-snac2-4f3b70d9979b22cfc1a789b14602a12ee5c896c7.tar.gz
penes-snac2-4f3b70d9979b22cfc1a789b14602a12ee5c896c7.tar.xz
penes-snac2-4f3b70d9979b22cfc1a789b14602a12ee5c896c7.zip
More work in not_really_markdown().
Diffstat (limited to 'html.c')
-rw-r--r--html.c60
1 files changed, 58 insertions, 2 deletions
diff --git a/html.c b/html.c
index 532c033..052656b 100644
--- a/html.c
+++ b/html.c
@@ -4,6 +4,7 @@
4#include "xs.h" 4#include "xs.h"
5#include "xs_io.h" 5#include "xs_io.h"
6#include "xs_json.h" 6#include "xs_json.h"
7#include "xs_regex.h"
7 8
8#include "snac.h" 9#include "snac.h"
9 10
@@ -15,10 +16,65 @@ d_char *not_really_markdown(char *content, d_char **f_content)
15 int in_blq = 0; 16 int in_blq = 0;
16 xs *list; 17 xs *list;
17 char *p, *v; 18 char *p, *v;
19 xs *wrk = xs_dup(content);
18 20
19 s = xs_str_new(NULL); 21 /* global changes */
22 {
23 /* backticks */
24 xs *ml = xs_regex_matchall(wrk, "`[^`]+`");
25 p = ml;
26
27 while (xs_list_iter(&p, &v)) {
28 xs *s1 = xs_crop(xs_dup(v), 1, -1);
29 xs *s2 = xs_fmt("<code>%s</code>", s1);
30
31 wrk = xs_replace_i(wrk, v, s2);
32 }
33 }
34
35 {
36 /* double asterisks */
37 xs *ml = xs_regex_matchall(wrk, "\\*\\*[^\\*]+\\*\\*");
38 p = ml;
39
40 while (xs_list_iter(&p, &v)) {
41 xs *s1 = xs_crop(xs_dup(v), 2, -2);
42 xs *s2 = xs_fmt("<b>%s</b>", s1);
43
44 wrk = xs_replace_i(wrk, v, s2);
45 }
46 }
47
48 {
49 /* single asterisks */
50 xs *ml = xs_regex_matchall(wrk, "\\*[^\\*]+\\*");
51 p = ml;
52
53 while (xs_list_iter(&p, &v)) {
54 xs *s1 = xs_crop(xs_dup(v), 1, -1);
55 xs *s2 = xs_fmt("<i>%s</i>", s1);
20 56
21 p = list = xs_split(content, "\n"); 57 wrk = xs_replace_i(wrk, v, s2);
58 }
59 }
60
61 {
62 /* urls */
63 xs *ml = xs_regex_matchall(wrk, "https?:/" "/[^ ]+");
64 p = ml;
65
66 while (xs_list_iter(&p, &v)) {
67 xs *s2 = xs_fmt("<a href=\"%s\">%s</a>", v, v);
68
69 wrk = xs_replace_i(wrk, v, s2);
70 }
71 }
72
73 /* now work on lines */
74
75 p = list = xs_split(wrk, "\n");
76
77 s = xs_str_new(NULL);
22 78
23 while (xs_list_iter(&p, &v)) { 79 while (xs_list_iter(&p, &v)) {
24 xs *ss = xs_strip(xs_dup(v)); 80 xs *ss = xs_strip(xs_dup(v));