summaryrefslogtreecommitdiff
path: root/src/html
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2014-11-06 11:12:24 -0800
committerJohn MacFarlane <fiddlosopher@gmail.com>2014-11-06 11:12:24 -0800
commitca8baa92556576731b59f793128d445dd7c76aa4 (patch)
tree0656dcaadda6894b664b447d4bf894e7708a236f /src/html
parent4c51f9648f7a868f05c70b4fb8b4242608716a0b (diff)
HTML renderer: render alt text as plain, unformatted string.
Diffstat (limited to 'src/html')
-rw-r--r--src/html/html.c55
1 files changed, 49 insertions, 6 deletions
diff --git a/src/html/html.c b/src/html/html.c
index 6261b9c..9b3a995 100644
--- a/src/html/html.c
+++ b/src/html/html.c
@@ -98,9 +98,56 @@ static inline void cr(strbuf *html)
}
// Convert an inline list to HTML. Returns 0 on success, and sets result.
+static void inlines_to_plain_html(strbuf *html, node_inl* ils)
+{
+ node_inl* children;
+ render_stack* rstack = NULL;
+
+ while(ils != NULL) {
+ children = NULL;
+ switch(ils->tag) {
+ case INL_STRING:
+ case INL_CODE:
+ case INL_RAW_HTML:
+ escape_html(html, ils->content.literal.data, ils->content.literal.len);
+ break;
+
+ case INL_LINEBREAK:
+ case INL_SOFTBREAK:
+ strbuf_putc(html, '\n');
+ break;
+
+ case INL_LINK:
+ case INL_IMAGE:
+ children = ils->content.inlines;
+ rstack = push_inline(rstack, ils->next, "");
+ break;
+
+ case INL_STRONG:
+ case INL_EMPH:
+ children = ils->content.inlines;
+ rstack = push_inline(rstack, ils->next, "");
+ break;
+ }
+ if (children) {
+ ils = children;
+ } else {
+ ils = ils->next;
+ }
+ while (ils == NULL && rstack != NULL) {
+ strbuf_puts(html, rstack->literal);
+ ils = rstack->next_sibling.inl;
+ rstack = pop_render_stack(rstack);
+ }
+ }
+
+ free_render_stack(rstack);
+}
+
+
+// Convert an inline list to HTML. Returns 0 on success, and sets result.
static void inlines_to_html(strbuf *html, node_inl* ils)
{
- strbuf scrap = GH_BUF_INIT;
node_inl* children;
render_stack* rstack = NULL;
@@ -151,11 +198,8 @@ static void inlines_to_html(strbuf *html, node_inl* ils)
if (ils->content.linkable.url)
escape_href(html, ils->content.linkable.url, -1);
- inlines_to_html(&scrap, ils->content.inlines);
strbuf_puts(html, "\" alt=\"");
- if (scrap.size)
- escape_html(html, scrap.ptr, scrap.size);
- strbuf_clear(&scrap);
+ inlines_to_plain_html(html, ils->content.inlines);
if (ils->content.linkable.title) {
strbuf_puts(html, "\" title=\"");
@@ -189,7 +233,6 @@ static void inlines_to_html(strbuf *html, node_inl* ils)
}
}
- strbuf_free(&scrap);
free_render_stack(rstack);
}