From e2d1035924a06072cc938e25609ce68d0808b6d3 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 28 Oct 2021 16:36:09 +0300 Subject: Make HTML renderer not to use empty attribute syntax --- libcmark-gfm/README-DEV | 22 +- libcmark-gfm/fix-html-renderer.patch | 40 ++ libcmark-gfm/libcmark-gfm/src | 1 - libcmark-gfm/libcmark-gfm/src/arena.c | 1 + libcmark-gfm/libcmark-gfm/src/blocks.c | 1 + libcmark-gfm/libcmark-gfm/src/buffer.c | 1 + libcmark-gfm/libcmark-gfm/src/buffer.h | 1 + libcmark-gfm/libcmark-gfm/src/case_fold_switch.inc | 1 + libcmark-gfm/libcmark-gfm/src/chunk.h | 1 + .../libcmark-gfm/src/cmark-gfm-extension_api.h | 1 + libcmark-gfm/libcmark-gfm/src/cmark-gfm.h | 1 + .../libcmark-gfm/src/cmark-gfm_version.h.in | 1 + libcmark-gfm/libcmark-gfm/src/cmark.c | 1 + libcmark-gfm/libcmark-gfm/src/cmark_ctype.c | 1 + libcmark-gfm/libcmark-gfm/src/cmark_ctype.h | 1 + libcmark-gfm/libcmark-gfm/src/commonmark.c | 1 + libcmark-gfm/libcmark-gfm/src/config.h.in | 1 + libcmark-gfm/libcmark-gfm/src/entities.inc | 1 + libcmark-gfm/libcmark-gfm/src/footnotes.c | 1 + libcmark-gfm/libcmark-gfm/src/footnotes.h | 1 + libcmark-gfm/libcmark-gfm/src/houdini.h | 1 + libcmark-gfm/libcmark-gfm/src/houdini_href_e.c | 1 + libcmark-gfm/libcmark-gfm/src/houdini_html_e.c | 1 + libcmark-gfm/libcmark-gfm/src/houdini_html_u.c | 1 + libcmark-gfm/libcmark-gfm/src/html.c | 486 +++++++++++++++++++++ libcmark-gfm/libcmark-gfm/src/html.c.orig | 1 + libcmark-gfm/libcmark-gfm/src/html.h | 1 + libcmark-gfm/libcmark-gfm/src/inlines.c | 1 + libcmark-gfm/libcmark-gfm/src/inlines.h | 1 + libcmark-gfm/libcmark-gfm/src/iterator.c | 1 + libcmark-gfm/libcmark-gfm/src/iterator.h | 1 + libcmark-gfm/libcmark-gfm/src/latex.c | 1 + libcmark-gfm/libcmark-gfm/src/libcmark-gfm.pc.in | 1 + libcmark-gfm/libcmark-gfm/src/linked_list.c | 1 + libcmark-gfm/libcmark-gfm/src/main.c | 1 + libcmark-gfm/libcmark-gfm/src/man.c | 1 + libcmark-gfm/libcmark-gfm/src/map.c | 1 + libcmark-gfm/libcmark-gfm/src/map.h | 1 + libcmark-gfm/libcmark-gfm/src/node.c | 1 + libcmark-gfm/libcmark-gfm/src/node.h | 1 + libcmark-gfm/libcmark-gfm/src/parser.h | 1 + libcmark-gfm/libcmark-gfm/src/plaintext.c | 1 + libcmark-gfm/libcmark-gfm/src/plugin.c | 1 + libcmark-gfm/libcmark-gfm/src/plugin.h | 1 + libcmark-gfm/libcmark-gfm/src/references.c | 1 + libcmark-gfm/libcmark-gfm/src/references.h | 1 + libcmark-gfm/libcmark-gfm/src/registry.c | 1 + libcmark-gfm/libcmark-gfm/src/registry.h | 1 + libcmark-gfm/libcmark-gfm/src/render.c | 1 + libcmark-gfm/libcmark-gfm/src/render.h | 1 + libcmark-gfm/libcmark-gfm/src/scanners.c | 1 + libcmark-gfm/libcmark-gfm/src/scanners.h | 1 + libcmark-gfm/libcmark-gfm/src/syntax_extension.c | 1 + libcmark-gfm/libcmark-gfm/src/syntax_extension.h | 1 + libcmark-gfm/libcmark-gfm/src/utf8.c | 1 + libcmark-gfm/libcmark-gfm/src/utf8.h | 1 + libcmark-gfm/libcmark-gfm/src/xml.c | 1 + 57 files changed, 597 insertions(+), 5 deletions(-) create mode 100644 libcmark-gfm/fix-html-renderer.patch delete mode 120000 libcmark-gfm/libcmark-gfm/src create mode 120000 libcmark-gfm/libcmark-gfm/src/arena.c create mode 120000 libcmark-gfm/libcmark-gfm/src/blocks.c create mode 120000 libcmark-gfm/libcmark-gfm/src/buffer.c create mode 120000 libcmark-gfm/libcmark-gfm/src/buffer.h create mode 120000 libcmark-gfm/libcmark-gfm/src/case_fold_switch.inc create mode 120000 libcmark-gfm/libcmark-gfm/src/chunk.h create mode 120000 libcmark-gfm/libcmark-gfm/src/cmark-gfm-extension_api.h create mode 120000 libcmark-gfm/libcmark-gfm/src/cmark-gfm.h create mode 120000 libcmark-gfm/libcmark-gfm/src/cmark-gfm_version.h.in create mode 120000 libcmark-gfm/libcmark-gfm/src/cmark.c create mode 120000 libcmark-gfm/libcmark-gfm/src/cmark_ctype.c create mode 120000 libcmark-gfm/libcmark-gfm/src/cmark_ctype.h create mode 120000 libcmark-gfm/libcmark-gfm/src/commonmark.c create mode 120000 libcmark-gfm/libcmark-gfm/src/config.h.in create mode 120000 libcmark-gfm/libcmark-gfm/src/entities.inc create mode 120000 libcmark-gfm/libcmark-gfm/src/footnotes.c create mode 120000 libcmark-gfm/libcmark-gfm/src/footnotes.h create mode 120000 libcmark-gfm/libcmark-gfm/src/houdini.h create mode 120000 libcmark-gfm/libcmark-gfm/src/houdini_href_e.c create mode 120000 libcmark-gfm/libcmark-gfm/src/houdini_html_e.c create mode 120000 libcmark-gfm/libcmark-gfm/src/houdini_html_u.c create mode 100644 libcmark-gfm/libcmark-gfm/src/html.c create mode 120000 libcmark-gfm/libcmark-gfm/src/html.c.orig create mode 120000 libcmark-gfm/libcmark-gfm/src/html.h create mode 120000 libcmark-gfm/libcmark-gfm/src/inlines.c create mode 120000 libcmark-gfm/libcmark-gfm/src/inlines.h create mode 120000 libcmark-gfm/libcmark-gfm/src/iterator.c create mode 120000 libcmark-gfm/libcmark-gfm/src/iterator.h create mode 120000 libcmark-gfm/libcmark-gfm/src/latex.c create mode 120000 libcmark-gfm/libcmark-gfm/src/libcmark-gfm.pc.in create mode 120000 libcmark-gfm/libcmark-gfm/src/linked_list.c create mode 120000 libcmark-gfm/libcmark-gfm/src/main.c create mode 120000 libcmark-gfm/libcmark-gfm/src/man.c create mode 120000 libcmark-gfm/libcmark-gfm/src/map.c create mode 120000 libcmark-gfm/libcmark-gfm/src/map.h create mode 120000 libcmark-gfm/libcmark-gfm/src/node.c create mode 120000 libcmark-gfm/libcmark-gfm/src/node.h create mode 120000 libcmark-gfm/libcmark-gfm/src/parser.h create mode 120000 libcmark-gfm/libcmark-gfm/src/plaintext.c create mode 120000 libcmark-gfm/libcmark-gfm/src/plugin.c create mode 120000 libcmark-gfm/libcmark-gfm/src/plugin.h create mode 120000 libcmark-gfm/libcmark-gfm/src/references.c create mode 120000 libcmark-gfm/libcmark-gfm/src/references.h create mode 120000 libcmark-gfm/libcmark-gfm/src/registry.c create mode 120000 libcmark-gfm/libcmark-gfm/src/registry.h create mode 120000 libcmark-gfm/libcmark-gfm/src/render.c create mode 120000 libcmark-gfm/libcmark-gfm/src/render.h create mode 120000 libcmark-gfm/libcmark-gfm/src/scanners.c create mode 120000 libcmark-gfm/libcmark-gfm/src/scanners.h create mode 120000 libcmark-gfm/libcmark-gfm/src/syntax_extension.c create mode 120000 libcmark-gfm/libcmark-gfm/src/syntax_extension.h create mode 120000 libcmark-gfm/libcmark-gfm/src/utf8.c create mode 120000 libcmark-gfm/libcmark-gfm/src/utf8.h create mode 120000 libcmark-gfm/libcmark-gfm/src/xml.c diff --git a/libcmark-gfm/README-DEV b/libcmark-gfm/README-DEV index dbf398b..94a742b 100644 --- a/libcmark-gfm/README-DEV +++ b/libcmark-gfm/README-DEV @@ -4,11 +4,25 @@ version. See ../README-DEV for general notes on cmark-gfm packaging. Symlink the required upstream files and directories into libcmark-gfm/: -$ ln -s ../../upstream/src libcmark-gfm +$ mkdir -p libcmark-gfm/src +$ pushd libcmark-gfm/src +$ ln -s ../../../upstream/src/*.{c,h,inc,in} ./ -Note that we unable to generate cmark-gfm_version.h directly from the template -as it is included as "cmark-gfm_version.h" in upstream's source code, which -makes impossible using the header-generating machinery. That's why we create +Also patch the HTML renderer not to use the empty attribute syntax (see the +reported issue #245 for details): + +$ mv html.c html.c.orig +$ cp html.c.orig html.c +$ git apply fix-html-renderer.patch +$ popd + +Note that patches are produced by commands similar to the following: + +$ git diff >fix-html-renderer.patch + +We unable to generate cmark-gfm_version.h directly from the template, since it +is included as "cmark-gfm_version.h" in upstream's source code, which makes +impossible using the header-generating machinery. That's why we create libcmark-gfm/cmark-gfm_version.h that includes that we auto-generate from upstream's src/cmark-gfm_version.h.in. diff --git a/libcmark-gfm/fix-html-renderer.patch b/libcmark-gfm/fix-html-renderer.patch new file mode 100644 index 0000000..58ac333 --- /dev/null +++ b/libcmark-gfm/fix-html-renderer.patch @@ -0,0 +1,40 @@ +diff --git a/libcmark-gfm/libcmark-gfm/src/html.c b/libcmark-gfm/libcmark-gfm/src/html.c +index 12d3c3e..f662aa3 100644 +--- a/libcmark-gfm/libcmark-gfm/src/html.c ++++ b/libcmark-gfm/libcmark-gfm/src/html.c +@@ -66,7 +66,7 @@ static bool S_put_footnote_backref(cmark_html_renderer *renderer, cmark_strbuf * + + cmark_strbuf_puts(html, "as.literal.data, node->as.literal.len); +- cmark_strbuf_puts(html, "\" class=\"footnote-backref\" data-footnote-backref aria-label=\"Back to content\">↩"); ++ cmark_strbuf_puts(html, "\" class=\"footnote-backref\" data-footnote-backref=\"\" aria-label=\"Back to content\">↩"); + + if (node->footnote.def_count > 1) + { +@@ -78,7 +78,7 @@ static bool S_put_footnote_backref(cmark_html_renderer *renderer, cmark_strbuf * + houdini_escape_href(html, node->as.literal.data, node->as.literal.len); + cmark_strbuf_puts(html, "-"); + cmark_strbuf_puts(html, n); +- cmark_strbuf_puts(html, "\" class=\"footnote-backref\" data-footnote-backref aria-label=\"Back to content\">↩"); ++ cmark_strbuf_puts(html, "\" class=\"footnote-backref\" data-footnote-backref=\"\" aria-label=\"Back to content\">↩"); + cmark_strbuf_puts(html, n); + cmark_strbuf_puts(html, ""); + } +@@ -406,7 +406,7 @@ static int S_render_node(cmark_html_renderer *renderer, cmark_node *node, + case CMARK_NODE_FOOTNOTE_DEFINITION: + if (entering) { + if (renderer->footnote_ix == 0) { +- cmark_strbuf_puts(html, "
\n
    \n"); ++ cmark_strbuf_puts(html, "
    \n
      \n"); + } + ++renderer->footnote_ix; + +@@ -435,7 +435,7 @@ static int S_render_node(cmark_html_renderer *renderer, cmark_node *node, + cmark_strbuf_puts(html, n); + } + +- cmark_strbuf_puts(html, "\" data-footnote-ref>"); ++ cmark_strbuf_puts(html, "\" data-footnote-ref=\"\">"); + houdini_escape_href(html, node->as.literal.data, node->as.literal.len); + cmark_strbuf_puts(html, ""); + } diff --git a/libcmark-gfm/libcmark-gfm/src b/libcmark-gfm/libcmark-gfm/src deleted file mode 120000 index ff7dce8..0000000 --- a/libcmark-gfm/libcmark-gfm/src +++ /dev/null @@ -1 +0,0 @@ -../../upstream/src \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/arena.c b/libcmark-gfm/libcmark-gfm/src/arena.c new file mode 120000 index 0000000..9732449 --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/arena.c @@ -0,0 +1 @@ +../../../upstream/src/arena.c \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/blocks.c b/libcmark-gfm/libcmark-gfm/src/blocks.c new file mode 120000 index 0000000..90cbe20 --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/blocks.c @@ -0,0 +1 @@ +../../../upstream/src/blocks.c \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/buffer.c b/libcmark-gfm/libcmark-gfm/src/buffer.c new file mode 120000 index 0000000..7f89eab --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/buffer.c @@ -0,0 +1 @@ +../../../upstream/src/buffer.c \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/buffer.h b/libcmark-gfm/libcmark-gfm/src/buffer.h new file mode 120000 index 0000000..9075fc8 --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/buffer.h @@ -0,0 +1 @@ +../../../upstream/src/buffer.h \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/case_fold_switch.inc b/libcmark-gfm/libcmark-gfm/src/case_fold_switch.inc new file mode 120000 index 0000000..7b336f2 --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/case_fold_switch.inc @@ -0,0 +1 @@ +../../../upstream/src/case_fold_switch.inc \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/chunk.h b/libcmark-gfm/libcmark-gfm/src/chunk.h new file mode 120000 index 0000000..9d7c402 --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/chunk.h @@ -0,0 +1 @@ +../../../upstream/src/chunk.h \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/cmark-gfm-extension_api.h b/libcmark-gfm/libcmark-gfm/src/cmark-gfm-extension_api.h new file mode 120000 index 0000000..5799e0a --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/cmark-gfm-extension_api.h @@ -0,0 +1 @@ +../../../upstream/src/cmark-gfm-extension_api.h \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/cmark-gfm.h b/libcmark-gfm/libcmark-gfm/src/cmark-gfm.h new file mode 120000 index 0000000..0f74546 --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/cmark-gfm.h @@ -0,0 +1 @@ +../../../upstream/src/cmark-gfm.h \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/cmark-gfm_version.h.in b/libcmark-gfm/libcmark-gfm/src/cmark-gfm_version.h.in new file mode 120000 index 0000000..3d0201d --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/cmark-gfm_version.h.in @@ -0,0 +1 @@ +../../../upstream/src/cmark-gfm_version.h.in \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/cmark.c b/libcmark-gfm/libcmark-gfm/src/cmark.c new file mode 120000 index 0000000..68eb4c6 --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/cmark.c @@ -0,0 +1 @@ +../../../upstream/src/cmark.c \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/cmark_ctype.c b/libcmark-gfm/libcmark-gfm/src/cmark_ctype.c new file mode 120000 index 0000000..cc41036 --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/cmark_ctype.c @@ -0,0 +1 @@ +../../../upstream/src/cmark_ctype.c \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/cmark_ctype.h b/libcmark-gfm/libcmark-gfm/src/cmark_ctype.h new file mode 120000 index 0000000..a37e884 --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/cmark_ctype.h @@ -0,0 +1 @@ +../../../upstream/src/cmark_ctype.h \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/commonmark.c b/libcmark-gfm/libcmark-gfm/src/commonmark.c new file mode 120000 index 0000000..ba2a48b --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/commonmark.c @@ -0,0 +1 @@ +../../../upstream/src/commonmark.c \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/config.h.in b/libcmark-gfm/libcmark-gfm/src/config.h.in new file mode 120000 index 0000000..3e00fe0 --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/config.h.in @@ -0,0 +1 @@ +../../../upstream/src/config.h.in \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/entities.inc b/libcmark-gfm/libcmark-gfm/src/entities.inc new file mode 120000 index 0000000..0a553d3 --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/entities.inc @@ -0,0 +1 @@ +../../../upstream/src/entities.inc \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/footnotes.c b/libcmark-gfm/libcmark-gfm/src/footnotes.c new file mode 120000 index 0000000..83d0262 --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/footnotes.c @@ -0,0 +1 @@ +../../../upstream/src/footnotes.c \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/footnotes.h b/libcmark-gfm/libcmark-gfm/src/footnotes.h new file mode 120000 index 0000000..c2dbfbf --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/footnotes.h @@ -0,0 +1 @@ +../../../upstream/src/footnotes.h \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/houdini.h b/libcmark-gfm/libcmark-gfm/src/houdini.h new file mode 120000 index 0000000..c064043 --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/houdini.h @@ -0,0 +1 @@ +../../../upstream/src/houdini.h \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/houdini_href_e.c b/libcmark-gfm/libcmark-gfm/src/houdini_href_e.c new file mode 120000 index 0000000..745e627 --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/houdini_href_e.c @@ -0,0 +1 @@ +../../../upstream/src/houdini_href_e.c \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/houdini_html_e.c b/libcmark-gfm/libcmark-gfm/src/houdini_html_e.c new file mode 120000 index 0000000..fcda553 --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/houdini_html_e.c @@ -0,0 +1 @@ +../../../upstream/src/houdini_html_e.c \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/houdini_html_u.c b/libcmark-gfm/libcmark-gfm/src/houdini_html_u.c new file mode 120000 index 0000000..95a168b --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/houdini_html_u.c @@ -0,0 +1 @@ +../../../upstream/src/houdini_html_u.c \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/html.c b/libcmark-gfm/libcmark-gfm/src/html.c new file mode 100644 index 0000000..f662aa3 --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/html.c @@ -0,0 +1,486 @@ +#include +#include +#include +#include +#include "cmark_ctype.h" +#include "config.h" +#include "cmark-gfm.h" +#include "houdini.h" +#include "scanners.h" +#include "syntax_extension.h" +#include "html.h" +#include "render.h" + +// Functions to convert cmark_nodes to HTML strings. + +static void escape_html(cmark_strbuf *dest, const unsigned char *source, + bufsize_t length) { + houdini_escape_html0(dest, source, length, 0); +} + +static void filter_html_block(cmark_html_renderer *renderer, uint8_t *data, size_t len) { + cmark_strbuf *html = renderer->html; + cmark_llist *it; + cmark_syntax_extension *ext; + bool filtered; + uint8_t *match; + + while (len) { + match = (uint8_t *) memchr(data, '<', len); + if (!match) + break; + + if (match != data) { + cmark_strbuf_put(html, data, (bufsize_t)(match - data)); + len -= (match - data); + data = match; + } + + filtered = false; + for (it = renderer->filter_extensions; it; it = it->next) { + ext = ((cmark_syntax_extension *) it->data); + if (!ext->html_filter_func(ext, data, len)) { + filtered = true; + break; + } + } + + if (!filtered) { + cmark_strbuf_putc(html, '<'); + } else { + cmark_strbuf_puts(html, "<"); + } + + ++data; + --len; + } + + if (len) + cmark_strbuf_put(html, data, (bufsize_t)len); +} + +static bool S_put_footnote_backref(cmark_html_renderer *renderer, cmark_strbuf *html, cmark_node *node) { + if (renderer->written_footnote_ix >= renderer->footnote_ix) + return false; + renderer->written_footnote_ix = renderer->footnote_ix; + + cmark_strbuf_puts(html, "as.literal.data, node->as.literal.len); + cmark_strbuf_puts(html, "\" class=\"footnote-backref\" data-footnote-backref=\"\" aria-label=\"Back to content\">↩"); + + if (node->footnote.def_count > 1) + { + for(int i = 2; i <= node->footnote.def_count; i++) { + char n[32]; + snprintf(n, sizeof(n), "%d", i); + + cmark_strbuf_puts(html, " as.literal.data, node->as.literal.len); + cmark_strbuf_puts(html, "-"); + cmark_strbuf_puts(html, n); + cmark_strbuf_puts(html, "\" class=\"footnote-backref\" data-footnote-backref=\"\" aria-label=\"Back to content\">↩"); + cmark_strbuf_puts(html, n); + cmark_strbuf_puts(html, ""); + } + } + + return true; +} + +static int S_render_node(cmark_html_renderer *renderer, cmark_node *node, + cmark_event_type ev_type, int options) { + cmark_node *parent; + cmark_node *grandparent; + cmark_strbuf *html = renderer->html; + cmark_llist *it; + cmark_syntax_extension *ext; + char start_heading[] = "plain == node) { // back at original node + renderer->plain = NULL; + } + + if (renderer->plain != NULL) { + switch (node->type) { + case CMARK_NODE_TEXT: + case CMARK_NODE_CODE: + case CMARK_NODE_HTML_INLINE: + escape_html(html, node->as.literal.data, node->as.literal.len); + break; + + case CMARK_NODE_LINEBREAK: + case CMARK_NODE_SOFTBREAK: + cmark_strbuf_putc(html, ' '); + break; + + default: + break; + } + return 1; + } + + if (node->extension && node->extension->html_render_func) { + node->extension->html_render_func(node->extension, renderer, node, ev_type, options); + return 1; + } + + switch (node->type) { + case CMARK_NODE_DOCUMENT: + break; + + case CMARK_NODE_BLOCK_QUOTE: + if (entering) { + cmark_html_render_cr(html); + cmark_strbuf_puts(html, "\n"); + } else { + cmark_html_render_cr(html); + cmark_strbuf_puts(html, "\n"); + } + break; + + case CMARK_NODE_LIST: { + cmark_list_type list_type = node->as.list.list_type; + int start = node->as.list.start; + + if (entering) { + cmark_html_render_cr(html); + if (list_type == CMARK_BULLET_LIST) { + cmark_strbuf_puts(html, "\n"); + } else if (start == 1) { + cmark_strbuf_puts(html, "\n"); + } else { + snprintf(buffer, BUFFER_SIZE, "
        \n"); + } + } else { + cmark_strbuf_puts(html, + list_type == CMARK_BULLET_LIST ? "\n" : "
      \n"); + } + break; + } + + case CMARK_NODE_ITEM: + if (entering) { + cmark_html_render_cr(html); + cmark_strbuf_puts(html, "'); + } else { + cmark_strbuf_puts(html, "\n"); + } + break; + + case CMARK_NODE_HEADING: + if (entering) { + cmark_html_render_cr(html); + start_heading[2] = (char)('0' + node->as.heading.level); + cmark_strbuf_puts(html, start_heading); + cmark_html_render_sourcepos(node, html, options); + cmark_strbuf_putc(html, '>'); + } else { + end_heading[3] = (char)('0' + node->as.heading.level); + cmark_strbuf_puts(html, end_heading); + cmark_strbuf_puts(html, ">\n"); + } + break; + + case CMARK_NODE_CODE_BLOCK: + cmark_html_render_cr(html); + + if (node->as.code.info.len == 0) { + cmark_strbuf_puts(html, ""); + } else { + bufsize_t first_tag = 0; + while (first_tag < node->as.code.info.len && + !cmark_isspace(node->as.code.info.data[first_tag])) { + first_tag += 1; + } + + if (options & CMARK_OPT_GITHUB_PRE_LANG) { + cmark_strbuf_puts(html, "as.code.info.data, first_tag); + if (first_tag < node->as.code.info.len && (options & CMARK_OPT_FULL_INFO_STRING)) { + cmark_strbuf_puts(html, "\" data-meta=\""); + escape_html(html, node->as.code.info.data + first_tag + 1, node->as.code.info.len - first_tag - 1); + } + cmark_strbuf_puts(html, "\">"); + } else { + cmark_strbuf_puts(html, "as.code.info.data, first_tag); + if (first_tag < node->as.code.info.len && (options & CMARK_OPT_FULL_INFO_STRING)) { + cmark_strbuf_puts(html, "\" data-meta=\""); + escape_html(html, node->as.code.info.data + first_tag + 1, node->as.code.info.len - first_tag - 1); + } + cmark_strbuf_puts(html, "\">"); + } + } + + escape_html(html, node->as.code.literal.data, node->as.code.literal.len); + cmark_strbuf_puts(html, "\n"); + break; + + case CMARK_NODE_HTML_BLOCK: + cmark_html_render_cr(html); + if (!(options & CMARK_OPT_UNSAFE)) { + cmark_strbuf_puts(html, ""); + } else if (renderer->filter_extensions) { + filter_html_block(renderer, node->as.literal.data, node->as.literal.len); + } else { + cmark_strbuf_put(html, node->as.literal.data, node->as.literal.len); + } + cmark_html_render_cr(html); + break; + + case CMARK_NODE_CUSTOM_BLOCK: + cmark_html_render_cr(html); + if (entering) { + cmark_strbuf_put(html, node->as.custom.on_enter.data, + node->as.custom.on_enter.len); + } else { + cmark_strbuf_put(html, node->as.custom.on_exit.data, + node->as.custom.on_exit.len); + } + cmark_html_render_cr(html); + break; + + case CMARK_NODE_THEMATIC_BREAK: + cmark_html_render_cr(html); + cmark_strbuf_puts(html, "\n"); + break; + + case CMARK_NODE_PARAGRAPH: + parent = cmark_node_parent(node); + grandparent = cmark_node_parent(parent); + if (grandparent != NULL && grandparent->type == CMARK_NODE_LIST) { + tight = grandparent->as.list.tight; + } else { + tight = false; + } + if (!tight) { + if (entering) { + cmark_html_render_cr(html); + cmark_strbuf_puts(html, "'); + } else { + if (parent->type == CMARK_NODE_FOOTNOTE_DEFINITION && node->next == NULL) { + cmark_strbuf_putc(html, ' '); + S_put_footnote_backref(renderer, html, parent); + } + cmark_strbuf_puts(html, "

      \n"); + } + } + break; + + case CMARK_NODE_TEXT: + escape_html(html, node->as.literal.data, node->as.literal.len); + break; + + case CMARK_NODE_LINEBREAK: + cmark_strbuf_puts(html, "
      \n"); + break; + + case CMARK_NODE_SOFTBREAK: + if (options & CMARK_OPT_HARDBREAKS) { + cmark_strbuf_puts(html, "
      \n"); + } else if (options & CMARK_OPT_NOBREAKS) { + cmark_strbuf_putc(html, ' '); + } else { + cmark_strbuf_putc(html, '\n'); + } + break; + + case CMARK_NODE_CODE: + cmark_strbuf_puts(html, ""); + escape_html(html, node->as.literal.data, node->as.literal.len); + cmark_strbuf_puts(html, ""); + break; + + case CMARK_NODE_HTML_INLINE: + if (!(options & CMARK_OPT_UNSAFE)) { + cmark_strbuf_puts(html, ""); + } else { + filtered = false; + for (it = renderer->filter_extensions; it; it = it->next) { + ext = (cmark_syntax_extension *) it->data; + if (!ext->html_filter_func(ext, node->as.literal.data, node->as.literal.len)) { + filtered = true; + break; + } + } + if (!filtered) { + cmark_strbuf_put(html, node->as.literal.data, node->as.literal.len); + } else { + cmark_strbuf_puts(html, "<"); + cmark_strbuf_put(html, node->as.literal.data + 1, node->as.literal.len - 1); + } + } + break; + + case CMARK_NODE_CUSTOM_INLINE: + if (entering) { + cmark_strbuf_put(html, node->as.custom.on_enter.data, + node->as.custom.on_enter.len); + } else { + cmark_strbuf_put(html, node->as.custom.on_exit.data, + node->as.custom.on_exit.len); + } + break; + + case CMARK_NODE_STRONG: + if (entering) { + cmark_strbuf_puts(html, ""); + } else { + cmark_strbuf_puts(html, ""); + } + break; + + case CMARK_NODE_EMPH: + if (entering) { + cmark_strbuf_puts(html, ""); + } else { + cmark_strbuf_puts(html, ""); + } + break; + + case CMARK_NODE_LINK: + if (entering) { + cmark_strbuf_puts(html, "as.link.url, 0))) { + houdini_escape_href(html, node->as.link.url.data, + node->as.link.url.len); + } + if (node->as.link.title.len) { + cmark_strbuf_puts(html, "\" title=\""); + escape_html(html, node->as.link.title.data, node->as.link.title.len); + } + cmark_strbuf_puts(html, "\">"); + } else { + cmark_strbuf_puts(html, ""); + } + break; + + case CMARK_NODE_IMAGE: + if (entering) { + cmark_strbuf_puts(html, "as.link.url, 0))) { + houdini_escape_href(html, node->as.link.url.data, + node->as.link.url.len); + } + cmark_strbuf_puts(html, "\" alt=\""); + renderer->plain = node; + } else { + if (node->as.link.title.len) { + cmark_strbuf_puts(html, "\" title=\""); + escape_html(html, node->as.link.title.data, node->as.link.title.len); + } + + cmark_strbuf_puts(html, "\" />"); + } + break; + + case CMARK_NODE_FOOTNOTE_DEFINITION: + if (entering) { + if (renderer->footnote_ix == 0) { + cmark_strbuf_puts(html, "
      \n
        \n"); + } + ++renderer->footnote_ix; + + cmark_strbuf_puts(html, "
      1. as.literal.data, node->as.literal.len); + cmark_strbuf_puts(html, "\">\n"); + } else { + if (S_put_footnote_backref(renderer, html, node)) { + cmark_strbuf_putc(html, '\n'); + } + cmark_strbuf_puts(html, "
      2. \n"); + } + break; + + case CMARK_NODE_FOOTNOTE_REFERENCE: + if (entering) { + cmark_strbuf_puts(html, "parent_footnote_def->as.literal.data, node->parent_footnote_def->as.literal.len); + cmark_strbuf_puts(html, "\" id=\"fnref-"); + houdini_escape_href(html, node->parent_footnote_def->as.literal.data, node->parent_footnote_def->as.literal.len); + + if (node->footnote.ref_ix > 1) { + char n[32]; + snprintf(n, sizeof(n), "%d", node->footnote.ref_ix); + cmark_strbuf_puts(html, "-"); + cmark_strbuf_puts(html, n); + } + + cmark_strbuf_puts(html, "\" data-footnote-ref=\"\">"); + houdini_escape_href(html, node->as.literal.data, node->as.literal.len); + cmark_strbuf_puts(html, ""); + } + break; + + default: + assert(false); + break; + } + + return 1; +} + +char *cmark_render_html(cmark_node *root, int options, cmark_llist *extensions) { + return cmark_render_html_with_mem(root, options, extensions, cmark_node_mem(root)); +} + +char *cmark_render_html_with_mem(cmark_node *root, int options, cmark_llist *extensions, cmark_mem *mem) { + char *result; + cmark_strbuf html = CMARK_BUF_INIT(mem); + cmark_event_type ev_type; + cmark_node *cur; + cmark_html_renderer renderer = {&html, NULL, NULL, 0, 0, NULL}; + cmark_iter *iter = cmark_iter_new(root); + + for (; extensions; extensions = extensions->next) + if (((cmark_syntax_extension *) extensions->data)->html_filter_func) + renderer.filter_extensions = cmark_llist_append( + mem, + renderer.filter_extensions, + (cmark_syntax_extension *) extensions->data); + + while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) { + cur = cmark_iter_get_node(iter); + S_render_node(&renderer, cur, ev_type, options); + } + + if (renderer.footnote_ix) { + cmark_strbuf_puts(&html, "
      \n
      \n"); + } + + result = (char *)cmark_strbuf_detach(&html); + + cmark_llist_free(mem, renderer.filter_extensions); + + cmark_iter_free(iter); + return result; +} diff --git a/libcmark-gfm/libcmark-gfm/src/html.c.orig b/libcmark-gfm/libcmark-gfm/src/html.c.orig new file mode 120000 index 0000000..e027c12 --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/html.c.orig @@ -0,0 +1 @@ +../../../upstream/src/html.c \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/html.h b/libcmark-gfm/libcmark-gfm/src/html.h new file mode 120000 index 0000000..adda921 --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/html.h @@ -0,0 +1 @@ +../../../upstream/src/html.h \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/inlines.c b/libcmark-gfm/libcmark-gfm/src/inlines.c new file mode 120000 index 0000000..9e9aafb --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/inlines.c @@ -0,0 +1 @@ +../../../upstream/src/inlines.c \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/inlines.h b/libcmark-gfm/libcmark-gfm/src/inlines.h new file mode 120000 index 0000000..0a668de --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/inlines.h @@ -0,0 +1 @@ +../../../upstream/src/inlines.h \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/iterator.c b/libcmark-gfm/libcmark-gfm/src/iterator.c new file mode 120000 index 0000000..cfb4a63 --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/iterator.c @@ -0,0 +1 @@ +../../../upstream/src/iterator.c \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/iterator.h b/libcmark-gfm/libcmark-gfm/src/iterator.h new file mode 120000 index 0000000..28748ee --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/iterator.h @@ -0,0 +1 @@ +../../../upstream/src/iterator.h \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/latex.c b/libcmark-gfm/libcmark-gfm/src/latex.c new file mode 120000 index 0000000..d75b63b --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/latex.c @@ -0,0 +1 @@ +../../../upstream/src/latex.c \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/libcmark-gfm.pc.in b/libcmark-gfm/libcmark-gfm/src/libcmark-gfm.pc.in new file mode 120000 index 0000000..9599079 --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/libcmark-gfm.pc.in @@ -0,0 +1 @@ +../../../upstream/src/libcmark-gfm.pc.in \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/linked_list.c b/libcmark-gfm/libcmark-gfm/src/linked_list.c new file mode 120000 index 0000000..3ea373f --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/linked_list.c @@ -0,0 +1 @@ +../../../upstream/src/linked_list.c \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/main.c b/libcmark-gfm/libcmark-gfm/src/main.c new file mode 120000 index 0000000..84494ea --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/main.c @@ -0,0 +1 @@ +../../../upstream/src/main.c \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/man.c b/libcmark-gfm/libcmark-gfm/src/man.c new file mode 120000 index 0000000..5699a40 --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/man.c @@ -0,0 +1 @@ +../../../upstream/src/man.c \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/map.c b/libcmark-gfm/libcmark-gfm/src/map.c new file mode 120000 index 0000000..3fcd65c --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/map.c @@ -0,0 +1 @@ +../../../upstream/src/map.c \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/map.h b/libcmark-gfm/libcmark-gfm/src/map.h new file mode 120000 index 0000000..b12d78b --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/map.h @@ -0,0 +1 @@ +../../../upstream/src/map.h \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/node.c b/libcmark-gfm/libcmark-gfm/src/node.c new file mode 120000 index 0000000..2e04437 --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/node.c @@ -0,0 +1 @@ +../../../upstream/src/node.c \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/node.h b/libcmark-gfm/libcmark-gfm/src/node.h new file mode 120000 index 0000000..96d704d --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/node.h @@ -0,0 +1 @@ +../../../upstream/src/node.h \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/parser.h b/libcmark-gfm/libcmark-gfm/src/parser.h new file mode 120000 index 0000000..7c43e4a --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/parser.h @@ -0,0 +1 @@ +../../../upstream/src/parser.h \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/plaintext.c b/libcmark-gfm/libcmark-gfm/src/plaintext.c new file mode 120000 index 0000000..7e66f56 --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/plaintext.c @@ -0,0 +1 @@ +../../../upstream/src/plaintext.c \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/plugin.c b/libcmark-gfm/libcmark-gfm/src/plugin.c new file mode 120000 index 0000000..3cb8b5e --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/plugin.c @@ -0,0 +1 @@ +../../../upstream/src/plugin.c \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/plugin.h b/libcmark-gfm/libcmark-gfm/src/plugin.h new file mode 120000 index 0000000..d140a86 --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/plugin.h @@ -0,0 +1 @@ +../../../upstream/src/plugin.h \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/references.c b/libcmark-gfm/libcmark-gfm/src/references.c new file mode 120000 index 0000000..8a869df --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/references.c @@ -0,0 +1 @@ +../../../upstream/src/references.c \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/references.h b/libcmark-gfm/libcmark-gfm/src/references.h new file mode 120000 index 0000000..4109166 --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/references.h @@ -0,0 +1 @@ +../../../upstream/src/references.h \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/registry.c b/libcmark-gfm/libcmark-gfm/src/registry.c new file mode 120000 index 0000000..7b8e408 --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/registry.c @@ -0,0 +1 @@ +../../../upstream/src/registry.c \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/registry.h b/libcmark-gfm/libcmark-gfm/src/registry.h new file mode 120000 index 0000000..a624415 --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/registry.h @@ -0,0 +1 @@ +../../../upstream/src/registry.h \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/render.c b/libcmark-gfm/libcmark-gfm/src/render.c new file mode 120000 index 0000000..f8cc43f --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/render.c @@ -0,0 +1 @@ +../../../upstream/src/render.c \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/render.h b/libcmark-gfm/libcmark-gfm/src/render.h new file mode 120000 index 0000000..d49f62f --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/render.h @@ -0,0 +1 @@ +../../../upstream/src/render.h \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/scanners.c b/libcmark-gfm/libcmark-gfm/src/scanners.c new file mode 120000 index 0000000..a35e4fc --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/scanners.c @@ -0,0 +1 @@ +../../../upstream/src/scanners.c \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/scanners.h b/libcmark-gfm/libcmark-gfm/src/scanners.h new file mode 120000 index 0000000..6924b87 --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/scanners.h @@ -0,0 +1 @@ +../../../upstream/src/scanners.h \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/syntax_extension.c b/libcmark-gfm/libcmark-gfm/src/syntax_extension.c new file mode 120000 index 0000000..dca0f4a --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/syntax_extension.c @@ -0,0 +1 @@ +../../../upstream/src/syntax_extension.c \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/syntax_extension.h b/libcmark-gfm/libcmark-gfm/src/syntax_extension.h new file mode 120000 index 0000000..0948201 --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/syntax_extension.h @@ -0,0 +1 @@ +../../../upstream/src/syntax_extension.h \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/utf8.c b/libcmark-gfm/libcmark-gfm/src/utf8.c new file mode 120000 index 0000000..cd9a96c --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/utf8.c @@ -0,0 +1 @@ +../../../upstream/src/utf8.c \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/utf8.h b/libcmark-gfm/libcmark-gfm/src/utf8.h new file mode 120000 index 0000000..6664ed1 --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/utf8.h @@ -0,0 +1 @@ +../../../upstream/src/utf8.h \ No newline at end of file diff --git a/libcmark-gfm/libcmark-gfm/src/xml.c b/libcmark-gfm/libcmark-gfm/src/xml.c new file mode 120000 index 0000000..0dcabde --- /dev/null +++ b/libcmark-gfm/libcmark-gfm/src/xml.c @@ -0,0 +1 @@ +../../../upstream/src/xml.c \ No newline at end of file -- cgit v1.1