Sha256: 313fa8a1497e1669375f055b15a0b38bd2de2cf5cdcfbc623721c319692aed8e

Contents?: true

Size: 1.22 KB

Versions: 2

Compression:

Stored size: 1.22 KB

Contents

require 'html-renderer'

#
# Strips out everything but the plain text.
#
class HTMLRenderer::Text < HTMLRenderer::Base

  # Methods where the first argument is the text content
  [
    # block-level calls
    :block_code, :block_quote,
    :block_html, :list, :list_item,

    # span-level calls
    :autolink, :codespan, :double_emphasis,
    :emphasis, :underline, :raw_html,
    :triple_emphasis, :strikethrough,
    :superscript, :highlight,

    # footnotes
    :footnotes, :footnote_def, :footnote_ref,

    # low level rendering
    :entity, :normal_text
  ].each do |method|
    define_method method do |*args|
      args.first
    end
  end

  # Other methods where we don't return only a specific argument
  def link(link, title, content)
    "#{content} (#{link})"
  end

  def image(link, title, content)
    content &&= content + " "
    "#{content}#{link}"
  end

  def div(text)
    text + "\n"
  end

  def paragraph(text)
    div(text) + "\n"
  end

  def separator
    "______________________\n\n"
  end

  def header(text, header_level)
    text + "\n"
  end

  def table(header, body)
    "#{header}#{body}"
  end

  def table_row(content)
    content + "\n"
  end

  def table_cell(content, alignment)
    content + "\t"
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
html-renderer-0.1.4 lib/html-renderer/text.rb
html-renderer-0.1.3 lib/html-renderer/text.rb