module Amber::Render::Filter::Bracketlink

Constants

linking using double square brackets

Public Class Methods

run(text) { |from, to| ... } click to toggle source
# File lib/amber/render/filter/bracketlink.rb, line 19
def self.run(text, &block)
  text.gsub(BRACKET_LINK_RE) do |m|
    link_text = $~[1].strip
    if link_text =~ /^.+\s*[-=]>\s*.+$/
      # link_text == "from -> to"
      from, to = link_text.split(/\s*[-=]>\s*/)[0..1]
      from = "" unless from.instance_of? String # \ sanity check for
      to   = "" unless from.instance_of? String # / badly formed links
    else
      # link_text == "to" (ie, no link label)
      from = nil
      to = link_text
    end
    yield(from, to)
  end
end