From c28af79329264a7cf331a1b1c414919e4ed9e9f9 Mon Sep 17 00:00:00 2001
From: Vicent Marti ");
+ inlines_to_html(html, b->inline_content);
+ gh_buf_puts(html, " ");
inlines_to_html(html, b->inline_content);
- gh_buf_puts(html, "");
+ blocks_to_html(html, b->children, false);
+ gh_buf_puts(html, "
");
+ cr(html);
+ break;
+
+ case list_item:
+ cr(html);
+ gh_buf_puts(html, "\n" : "
" : "");
+ cr(html);
+ break;
+
+ case atx_header:
+ case setext_header:
+ cr(html);
+ gh_buf_printf(html, "\n");
+ }
+
+ blocks_to_html(html, b->children, data->tight);
+ gh_buf_puts(html, data->list_type == bullet ? "
");
+ cr(html);
+ break;
+
+ case html_block:
+ gh_buf_put(html, b->string_content.ptr, b->string_content.size);
+ break;
+
+ case hrule:
+ gh_buf_puts(html, "");
+ escape_html(html, b->string_content.ptr, b->string_content.size);
+ gh_buf_puts(html, "
");
+ cr(html);
+ break;
+
+ case reference_def:
+ break;
+
+ default:
+ assert(false);
+ }
+
+ b = b->next;
+ }
+}
+
+// Convert an inline list to HTML. Returns 0 on success, and sets result.
+void inlines_to_html(gh_buf *html, inl* ils)
+{
+ gh_buf scrap = GH_BUF_INIT;
+
+ while(ils != NULL) {
+ switch(ils->tag) {
+ case INL_STRING:
+ escape_html(html, ils->content.literal.data, ils->content.literal.len);
+ break;
+
+ case INL_LINEBREAK:
+ gh_buf_puts(html, "
\n");
+ break;
+
+ case INL_SOFTBREAK:
+ gh_buf_putc(html, '\n');
+ break;
+
+ case INL_CODE:
+ gh_buf_puts(html, "");
+ escape_html(html, ils->content.literal.data, ils->content.literal.len);
+ gh_buf_puts(html, "
");
+ break;
+
+ case INL_RAW_HTML:
+ case INL_ENTITY:
+ gh_buf_put(html,
+ ils->content.literal.data,
+ ils->content.literal.len);
+ break;
+
+ case INL_LINK:
+ gh_buf_puts(html, "content.linkable.url, -1);
+
+ if (ils->content.linkable.title) {
+ gh_buf_puts(html, "\" title=\"");
+ escape_html(html, ils->content.linkable.title, -1);
+ }
+
+ gh_buf_puts(html, "\">");
+ inlines_to_html(html, ils->content.inlines);
+ gh_buf_puts(html, "");
+ break;
+
+ case INL_IMAGE:
+ gh_buf_puts(html, "content.linkable.url, -1);
+
+ inlines_to_html(&scrap, ils->content.inlines);
+ if (scrap.size) {
+ gh_buf_puts(html, "\" alt=\"");
+ escape_html(html, scrap.ptr, scrap.size);
+ }
+ gh_buf_clear(&scrap);
+
+ if (ils->content.linkable.title) {
+ gh_buf_puts(html, "\" title=\"");
+ escape_html(html, ils->content.linkable.title, -1);
+ }
+
+ gh_buf_puts(html, "\"/>");
+ break;
+
+ case INL_STRONG:
+ gh_buf_puts(html, "");
+ inlines_to_html(html, ils->content.inlines);
+ gh_buf_puts(html, "");
+ break;
+
+ case INL_EMPH:
+ gh_buf_puts(html, "");
+ inlines_to_html(html, ils->content.inlines);
+ gh_buf_puts(html, "");
+ break;
+ }
+ ils = ils->next;
+ }
+}
--
cgit v1.2.3
From a7314deae649646f1f7ce5ede972641b5b62538c Mon Sep 17 00:00:00 2001
From: Vicent Marti
");
+ gh_buf_puts(html, "");
cr(html);
break;
--
cgit v1.2.3
From bb6d7c4a394e61574f5f32db60da5c5f5a5e5002 Mon Sep 17 00:00:00 2001
From: Vicent Marti ");
escape_html(html, b->string_content.ptr, b->string_content.size);
- gh_buf_puts(html, "
");
+
+ gh_buf_puts(html, "
tag == fenced_code) {
+ gh_buf *info = &b->attributes.fenced_code_data.info;
+
+ if (gh_buf_len(info) > 0) {
+ int first_tag = gh_buf_strchr(info, ' ', 0);
+ if (first_tag < 0)
+ first_tag = gh_buf_len(info);
+
+
+ gh_buf_puts(html, " class=\"");
+ escape_html(html, info->ptr, first_tag);
+ gh_buf_putc(html, '"');
+ }
+ }
+
+ gh_buf_puts(html, ">
");
cr(html);
--
cgit v1.2.3
From 28be4a59c940bd55ed4fef668091d52638925c3c Mon Sep 17 00:00:00 2001
From: Vicent Marti ");
escape_html(html, b->string_content.ptr, b->string_content.size);
gh_buf_puts(html, "
"); + gh_buf_puts(html, "\n"); break; case list_item: @@ -68,8 +66,7 @@ void blocks_to_html(gh_buf *html, block *b, bool tight) gh_buf_puts(html, "\n"); blocks_to_html(html, b->children, false); - gh_buf_puts(html, ""); - cr(html); + gh_buf_puts(html, "
");
escape_html(html, b->string_content.ptr, b->string_content.size);
- gh_buf_puts(html, "
");
- cr(html);
+ gh_buf_puts(html, "\n");
break;
case html_block:
@@ -131,8 +126,7 @@ void blocks_to_html(gh_buf *html, block *b, bool tight)
break;
case hrule:
- gh_buf_puts(html, ""); + strbuf_puts(html, "
"); inlines_to_html(html, b->inline_content); - gh_buf_puts(html, "
\n"); + strbuf_puts(html, "\n"); } break; case block_quote: cr(html); - gh_buf_puts(html, "\n"); + strbuf_puts(html, "\n"); break; case list_item: cr(html); - gh_buf_puts(html, "\n"); blocks_to_html(html, b->children, false); - gh_buf_puts(html, "\n"); + strbuf_puts(html, "
tag == fenced_code) {
- gh_buf *info = &b->attributes.fenced_code_data.info;
+ strbuf *info = &b->attributes.fenced_code_data.info;
- if (gh_buf_len(info) > 0) {
- int first_tag = gh_buf_strchr(info, ' ', 0);
+ if (strbuf_len(info) > 0) {
+ int first_tag = strbuf_strchr(info, ' ', 0);
if (first_tag < 0)
- first_tag = gh_buf_len(info);
+ first_tag = strbuf_len(info);
- gh_buf_puts(html, " class=\"");
+ strbuf_puts(html, " class=\"");
escape_html(html, info->ptr, first_tag);
- gh_buf_putc(html, '"');
+ strbuf_putc(html, '"');
}
}
- gh_buf_puts(html, ">");
+ strbuf_puts(html, ">");
escape_html(html, b->string_content.ptr, b->string_content.size);
- gh_buf_puts(html, "
\n");
+ strbuf_puts(html, "\n");
break;
case html_block:
- gh_buf_put(html, b->string_content.ptr, b->string_content.size);
+ strbuf_put(html, b->string_content.ptr, b->string_content.size);
break;
case hrule:
- gh_buf_puts(html, "");
+ strbuf_puts(html, "");
escape_html(html, ils->content.literal.data, ils->content.literal.len);
- gh_buf_puts(html, "
");
+ strbuf_puts(html, "
");
break;
case INL_RAW_HTML:
case INL_ENTITY:
- gh_buf_put(html,
+ strbuf_put(html,
ils->content.literal.data,
ils->content.literal.len);
break;
case INL_LINK:
- gh_buf_puts(html, "content.linkable.url)
escape_href(html, ils->content.linkable.url, -1);
if (ils->content.linkable.title) {
- gh_buf_puts(html, "\" title=\"");
+ strbuf_puts(html, "\" title=\"");
escape_html(html, ils->content.linkable.title, -1);
}
- gh_buf_puts(html, "\">");
+ strbuf_puts(html, "\">");
inlines_to_html(html, ils->content.inlines);
- gh_buf_puts(html, "");
+ strbuf_puts(html, "\n"); blocks_to_html(html, b->children, false); strbuf_puts(html, "\n"); break; - case list_item: + case BLOCK_LIST_ITEM: cr(html); strbuf_puts(html, "
tag == fenced_code) { + if (b->tag == BLOCK_FENCED_CODE) { strbuf *info = &b->attributes.fenced_code_data.info; if (strbuf_len(info) > 0) { @@ -121,15 +121,15 @@ void blocks_to_html(strbuf *html, node_block *b, bool tight) strbuf_puts(html, "\n"); break; - case html_block: + case BLOCK_HTML: strbuf_put(html, b->string_content.ptr, b->string_content.size); break; - case hrule: + case BLOCK_HRULE: strbuf_puts(html, "
tag == BLOCK_FENCED_CODE) { - strbuf *info = &b->attributes.fenced_code_data.info; + strbuf *info = &b->as.code.info; if (strbuf_len(info) > 0) { int first_tag = strbuf_strchr(info, ' ', 0); -- cgit v1.2.3 From 2c06fa95fd3059a099bbe403beaf62f2e033f5b7 Mon Sep 17 00:00:00 2001 From: Vicent MartiDate: Tue, 9 Sep 2014 03:42:05 +0200 Subject: Fix the class attribute for code fences --- src/html/html.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/html/html.c') diff --git a/src/html/html.c b/src/html/html.c index 129335f..74f6791 100644 --- a/src/html/html.c +++ b/src/html/html.c @@ -99,7 +99,7 @@ void blocks_to_html(strbuf *html, node_block *b, bool tight) case BLOCK_FENCED_CODE: cr(html); - strbuf_puts(html, " \n"); break; -- cgit v1.2.3 From d21ef7b5db11075e038e60732682dfd8a5cf6a13 Mon Sep 17 00:00:00 2001 From: Vicent Martitag == BLOCK_FENCED_CODE) { strbuf *info = &b->as.code.info; @@ -109,14 +109,13 @@ void blocks_to_html(strbuf *html, node_block *b, bool tight) if (first_tag < 0) first_tag = strbuf_len(info); - - strbuf_puts(html, " class=\""); + strbuf_puts(html, " class=\"lang-"); escape_html(html, info->ptr, first_tag); strbuf_putc(html, '"'); } } - strbuf_puts(html, ">
"); + strbuf_putc(html, '>'); escape_html(html, b->string_content.ptr, b->string_content.size); strbuf_puts(html, "
Date: Tue, 9 Sep 2014 03:42:46 +0200 Subject: Oops --- src/html/html.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/html/html.c') diff --git a/src/html/html.c b/src/html/html.c index 74f6791..b48b10b 100644 --- a/src/html/html.c +++ b/src/html/html.c @@ -109,7 +109,7 @@ void blocks_to_html(strbuf *html, node_block *b, bool tight) if (first_tag < 0) first_tag = strbuf_len(info); - strbuf_puts(html, " class=\"lang-"); + strbuf_puts(html, " class=\"language-"); escape_html(html, info->ptr, first_tag); strbuf_putc(html, '"'); } -- cgit v1.2.3 From 118e3d3c39242225baa876319cdbfbb1adadc77b Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Mon, 15 Sep 2014 15:28:49 +0200 Subject: Cleanup external APIs --- src/html/html.c | 163 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 84 insertions(+), 79 deletions(-) (limited to 'src/html/html.c') diff --git a/src/html/html.c b/src/html/html.c index b48b10b..6f3bc76 100644 --- a/src/html/html.c +++ b/src/html/html.c @@ -32,8 +32,89 @@ static inline void cr(strbuf *html) strbuf_putc(html, '\n'); } +// 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; + + while(ils != NULL) { + switch(ils->tag) { + case INL_STRING: + escape_html(html, ils->content.literal.data, ils->content.literal.len); + break; + + case INL_LINEBREAK: + strbuf_puts(html, "
\n"); + break; + + case INL_SOFTBREAK: + strbuf_putc(html, '\n'); + break; + + case INL_CODE: + strbuf_puts(html, ""); + escape_html(html, ils->content.literal.data, ils->content.literal.len); + strbuf_puts(html, "
"); + break; + + case INL_RAW_HTML: + strbuf_put(html, + ils->content.literal.data, + ils->content.literal.len); + break; + + case INL_LINK: + strbuf_puts(html, "content.linkable.url) + escape_href(html, ils->content.linkable.url, -1); + + if (ils->content.linkable.title) { + strbuf_puts(html, "\" title=\""); + escape_html(html, ils->content.linkable.title, -1); + } + + strbuf_puts(html, "\">"); + inlines_to_html(html, ils->content.inlines); + strbuf_puts(html, ""); + break; + + case INL_IMAGE: + strbuf_puts(html, "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); + + if (ils->content.linkable.title) { + strbuf_puts(html, "\" title=\""); + escape_html(html, ils->content.linkable.title, -1); + } + + strbuf_puts(html, "\"/>"); + break; + + case INL_STRONG: + strbuf_puts(html, ""); + inlines_to_html(html, ils->content.inlines); + strbuf_puts(html, ""); + break; + + case INL_EMPH: + strbuf_puts(html, ""); + inlines_to_html(html, ils->content.inlines); + strbuf_puts(html, ""); + break; + } + ils = ils->next; + } +} + // Convert a node_block list to HTML. Returns 0 on success, and sets result. -void blocks_to_html(strbuf *html, node_block *b, bool tight) +static void blocks_to_html(strbuf *html, node_block *b, bool tight) { struct ListData *data; @@ -139,83 +220,7 @@ void blocks_to_html(strbuf *html, node_block *b, bool tight) } } -// Convert an inline list to HTML. Returns 0 on success, and sets result. -void inlines_to_html(strbuf *html, node_inl* ils) +void stmd_render_html(strbuf *html, node_block *root) { - strbuf scrap = GH_BUF_INIT; - - while(ils != NULL) { - switch(ils->tag) { - case INL_STRING: - escape_html(html, ils->content.literal.data, ils->content.literal.len); - break; - - case INL_LINEBREAK: - strbuf_puts(html, "
\n"); - break; - - case INL_SOFTBREAK: - strbuf_putc(html, '\n'); - break; - - case INL_CODE: - strbuf_puts(html, ""); - escape_html(html, ils->content.literal.data, ils->content.literal.len); - strbuf_puts(html, "
"); - break; - - case INL_RAW_HTML: - strbuf_put(html, - ils->content.literal.data, - ils->content.literal.len); - break; - - case INL_LINK: - strbuf_puts(html, "content.linkable.url) - escape_href(html, ils->content.linkable.url, -1); - - if (ils->content.linkable.title) { - strbuf_puts(html, "\" title=\""); - escape_html(html, ils->content.linkable.title, -1); - } - - strbuf_puts(html, "\">"); - inlines_to_html(html, ils->content.inlines); - strbuf_puts(html, ""); - break; - - case INL_IMAGE: - strbuf_puts(html, "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); - - if (ils->content.linkable.title) { - strbuf_puts(html, "\" title=\""); - escape_html(html, ils->content.linkable.title, -1); - } - - strbuf_puts(html, "\"/>"); - break; - - case INL_STRONG: - strbuf_puts(html, ""); - inlines_to_html(html, ils->content.inlines); - strbuf_puts(html, ""); - break; - - case INL_EMPH: - strbuf_puts(html, ""); - inlines_to_html(html, ils->content.inlines); - strbuf_puts(html, ""); - break; - } - ils = ils->next; - } + blocks_to_html(html, root, false); } -- cgit v1.2.3 From 507d8d3a09f6704e8c1f21e5a5df2e4e014e6779 Mon Sep 17 00:00:00 2001 From: Jordan MilneDate: Thu, 18 Sep 2014 09:26:05 -0300 Subject: Fix memory leak when rendering images as HTML --- src/html/html.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/html/html.c') diff --git a/src/html/html.c b/src/html/html.c index 6f3bc76..ab6fc35 100644 --- a/src/html/html.c +++ b/src/html/html.c @@ -111,6 +111,8 @@ static void inlines_to_html(strbuf *html, node_inl* ils) } ils = ils->next; } + + strbuf_free(&scrap); } // Convert a node_block list to HTML. Returns 0 on success, and sets result. -- cgit v1.2.3