Class: HTML::Pipeline::LinkifyGitHubFilter

Inherits:
TextFilter
  • Object
show all
Defined in:
lib/html/pipeline/linkify_github.rb

Overview

Filter that converts GitHub’s url into friendly markdown.

For example:

https://github.com/rails/rails/pull/21862
https://github.com/rails/rails/issues/21843
https://github.com/rails/rails/commit/67597e1719ec6af7e22964603cc77aa5b085a864

=>

[rails/rails#21862](https://github.com/rails/rails/pull/21862)
[rails/rails#21843](https://github.com/rails/rails/issues/21843)
[rails/rails@`67597e`](https://github.com/rails/rails/commit/67597e1719ec6af7e22964603cc77aa5b085a864)

This filter does not write any additional information to the context hash.

Constant Summary collapse

GITHUB_URL =
"github.com".freeze
PULL =
"/pull/".freeze
ISSUES =
"/issues/".freeze
COMMIT =
"/commit/".freeze
PULL_REQUEST_REGEXP =
%r{https?://(www.)?github.com/(?<owner>.+)/(?<repo>.+)/pull/(?<number>\d+)/?}.freeze
ISSUES_REGEXP =
%r{https?://(www.)?github.com/(?<owner>.+)/(?<repo>.+)/issues/(?<number>\d+)/?}.freeze
COMMIT_REGEXP =
%r{https?://(www.)?github.com/(?<owner>.+)/(?<repo>.+)/commit/(?<number>\w+)/?}.freeze

Instance Method Summary collapse

Instance Method Details

#callObject

Convert GitHub urls into friendly markdown.



31
32
33
34
35
36
37
38
39
# File 'lib/html/pipeline/linkify_github.rb', line 31

def call
  return @text unless @text.include?(GITHUB_URL)

  replace_pull_request_links if has_pull_request_link?
  replace_issue_links if has_issue_link?
  replace_commit_links if has_commit_link?

  @text
end