Sha256: e658d86452b20ff3ec8de8043a14a017b3190adffa5669cf7ad412aa0688b6f3

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

require 'cgi'

module ClWiki
  class FormatPreBlockquote < ClWiki::CustomFormatter
    def self.match_re
      %r{\[p\].*?\[/p\]}mi
    end

    # Only matched text is passed in, and whatever is returned is used (i.e. you
    # don't have to use gsub! you're not modifying the page's) ivar of content.
    def self.format_content(content, page)
      content = CGI.escapeHTML(content)

      # Remove 0 or 1 newline at the front of the block, to remove the
      # almost-always-there first newline and prevent a gap always at the top of
      # every block, but allow additional newlines if the page really wants
      # newlines at the top of the block
      content.gsub!(/\[p\]\n?/i, '<blockquote><pre>')

      # Remove 0 to 2 newlines after the block, to remove unnecessary blank
      # lines in most cases, but keep 3 or more, to allow the page to
      # intentionally put some blank space after something if necessary.
      content.gsub!(%r{\[/p\]\n{0,2}}i, '</pre></blockquote>')
    end
  end
end

ClWiki::CustomFormatters.instance.register(ClWiki::FormatPreBlockquote)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
clwiki-3.3.2 lib/cl_wiki/format_pre_blockquote.rb