From 37aa148292bcc3bc072f6b94de55f0ef96760b20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johanna=20R=C3=BChrig?= Date: Wed, 22 Sep 2021 18:25:12 +0200 Subject: [PATCH 1/7] Added rndr_colored function --- html/html.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/html/html.c b/html/html.c index 44b69a2..15bdabd 100755 --- a/html/html.c +++ b/html/html.c @@ -205,6 +205,21 @@ rndr_strikethrough(struct buf *ob, const struct buf *text, void *opaque) return 1; } +static int +rndr_colored(struct buf *ob, const struct buf *text, const struct buf *color, void *opaque) +{ + if (!text || !text->size || !color || !color->size) + return 0; + + BUFPUTSL(ob, "data, color->size); + BUFPUTSL(ob, "\">"); + bufput(ob, text->data, text->size); + BUFPUTSL(ob, ""); + + return 1; +} + static int rndr_double_emphasis(struct buf *ob, const struct buf *text, void *opaque) { From 12f085a3af02f78af66f83d23b98c40bcd0bd9a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johanna=20R=C3=BChrig?= Date: Wed, 22 Sep 2021 18:27:39 +0200 Subject: [PATCH 2/7] Update html.c --- html/html.c | 1 + 1 file changed, 1 insertion(+) diff --git a/html/html.c b/html/html.c index 15bdabd..fab3761 100755 --- a/html/html.c +++ b/html/html.c @@ -792,6 +792,7 @@ sdhtml_renderer(struct sd_callbacks *callbacks, struct html_renderopt *options, rndr_autolink, rndr_codespan, + rndr_colored, rndr_spoilerspan, rndr_double_emphasis, rndr_emphasis, From d0401ed1972bd4bcd9bfbd903e65674d51663ef5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johanna=20R=C3=BChrig?= Date: Wed, 22 Sep 2021 19:05:19 +0200 Subject: [PATCH 3/7] Added parse and prefix functions --- src/markdown.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/src/markdown.c b/src/markdown.c index fa85a71..e069fbd 100644 --- a/src/markdown.c +++ b/src/markdown.c @@ -603,6 +603,48 @@ parse_spoilerspan(struct buf *ob, struct sd_markdown *rndr, uint8_t *data, size_ size_t len; size_t i = 0; struct buf *work = 0; + struct buf *color = 0; + int r; + + render_method = rndr->cb.coloredtext; + + if (!render_method) return 0; + + while (i < size) { + colorlen = find_emph_char(data + i, size - i, ':'); + if (!colorlen) return 0; + i += colorlen + if (i < size && data[i] == ':' && data[i - 1] == ':') { + color = rndr_newbuf(rndr, BUFFER_SPAN); + parse_inline(color, rndr, data, i - 1); + } + + len = find_emph_char(data + i, size - i, '<'); + if (!len) return 0; + i += len; + + if (i < size && data[i] == '<' && data[i - 1] == ':') { + work = rndr_newbuf(rndr, BUFFER_SPAN); + parse_inline(work, rndr, data, i - 1); + r = render_method(ob, work, color, rndr->opaque); + rndr_popbuf(rndr, BUFFER_SPAN); + + if (!r) return 0; + + return i + 1; + } + i++; + } + return 0; +} + +static size_t +parse_coloredtext(struct buf *ob, struct sd_markdown *rndr, uint8_t *data, size_t size) +{ + int (*render_method)(struct buf *ob, const struct buf *text, const struct buf *color, void *opaque); + size_t len; + size_t i = 0; + struct buf *work = 0; int r; render_method = rndr->cb.spoilerspan; @@ -643,6 +685,13 @@ char_emphasis(struct buf *ob, struct sd_markdown *rndr, uint8_t *data, size_t ma return ret + 2; } + if (size > 4 && c == '>' && data[1] == 'c' && data[2] == ':') { + if(_isspace(data[2]) || (ret = parse_coloredtext(ob, rndr, data + 2, size - 2)) == 0) + return 0; + + return ret + 3; + } + if (size > 2 && data[1] != c) { /* whitespace cannot follow an opening emphasis; @@ -1480,6 +1529,25 @@ prefix_blockspoiler(uint8_t *data, size_t size) return 0; } +static size_t +prefix_coloredtext(uint8_t *data, size_t size) +{ + size_t i = 0; + if (i < size && data[i] == ' ') i++; + if (i < size && data[i] == ' ') i++; + if (i < size && data[i] == ' ') i++; + + if (i + 2 < size && data[i] == '>' && data[i + 1] == 'c' && data[i + 2] == ':') { + size_t coloredspan = find_emph_char(data + i + 2, size - i - 1, '<'); + if (i + coloredspan < size && coloredspan > 0 && data[i + coloredspan] == ':') + return 0; + + return i + 3; + } + + return 0; +} + /* prefix_code • returns prefix length for block code*/ static size_t prefix_code(uint8_t *data, size_t size) From 66ec1a8e071a8a2bb3d28a5e8ef0149eef60470d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johanna=20R=C3=BChrig?= Date: Wed, 22 Sep 2021 19:09:22 +0200 Subject: [PATCH 4/7] Revert mixup --- src/markdown.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/markdown.c b/src/markdown.c index e069fbd..961dc6c 100644 --- a/src/markdown.c +++ b/src/markdown.c @@ -603,30 +603,21 @@ parse_spoilerspan(struct buf *ob, struct sd_markdown *rndr, uint8_t *data, size_ size_t len; size_t i = 0; struct buf *work = 0; - struct buf *color = 0; int r; - render_method = rndr->cb.coloredtext; + render_method = rndr->cb.spoilerspan; if (!render_method) return 0; while (i < size) { - colorlen = find_emph_char(data + i, size - i, ':'); - if (!colorlen) return 0; - i += colorlen - if (i < size && data[i] == ':' && data[i - 1] == ':') { - color = rndr_newbuf(rndr, BUFFER_SPAN); - parse_inline(color, rndr, data, i - 1); - } - len = find_emph_char(data + i, size - i, '<'); if (!len) return 0; i += len; - if (i < size && data[i] == '<' && data[i - 1] == ':') { + if (i < size && data[i] == '<' && data[i - 1] == '!') { work = rndr_newbuf(rndr, BUFFER_SPAN); parse_inline(work, rndr, data, i - 1); - r = render_method(ob, work, color, rndr->opaque); + r = render_method(ob, work, rndr->opaque); rndr_popbuf(rndr, BUFFER_SPAN); if (!r) return 0; @@ -645,21 +636,30 @@ parse_coloredtext(struct buf *ob, struct sd_markdown *rndr, uint8_t *data, size_ size_t len; size_t i = 0; struct buf *work = 0; + struct buf *color = 0; int r; - render_method = rndr->cb.spoilerspan; + render_method = rndr->cb.coloredtext; if (!render_method) return 0; while (i < size) { + colorlen = find_emph_char(data + i, size - i, ':'); + if (!colorlen) return 0; + i += colorlen + if (i < size && data[i] == ':' && data[i - 1] == ':') { + color = rndr_newbuf(rndr, BUFFER_SPAN); + parse_inline(color, rndr, data, i - 1); + } + len = find_emph_char(data + i, size - i, '<'); if (!len) return 0; i += len; - if (i < size && data[i] == '<' && data[i - 1] == '!') { + if (i < size && data[i] == '<' && data[i - 1] == ':') { work = rndr_newbuf(rndr, BUFFER_SPAN); parse_inline(work, rndr, data, i - 1); - r = render_method(ob, work, rndr->opaque); + r = render_method(ob, work, color, rndr->opaque); rndr_popbuf(rndr, BUFFER_SPAN); if (!r) return 0; From bc10fcbf414740a740a0464f9e72ecbfbdb766be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johanna=20R=C3=BChrig?= Date: Wed, 22 Sep 2021 19:12:35 +0200 Subject: [PATCH 5/7] Added colortext --- src/markdown.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/markdown.h b/src/markdown.h index c70a2bb..8cc7abd 100644 --- a/src/markdown.h +++ b/src/markdown.h @@ -82,6 +82,7 @@ struct sd_callbacks { /* span level callbacks - NULL or return 0 prints the span verbatim */ int (*autolink)(struct buf *ob, const struct buf *link, enum mkd_autolink type, void *opaque); int (*codespan)(struct buf *ob, const struct buf *text, void *opaque); + int (*coloredtext)(struct buf *ob, const struct buf *text, const struct buf *color, void *opaque); int (*spoilerspan)(struct buf *ob, const struct buf *text, void *opaque); int (*double_emphasis)(struct buf *ob, const struct buf *text, void *opaque); int (*emphasis)(struct buf *ob, const struct buf *text, void *opaque); From 5a659208f684896796a823c73905c4735f290e4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johanna=20R=C3=BChrig?= Date: Wed, 22 Sep 2021 19:14:44 +0200 Subject: [PATCH 6/7] Update html.c --- html/html.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/html/html.c b/html/html.c index fab3761..3c67d2e 100755 --- a/html/html.c +++ b/html/html.c @@ -206,7 +206,7 @@ rndr_strikethrough(struct buf *ob, const struct buf *text, void *opaque) } static int -rndr_colored(struct buf *ob, const struct buf *text, const struct buf *color, void *opaque) +rndr_coloredtext(struct buf *ob, const struct buf *text, const struct buf *color, void *opaque) { if (!text || !text->size || !color || !color->size) return 0; @@ -749,6 +749,7 @@ sdhtml_toc_renderer(struct sd_callbacks *callbacks, struct html_renderopt *optio NULL, rndr_codespan, + rndr_coloredtext, rndr_spoilerspan, rndr_double_emphasis, rndr_emphasis, @@ -792,7 +793,7 @@ sdhtml_renderer(struct sd_callbacks *callbacks, struct html_renderopt *options, rndr_autolink, rndr_codespan, - rndr_colored, + rndr_coloredtext, rndr_spoilerspan, rndr_double_emphasis, rndr_emphasis, From eb3228275187184a493a1b0ae7822745fe364140 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johanna=20R=C3=BChrig?= Date: Wed, 22 Sep 2021 19:25:04 +0200 Subject: [PATCH 7/7] Update html.c --- html/html.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html/html.c b/html/html.c index 3c67d2e..31cd690 100755 --- a/html/html.c +++ b/html/html.c @@ -208,7 +208,7 @@ rndr_strikethrough(struct buf *ob, const struct buf *text, void *opaque) static int rndr_coloredtext(struct buf *ob, const struct buf *text, const struct buf *color, void *opaque) { - if (!text || !text->size || !color || !color->size) + if (!text || !text->size || !color || !color->size || !color+text->size) return 0; BUFPUTSL(ob, "