diff --git a/.rubocop.yml b/.rubocop.yml index 53a2400..75704dd 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -5,12 +5,3 @@ AllCops: TargetRubyVersion: 2.3 Exclude: - vendor/**/* - -Metrics/LineLength: - Exclude: - - spec/**/* - - jekyll-mentions.gemspec - -Metrics/BlockLength: - Exclude: - - spec/**/* diff --git a/jekyll-mentions.gemspec b/jekyll-mentions.gemspec index 1357d81..531abe8 100644 --- a/jekyll-mentions.gemspec +++ b/jekyll-mentions.gemspec @@ -21,5 +21,5 @@ Gem::Specification.new do |s| s.add_development_dependency "rake", "~> 12.0" s.add_development_dependency "rspec", "~> 3.0" - s.add_development_dependency "rubocop", "~> 0.57.2" + s.add_development_dependency "rubocop-jekyll", "~> 0.3" end diff --git a/lib/jekyll-mentions.rb b/lib/jekyll-mentions.rb index b8016d4..22553d8 100644 --- a/lib/jekyll-mentions.rb +++ b/lib/jekyll-mentions.rb @@ -8,7 +8,7 @@ class Mentions GITHUB_DOT_COM = "https://github.com" BODY_START_TAG = "\s*! + OPENING_BODY_TAG_REGEX = %r!\s*!.freeze InvalidJekyllMentionConfig = Class.new(Jekyll::Errors::FatalException) @@ -17,6 +17,7 @@ class << self def mentionify(doc) content = doc.output return unless content.include?("@") + src = mention_base(doc.site.config) if content.include? BODY_START_TAG head, opener, tail = content.partition(OPENING_BODY_TAG_REGEX) @@ -28,6 +29,7 @@ def mentionify(doc) doc.output = String.new(head) << opener << processed_markup << rest.join else return unless content =~ filter_regex + doc.output = filter_with_mention(src).call(content)[:output].to_s end end @@ -93,13 +95,14 @@ def mentionable?(doc) private def filter_regex - @filter_regex ||= begin - Regexp.new( - HTML::Pipeline::MentionFilter::MentionPatterns[mention_username_pattern] - ) - rescue TypeError - %r!@\w+! - end + @filter_regex ||= + begin + Regexp.new( + HTML::Pipeline::MentionFilter::MentionPatterns[mention_username_pattern] + ) + rescue TypeError + %r!@\w+! + end end def default_mention_base