From 6d16d197353e43b0fc299b8c250bdbff0c581b15 Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Fri, 14 Nov 2014 10:25:12 +0800 Subject: [PATCH 1/4] Special-case comment tag to ignore all its content Fix #143 --- src/html_smartypants.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/html_smartypants.c b/src/html_smartypants.c index bbe4fc50..b0904da7 100644 --- a/src/html_smartypants.c +++ b/src/html_smartypants.c @@ -313,6 +313,16 @@ smartypants_cb__ltag(hoedown_buffer *ob, struct smartypants_data *smrt, uint8_t size_t tag, i = 0; + /* This is a comment. Copy everything verbatim until --> or EOF is seen. */ + if (i + 4 < size && memcmp(text, "", 3) != 0) + i++; + i += 3; + hoedown_buffer_put(ob, text, i + 1); + return i; + } + while (i < size && text[i] != '>') i++; From 9b789d24a52c6ebf4e86f6b7213eb669bfe03a71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Israel=20Pe=C3=B1a?= Date: Fri, 30 Jan 2015 19:02:37 -0800 Subject: [PATCH 2/4] allow the HOEDOWN_EXT_UNDERLINE to work When the `HOEDOWN_EXT_UNDERLINE` extension was enabled, underlined spans would actually be passed verbatim to the output buffer. This was because the active_char was _only_ set when the emphasis, double_emphasis, or triple_emphasis handlers were registered. As a result, no active char was found in the input buffer, so everything was passed through verbatim. This patch fixes this by also registering the `active_char` if the underline handler is registered. I also added a simple regression test. I personally don't use this extension, but I encountered this bug over the course of writing bindings for Rust. --- src/document.c | 2 +- test/Tests/Underline.html | 1 + test/Tests/Underline.text | 1 + test/config.json | 5 +++++ 4 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 test/Tests/Underline.html create mode 100644 test/Tests/Underline.text diff --git a/src/document.c b/src/document.c index 47f6cf2d..ec781e5f 100644 --- a/src/document.c +++ b/src/document.c @@ -2751,7 +2751,7 @@ hoedown_document_new( memset(doc->active_char, 0x0, 256); - if (doc->md.emphasis || doc->md.double_emphasis || doc->md.triple_emphasis) { + if (doc->md.emphasis || doc->md.double_emphasis || doc->md.triple_emphasis || doc->md.underline) { doc->active_char['*'] = MD_CHAR_EMPHASIS; doc->active_char['_'] = MD_CHAR_EMPHASIS; if (extensions & HOEDOWN_EXT_STRIKETHROUGH) diff --git a/test/Tests/Underline.html b/test/Tests/Underline.html new file mode 100644 index 00000000..c2a8bbad --- /dev/null +++ b/test/Tests/Underline.html @@ -0,0 +1 @@ +

This underline will work.

diff --git a/test/Tests/Underline.text b/test/Tests/Underline.text new file mode 100644 index 00000000..8068546c --- /dev/null +++ b/test/Tests/Underline.text @@ -0,0 +1 @@ +This _underline_ will work. diff --git a/test/config.json b/test/config.json index b6ecb551..d3e170e8 100644 --- a/test/config.json +++ b/test/config.json @@ -101,6 +101,11 @@ "input": "Tests/Math.text", "output": "Tests/Math.html", "flags": ["--math"] + }, + { + "input": "Tests/Underline.text", + "output": "Tests/Underline.html", + "flags": ["--underline"] } ] } From 5cf1ed3fe2f85140bfe84c0f72c26281abf9dbc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Israel=20Pe=C3=B1a?= Date: Fri, 30 Jan 2015 20:43:42 -0800 Subject: [PATCH 3/4] set active_char for footnotes This enables handling footnotes and footnote references without also handling images and links. --- src/document.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/document.c b/src/document.c index 47f6cf2d..ab825b87 100644 --- a/src/document.c +++ b/src/document.c @@ -2766,7 +2766,7 @@ hoedown_document_new( if (doc->md.linebreak) doc->active_char['\n'] = MD_CHAR_LINEBREAK; - if (doc->md.image || doc->md.link) + if (doc->md.image || doc->md.link || doc->md.footnotes || doc->md.footnote_ref) doc->active_char['['] = MD_CHAR_LINK; doc->active_char['<'] = MD_CHAR_LANGLE; From c641dc1436a00aadc1a6aa46508f88dae26c29a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Israel=20Pe=C3=B1a?= Date: Sat, 31 Jan 2015 00:02:28 -0800 Subject: [PATCH 4/4] only set active_char if extension is on --- src/document.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/document.c b/src/document.c index ec781e5f..66ecd3c1 100644 --- a/src/document.c +++ b/src/document.c @@ -2751,7 +2751,11 @@ hoedown_document_new( memset(doc->active_char, 0x0, 256); - if (doc->md.emphasis || doc->md.double_emphasis || doc->md.triple_emphasis || doc->md.underline) { + if (extensions & HOEDOWN_EXT_UNDERLINE && doc->md.underline) { + doc->active_char['_'] = MD_CHAR_EMPHASIS; + } + + if (doc->md.emphasis || doc->md.double_emphasis || doc->md.triple_emphasis) { doc->active_char['*'] = MD_CHAR_EMPHASIS; doc->active_char['_'] = MD_CHAR_EMPHASIS; if (extensions & HOEDOWN_EXT_STRIKETHROUGH)