vmg / redcarpet

The safe Markdown parser, reloaded.
MIT License
4.99k stars 527 forks source link

Raising errors in callbacks crashes a Markdown instance #318

Open adamflorin opened 11 years ago

adamflorin commented 11 years ago

Please see reproducible case:

https://gist.github.com/adamflorin/7045640

If I use a Markdown instance repeatedly to render text, and raise an error within a custom formatting callback, eventually Redcarpet (or Sundown?) will crash, bringing down Ruby with it, with the error:

Assertion failed: (md->work_bufs[BUFFER_BLOCK].size == 0), function sd_markdown_render, file markdown.c, line 2544.
Abort trap: 6

In my case, I can just instantiate a new Redcarpet instance each time I render, so this is not pressing for me. But perhaps of interest to you?

KCErb commented 9 years ago

FWIW

I get the same error by essentially this:

Attach my renderer somewhere accessible:

NameSpace.text_renderer = Redcarpet::Markdown.new(TextRenderer, opts)

Spin up an instance, and inside that instance call it again:

text_renderer.render text
  ### Inside TextRenderer
  def block_code(file_path, content)
    # . . .
    NameSpace.text_renderer.render content
    # . . .
  end

I'll use @lynxnathan's suggestion of just making a new instance but thought I'd pass on another use case.

(In my case, I'm not using the fenced code block for code, I'm using it for a figure caption, and I want to be able to put bold text etc in the figure caption, thus I need to render inside as well).

aselder commented 8 years ago

We're seeing this also: RedCarpet 3.3.4, Ruby 2.2.5