class GyazzMarkup::Markup

Public Class Methods

new(opts={}) click to toggle source
# File lib/gyazz-markup/markup.rb, line 5
def initialize(opts={})
  @opts = GyazzMarkup::Options.default
  opts.each do |k,v|
    next unless @opts.has_key? k
    next unless v
    @opts[k] = v
  end
end

Public Instance Methods

markup(txt) click to toggle source
# File lib/gyazz-markup/markup.rb, line 18
def markup(txt)
  lines = txt.split(/[\r\n]/).delete_if{|line|
    line.empty?
  }

  lines.map do |line|
    line = markup_url_with_image line
    line = markup_image line
    line = markup_strong line
    line = markup_url_with_title line
    line = markup_url line
    line = markup_wiki_link line
    line = markup_inner_link line
    line = markup_listtag line
  end
end
markup_image(str) click to toggle source
# File lib/gyazz-markup/markup.rb, line 42
def markup_image(str)
  pat = /\[{2,3}(https?:\/\/[^\s]+)\.(png|jpe?g|gif|bmp)\]{2,3}/
  str !~ pat ? str : str.gsub(pat, "<a href=\"#{$1}.#{$2}\"><img src=\"#{$1}.#{$2}\"></a>")
end
markup_listtag(str) click to toggle source
# File lib/gyazz-markup/markup.rb, line 35
def markup_listtag(str)
  return str unless options[:listtag]
  indent_count = str.scan(/^(\s*).*$/)[0][0].size
  prefix = "#{options[:prefix]} " if options[:prefix]
  "<#{options[:listtag]} class=\"gyazz_indent#{indent_count}\">#{prefix}#{str.strip}</#{options[:listtag]}>"
end
markup_strong(str) click to toggle source
# File lib/gyazz-markup/markup.rb, line 62
def markup_strong(str)
  pat = /\[{3}(.+)\]{3}/
  str !~ pat ? str : str.gsub(pat, "<strong>#{$1}</strong>")
end
markup_url(str) click to toggle source
# File lib/gyazz-markup/markup.rb, line 47
def markup_url(str)
  pat = /\[{2}(https?:\/\/[^\s]+)\]{2}/
  str !~ pat ? str : str.gsub(pat, "<a href=\"#{$1}\">#{$1}</a>")
end
markup_url_with_image(str) click to toggle source
# File lib/gyazz-markup/markup.rb, line 72
def markup_url_with_image(str)
  pat = /\[{2}(https?:\/\/[^\s]+)\s(https?:\/\/[^\s]+)\.(png|jpe?g|gif|bmp)\]{2}/
  str !~ pat ? str : str.gsub(pat, "<a href=\"#{$1}\"><img src=\"#{$2}.#{$3}\"></a>")
end
markup_url_with_title(str) click to toggle source
# File lib/gyazz-markup/markup.rb, line 67
def markup_url_with_title(str)
  pat = /\[{2}(https?:\/\/[^\s]+)\s(.+)\]{2}/
  str !~ pat ? str : str.gsub(pat, "<a href=\"#{$1}\">#{$2}</a>")
end
options() click to toggle source
# File lib/gyazz-markup/markup.rb, line 14
def options
  @opts
end