class HTML::Pipeline::IssueReferenceFilter
identify github issue references using a customizable filter pattern
Constants
- IGNORE_PARENTS
Don't look for mentions in text nodes that are children of these elements
- REPOSITORY_NAME
- SHORT_PATTERN
Match references of the form:
-
#123
-
codetree/feedback#123
-
GH-123
-
- URL_PATTERN
Match references of the form:
Public Class Methods
issue_references_in(text) { |match, repository, number| ... }
click to toggle source
# File lib/html/pipeline/issue_reference_filter.rb, line 54 def self.issue_references_in(text) text.gsub SHORT_PATTERN do |match| repository = Regexp.last_match(2) number = Regexp.last_match(3) yield match, repository, number end end
Public Instance Methods
call()
click to toggle source
# File lib/html/pipeline/issue_reference_filter.rb, line 66 def call doc.search('.//text()').each do |node| content = node.to_html next if has_ancestor?(node, IGNORE_PARENTS) html = issue_reference_filter(content, base_url, default_repo) next if html == content node.replace(html) end doc end
default_repo()
click to toggle source
# File lib/html/pipeline/issue_reference_filter.rb, line 62 def default_repo context[:repository] end
issue_reference_filter(text, _base_url = '/', default_repo = nil)
click to toggle source
# File lib/html/pipeline/issue_reference_filter.rb, line 80 def issue_reference_filter(text, _base_url = '/', default_repo = nil) self.class.issue_references_in(text) do |match, referenced_repo, number| repo = referenced_repo || default_repo repo ? link_to_issue(repo, number, default_repo) : match end end
link_to_issue(repo, number, default_repo)
click to toggle source
# File lib/html/pipeline/issue_reference_filter.rb, line 87 def link_to_issue(repo, number, default_repo) content = "##{number}" content = "#{repo}#{content}" if repo != default_repo url = base_url.dup url << '/' unless url =~ %r{[/~]\z} url << "#{repo}/issues/#{number}" "<a href='#{url}' class='issue-reference'>#{content}</a>" end