Sha256: 14f3051a6709c44beb06441bb484117ad1e039111de68cdd0a9df772888dbf0c

Contents?: true

Size: 1.08 KB

Versions: 21

Compression:

Stored size: 1.08 KB

Contents

# ~*~ encoding: utf-8 ~*~

class Gollum::Filter::Render < Gollum::Filter
  def extract(data)
    begin
      working_dir = Pathname.new(@markup.wiki.path).join(@markup.dir)
      working_dir = working_dir.exist? ? working_dir.to_s : '.'
      Dir.chdir(working_dir) do
        data = GitHub::Markup.render_s(@markup.format, data)
      end
      if data.nil?
        raise "There was an error converting #{@markup.name} to HTML."
      end
    rescue Object => e
      data = html_error("Failed to render page: #{e.message}")
    end

    data
  end

  def process(data)
    data = add_editable_header_class(data)
    data
  end

  private

  def add_editable_header_class(data)
    doc = Nokogiri::HTML::DocumentFragment.parse(data)
    doc.css('h1,h2,h3,h4,h5,h6').each_with_index do |header, i|
      next if header.content.empty?
      next if header.inner_html.match(PLACEHOLDER_PATTERN)
      klass = header['class']
      if klass
        header['class'] = klass << ' editable'
      else
        header['class'] = 'editable'
      end
    end
    doc.to_xml(@markup.class.to_xml_opts)
  end

end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
gollum-lib-5.1.3-java lib/gollum-lib/filter/render.rb
gollum-lib-5.1.3 lib/gollum-lib/filter/render.rb
gollum-lib-5.1.2-java lib/gollum-lib/filter/render.rb
gollum-lib-5.1.2 lib/gollum-lib/filter/render.rb
gollum-lib-5.1.1-java lib/gollum-lib/filter/render.rb
gollum-lib-5.1.1 lib/gollum-lib/filter/render.rb
gollum-lib-5.1-java lib/gollum-lib/filter/render.rb
gollum-lib-5.1 lib/gollum-lib/filter/render.rb
gollum-lib-5.0.6-java lib/gollum-lib/filter/render.rb
gollum-lib-5.0.6 lib/gollum-lib/filter/render.rb
gollum-lib-5.0.5-java lib/gollum-lib/filter/render.rb
gollum-lib-5.0.5 lib/gollum-lib/filter/render.rb
gollum-lib-5.0.4-java lib/gollum-lib/filter/render.rb
gollum-lib-5.0.4 lib/gollum-lib/filter/render.rb
gollum-lib-5.0.3-java lib/gollum-lib/filter/render.rb
gollum-lib-5.0.3 lib/gollum-lib/filter/render.rb
gollum-lib-5.0.2-java lib/gollum-lib/filter/render.rb
gollum-lib-5.0.2 lib/gollum-lib/filter/render.rb
gollum-lib-5.0.1-java lib/gollum-lib/filter/render.rb
gollum-lib-5.0.1 lib/gollum-lib/filter/render.rb