hoedown/hoedown

HTML Renderer Output Issues

Closed this issue · 3 comments

Hello!

I'm trying to use hoedown from within a Swift, so added the following:

let markdown = "[some link](http://raywenderlich.com)\n\n**Some Bold Text**\n\n1. Item 1\n2. A second item\n3. Number 3"

let renderer = hoedown_html_renderer_new(hoedown_html_flags(0), 1)
let document = hoedown_document_new(renderer, hoedown_extensions(0), 1)

var ib = hoedown_buffer_new(1024)
var ob = hoedown_buffer_new(64)

hoedown_buffer_put(ib, markdown, markdown.characters.count)
hoedown_document_render(document, ob, ib.memory.data, ib.memory.size)

let output = hoedown_buffer_cstr(ob)
print(String.fromCString(output))

which gives the following output:

<p><a href="http://raywenderlich.com"></a></p>

<p>**Some Bold Text**</p>

<ol>
<li></li>
<li></li>
<li></li>
</ol>

As I'm sure you can tell, this isn't the expected output. So, I wondered if there was something funky going on with Swift, and jumped over to Obj-C to test things out.

Using the following Obj-C:

NSString *markdown = @"[some link](http://raywenderlich.com)\n\n**Some Bold Text**\n\n1. Item 1\n2. A second item\n3. Number 3";

hoedown_renderer *renderer = hoedown_html_renderer_new(0, 1);
hoedown_document *document = hoedown_document_new(renderer, 0, 1);

hoedown_buffer *ib = hoedown_buffer_new(1024);
hoedown_buffer *ob = hoedown_buffer_new(64);

hoedown_buffer_put(ib, (const unsigned char*)markdown.UTF8String, markdown.length);
hoedown_document_render(document, ob, ib->data, ib->size);

NSString *output = [NSString stringWithUTF8String:hoedown_buffer_cstr(ob)];
NSLog(output);

I get the following output:

<p><a href="http://raywenderlich.com"></a></p>

<p>**Some Bold Text**</p>

<ol>
<li></li>
<li></li>
<li></li>
</ol>

Again, not quite what I expected. In one final attempt to try and figure things out, I dropped down to C. Running the following:

const unsigned char markdown[] = "[some link](http://raywenderlich.com)\n\n**Some Bold Text**\n\n1. Item 1\n2. A second item\n3. Number 3";

hoedown_renderer *renderer = hoedown_html_renderer_new(0, 1);
hoedown_document *document = hoedown_document_new(renderer, 0, 1);

hoedown_buffer *ib = hoedown_buffer_new(1024);
hoedown_buffer *ob = hoedown_buffer_new(64);

hoedown_buffer_put(ib, markdown, sizeof(markdown));
hoedown_document_render(document, ob, ib->data, ib->size);

const char *output = hoedown_buffer_cstr(ob);
printf(output);

provides the following output:

<p><a href="http://raywenderlich.com"></a></p>

<p>**Some Bold Text**</p>

<ol>
<li></li>
<li></li>
<li></li>
</ol>

So now I'm at a bit of a loss, and have been banging my head against a wall for some time now. Is there something that I'm doing wrong here? Or could there be an issue with the html renderer?

Any help would be greatly appreciated.

Thanks. 😄

Using midnight_dynamite I tried the following code:

proc test_issue() =
  var md_params = init_md_params()
  defer: md_params.free
  echo md_params.render("""[some link](http://raywenderlich.com)

**Some Bold Text**

1. Item 1
2. A second item
3. Number 3""")

It did output the expected html:

<p><a href="http://raywenderlich.com">some link</a></p>

<p><strong>Some Bold Text</strong></p>

<ol>
<li>Item 1</li>
<li>A second item</li>
<li>Number 3</li>
</ol>

The only different thing I'm doing is using the following default extension flags, {md_ext_autolink, md_ext_highlight, md_ext_no_intra_emphasis, md_ext_fenced_code, md_ext_strikethrough} and not using an input hoedown_buffer but rather passing the C string directly to hoedown_document_render as input. Does changing any of those improve the output for you?

If not, and you have a repo or gist with the swift project, I can take a look at it.

No worries, you were just using a max_nesting (the last parameter to hoedown_document_new) of 1. max_nesting is a security measure, if you only allow your markdown to nest one time, then the list items won't even get their content parsed because the maximum nesting has been exceeded.

You should simply set a higher limit like 16, which is what is used by the CLI, the examples and probably midnight_dynamite as well:

let document = hoedown_document_new(renderer, hoedown_extensions(0), 16)

@jmendeth Superb, that fixed the issue! 👍

Greatly appreciate your response, and thanks to @gradha too.