lib/awesome_bot/links.rb in awesome_bot-1.17.2 vs lib/awesome_bot/links.rb in awesome_bot-1.18.0

- old
+ new

@@ -1,7 +1,16 @@ # Get and filter links module AwesomeBot + # This matches, from left to right: + # a literal [ + # the link title - i.e. anything up to the next closing bracket + # a literal ] + # a literal ( + # the link destination (optionally enclosed in a single pair of angle brackets) + # a literal ) + MARKDOWN_LINK_REGEX = /\[ [^\]]+ \] \( <? ([^)<>]+) >? \)/x + class << self def links_filter(list) list.reject { |x| x.length < 9 } .map do |x| x.gsub(',','%2c').gsub(/'.*/, '').gsub(/,.*/, '') @@ -43,12 +52,13 @@ rel = get_relative_links content, url_base return rel + ext end def get_relative_links(content, base) - links = content.scan /\].*?\)/ + links = [] + content.scan(MARKDOWN_LINK_REGEX) { |groups| links << groups.first } + links.reject { |x| x.include?('http') || x.include?('#') } - .map { |x| x.sub '](', ''} .map { |x| x =~ /\S/ ? x.match(/^\S*/) : x } .map { |x| "#{base}#{x}"} end end # class end