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

See rubular.com/r/zM9MJl8SOC

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