Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow any valid blocks to be rendered, skipping invalid blocks #37

Closed
wants to merge 1 commit into from

Conversation

JoeWoodward
Copy link

Currently the logic renders nothing if any single block is invalid. I've changed this to render any blocks that are valid instead. Ideally the gem should allow configuring a logger so we can log when an invalid block is detected.

@xiaohui-zhangxh
Copy link
Owner

Hi JoeWoodward, thanks for pointing out this issue, I have put this logic to new version 0.4.0 2fed69f , now you can write your own invalid block renderer to handle this:

class MyInvalidBlockRender do
  def initialize(raw)
    @raw = raw
    # can record/log invalid block from here:
    # Sentry.capture_message "invalid block: #{raw}"
  end

  def valid?
    false
  end

  def render
    '<div>invalid block</div>'
  end

  def plain; end
  def output; {} end
end

doc = EditorJs::Document.new(editor_js_output, invalid_block_renderer: MyInvalidBlockRender)
doc.render  # [String] render HTML for display
doc.plain   # [String] render text for full-text searching
doc.output  # [Hash] return sanitized data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants