diff --git a/html.c b/html.c
index 7651a5b..db7d10e 100644
--- a/html.c
+++ b/html.c
@@ -16,69 +16,53 @@ d_char *not_really_markdown(char *content, d_char **f_content)
int in_blq = 0;
xs *list;
char *p, *v;
- xs *wrk = xs_dup(content);
-
- /* global changes */
- {
- /* backticks */
- xs *ml = xs_regex_match(wrk, "`[^`]+`");
- p = ml;
-
- while (xs_list_iter(&p, &v)) {
- xs *s1 = xs_crop(xs_dup(v), 1, -1);
- xs *s2 = xs_fmt("%s
", s1);
-
- wrk = xs_replace_i(wrk, v, s2);
- }
- }
+ xs *wrk = xs_str_new(NULL);
{
- /* double asterisks */
- xs *ml = xs_regex_match(wrk, "\\*\\*[^\\*]+\\*\\*");
- p = ml;
+ /* split by special markup */
+ xs *sm = xs_regex_split(content,
+ "(`[^`]+`|\\*\\*?[^\\*]+\\*?\\*|https?:/" "/[^ ]*)");
+ int n = 0;
+ p = sm;
while (xs_list_iter(&p, &v)) {
- xs *s1 = xs_crop(xs_dup(v), 2, -2);
- xs *s2 = xs_fmt("%s", s1);
-
- wrk = xs_replace_i(wrk, v, s2);
- }
- }
-
- {
- /* single asterisks */
- xs *ml = xs_regex_match(wrk, "\\*[^\\*]+\\*");
- p = ml;
-
- while (xs_list_iter(&p, &v)) {
- xs *s1 = xs_crop(xs_dup(v), 1, -1);
- xs *s2 = xs_fmt("%s", s1);
-
- wrk = xs_replace_i(wrk, v, s2);
- }
- }
-
-#if 0
- {
- /* urls */
- xs *done = xs_list_new();
- xs *ml = xs_regex_matchall(wrk, "https?:/" "/[^ ]+");
- p = ml;
-
- while (xs_list_iter(&p, &v)) {
- if (xs_list_in(done, v) == -1) {
- xs *s2 = xs_fmt("%s", v, v);
- wrk = xs_replace_i(wrk, v, s2);
-
- /* keep track of already done replaces */
- done = xs_list_append(done, v);
+ if ((n & 0x1)) {
+ /* markup */
+ if (xs_startswith(v, "`")) {
+ xs *s1 = xs_crop(xs_dup(v), 1, -1);
+ xs *s2 = xs_fmt("%s
", s1);
+ wrk = xs_str_cat(wrk, s2);
+ }
+ else
+ if (xs_startswith(v, "**")) {
+ xs *s1 = xs_crop(xs_dup(v), 2, -2);
+ xs *s2 = xs_fmt("%s", s1);
+ wrk = xs_str_cat(wrk, s2);
+ }
+ else
+ if (xs_startswith(v, "*")) {
+ xs *s1 = xs_crop(xs_dup(v), 1, -1);
+ xs *s2 = xs_fmt("%s", s1);
+ wrk = xs_str_cat(wrk, s2);
+ }
+ else
+ if (xs_startswith(v, "http")) {
+ xs *s1 = xs_fmt("%s", v, v);
+ wrk = xs_str_cat(wrk, s1);
+ }
+ else
+ /* what the hell is this */
+ wrk = xs_str_cat(wrk, v);
}
+ else
+ /* surrounded text, copy directly */
+ wrk = xs_str_cat(wrk, v);
+
+ n++;
}
}
-#endif
-
- /* now work on lines */
+ /* now work by lines */
p = list = xs_split(wrk, "\n");
s = xs_str_new(NULL);