Class: Markbridge::Renderers::Discourse::IdentityEscaper

Inherits:
Object
  • Object
show all
Defined in:
lib/markbridge/renderers/discourse/identity_escaper.rb

Overview

Pass-through escaper. Returns its input unchanged.

Useful for migration paths where the source content is already valid Markdown (or otherwise trusted not to need escaping) and should reach the postprocessor verbatim. For partial passthrough (e.g. allow lists but still escape headings), see MarkdownEscaper#initialize‘s allow: kwarg.

Examples:

Per-call use via the renderer factory

renderer = Markbridge.discourse_renderer(escape: false)
Markbridge.bbcode_to_markdown(post.body, renderer:)

Instance Method Summary collapse

Instance Method Details

#escape(text, in_link_label: false) ⇒ String

Returns text with ] optionally escaped, or “” when text is nil.

Parameters:

  • text (String, nil)
  • in_link_label (Boolean) (defaults to: false)

    when true, escape ] so the text can be spliced into a Markdown link label [text](url) without terminating it early. Mirrors MarkdownEscaper#escape‘s in_link_label:. This isn’t a stylistic escape — without it, trusted-Markdown content containing ] inside a Url/Email ancestor produces a broken link.

Returns:

  • (String)

    text with ] optionally escaped, or “” when text is nil



28
29
30
31
32
33
# File 'lib/markbridge/renderers/discourse/identity_escaper.rb', line 28

def escape(text, in_link_label: false)
  return "" if text.nil?
  return text.gsub("]", "\\]") if in_link_label && text.include?("]")

  text
end