diff options
Diffstat (limited to 'html.c')
| -rw-r--r-- | html.c | 110 |
1 files changed, 0 insertions, 110 deletions
| @@ -12,116 +12,6 @@ | |||
| 12 | 12 | ||
| 13 | #include "snac.h" | 13 | #include "snac.h" |
| 14 | 14 | ||
| 15 | d_char *not_really_markdown(char *content, d_char **f_content) | ||
| 16 | /* formats a content using some Markdown rules */ | ||
| 17 | { | ||
| 18 | d_char *s = NULL; | ||
| 19 | int in_pre = 0; | ||
| 20 | int in_blq = 0; | ||
| 21 | xs *list; | ||
| 22 | char *p, *v; | ||
| 23 | xs *wrk = xs_str_new(NULL); | ||
| 24 | |||
| 25 | { | ||
| 26 | /* split by special markup */ | ||
| 27 | xs *sm = xs_regex_split(content, | ||
| 28 | "(`[^`]+`|\\*\\*?[^\\*]+\\*?\\*|https?:/" "/[^[:space:]]+)"); | ||
| 29 | int n = 0; | ||
| 30 | |||
| 31 | p = sm; | ||
| 32 | while (xs_list_iter(&p, &v)) { | ||
| 33 | if ((n & 0x1)) { | ||
| 34 | /* markup */ | ||
| 35 | if (xs_startswith(v, "`")) { | ||
| 36 | xs *s1 = xs_crop(xs_dup(v), 1, -1); | ||
| 37 | xs *s2 = xs_fmt("<code>%s</code>", s1); | ||
| 38 | wrk = xs_str_cat(wrk, s2); | ||
| 39 | } | ||
| 40 | else | ||
| 41 | if (xs_startswith(v, "**")) { | ||
| 42 | xs *s1 = xs_crop(xs_dup(v), 2, -2); | ||
| 43 | xs *s2 = xs_fmt("<b>%s</b>", s1); | ||
| 44 | wrk = xs_str_cat(wrk, s2); | ||
| 45 | } | ||
| 46 | else | ||
| 47 | if (xs_startswith(v, "*")) { | ||
| 48 | xs *s1 = xs_crop(xs_dup(v), 1, -1); | ||
| 49 | xs *s2 = xs_fmt("<i>%s</i>", s1); | ||
| 50 | wrk = xs_str_cat(wrk, s2); | ||
| 51 | } | ||
| 52 | else | ||
| 53 | if (xs_startswith(v, "http")) { | ||
| 54 | xs *s1 = xs_fmt("<a href=\"%s\">%s</a>", v, v); | ||
| 55 | wrk = xs_str_cat(wrk, s1); | ||
| 56 | } | ||
| 57 | else | ||
| 58 | /* what the hell is this */ | ||
| 59 | wrk = xs_str_cat(wrk, v); | ||
| 60 | } | ||
| 61 | else | ||
| 62 | /* surrounded text, copy directly */ | ||
| 63 | wrk = xs_str_cat(wrk, v); | ||
| 64 | |||
| 65 | n++; | ||
| 66 | } | ||
| 67 | } | ||
| 68 | |||
| 69 | /* now work by lines */ | ||
| 70 | p = list = xs_split(wrk, "\n"); | ||
| 71 | |||
| 72 | s = xs_str_new(NULL); | ||
| 73 | |||
| 74 | while (xs_list_iter(&p, &v)) { | ||
| 75 | xs *ss = xs_strip(xs_dup(v)); | ||
| 76 | |||
| 77 | if (xs_startswith(ss, "```")) { | ||
| 78 | if (!in_pre) | ||
| 79 | s = xs_str_cat(s, "<pre>"); | ||
| 80 | else | ||
| 81 | s = xs_str_cat(s, "</pre>"); | ||
| 82 | |||
| 83 | in_pre = !in_pre; | ||
| 84 | continue; | ||
| 85 | } | ||
| 86 | |||
| 87 | if (xs_startswith(ss, ">")) { | ||
| 88 | /* delete the > and subsequent spaces */ | ||
| 89 | ss = xs_strip(xs_crop(ss, 1, 0)); | ||
| 90 | |||
| 91 | if (!in_blq) { | ||
| 92 | s = xs_str_cat(s, "<blockquote>"); | ||
| 93 | in_blq = 1; | ||
| 94 | } | ||
| 95 | |||
| 96 | s = xs_str_cat(s, ss); | ||
| 97 | s = xs_str_cat(s, "<br>"); | ||
| 98 | |||
| 99 | continue; | ||
| 100 | } | ||
| 101 | |||
| 102 | if (in_blq) { | ||
| 103 | s = xs_str_cat(s, "</blockquote>"); | ||
| 104 | in_blq = 0; | ||
| 105 | } | ||
| 106 | |||
| 107 | s = xs_str_cat(s, ss); | ||
| 108 | s = xs_str_cat(s, "<br>"); | ||
| 109 | } | ||
| 110 | |||
| 111 | if (in_blq) | ||
| 112 | s = xs_str_cat(s, "</blockquote>"); | ||
| 113 | if (in_pre) | ||
| 114 | s = xs_str_cat(s, "</pre>"); | ||
| 115 | |||
| 116 | /* some beauty fixes */ | ||
| 117 | s = xs_replace_i(s, "</blockquote><br>", "</blockquote>"); | ||
| 118 | |||
| 119 | *f_content = s; | ||
| 120 | |||
| 121 | return *f_content; | ||
| 122 | } | ||
| 123 | |||
| 124 | |||
| 125 | int login(snac *snac, char *headers) | 15 | int login(snac *snac, char *headers) |
| 126 | /* tries a login */ | 16 | /* tries a login */ |
| 127 | { | 17 | { |