summaryrefslogtreecommitdiff
path: root/html.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--html.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/html.c b/html.c
index 2646e7d..de9060c 100644
--- a/html.c
+++ b/html.c
@@ -7,3 +7,68 @@
7 7
8#include "snac.h" 8#include "snac.h"
9 9
10d_char *not_really_markdown(char *content, d_char **f_content)
11/* formats a content using some Markdown rules */
12{
13 d_char *s = NULL;
14 int in_pre = 0;
15 int in_blq = 0;
16 xs *list;
17 char *p, *v;
18
19 s = xs_str_new(NULL);
20
21 p = list = xs_split(content, "\n");
22
23 while (xs_list_iter(&p, &v)) {
24 xs *ss = xs_strip(xs_dup(v));
25
26 if (xs_startswith(ss, "```")) {
27 if (!in_pre)
28 s = xs_str_cat(s, "<pre>");
29 else
30 s = xs_str_cat(s, "</pre>");
31
32 in_pre = !in_pre;
33 continue;
34 }
35
36 if (xs_startswith(ss, ">")) {
37 /* delete the > and subsequent spaces */
38 ss = xs_strip(xs_crop(ss, 1, 0));
39
40 if (!in_blq) {
41 s = xs_str_cat(s, "<blockquote>");
42 in_blq = 1;
43 }
44
45 s = xs_str_cat(s, ss);
46 s = xs_str_cat(s, "<br>");
47
48 continue;
49 }
50
51 if (in_blq) {
52 s = xs_str_cat(s, "</blockquote>");
53 in_blq = 0;
54 }
55
56 s = xs_str_cat(s, ss);
57 s = xs_str_cat(s, "<br>");
58 }
59
60 if (in_blq)
61 s = xs_str_cat(s, "</blockquote>");
62 if (in_pre)
63 s = xs_str_cat(s, "</pre>");
64
65 /* some beauty fixes */
66 if (xs_str_in(s, "</blockquote><br>") != -1) {
67 xs *os = s;
68 s = xs_replace(os, "</blockquote><br>", "</blockquote>");
69 }
70
71 *f_content = s;
72
73 return *f_content;
74}