module Hoe::Markdown::Util

Constants

GITHUB_ISSUE_MENTION_REGEX
GITHUB_USER_REGEX

see github.com/shinnn/github-username-regex

GIT_SHA1_REGEX

Public Class Methods

linkify_git_commits(markdown) click to toggle source
# File lib/hoe/markdown/util.rb, line 68
def self.linkify_git_commits(markdown)
  markdown.gsub(GITHUB_SHA1_REGEX, "[`\\1`](https://)") # TODO YOU WERE HERE
end
linkify_github_issues(markdown, issues_uri) click to toggle source
# File lib/hoe/markdown/util.rb, line 32
def self.linkify_github_issues(markdown, issues_uri)
  if issues_uri.nil? || issues_uri.empty?
    raise "#{__FILE__}:#{__method__}: URI for bugs cannot be empty\n"
  end

  issue_uri_regex = %r{
    # not already in a markdown hyperlink
    (?<!\]\()

    #{issues_uri}/([[:digit:]]+)

    # don't truncate the issue number to meet the previous negative lookahead
    (?![[[:digit:]]])
  }x

  pull_uri = issues_uri.gsub("issues", "pull")
  pull_uri_regex = %r{
    # not already in a markdown hyperlink
    (?<!\]\()

    #{pull_uri}/([[:digit:]]+)

    # don't truncate the issue number to meet the previous negative lookahead
    (?![[[:digit:]]])
  }x

  markdown
    .gsub(GITHUB_ISSUE_MENTION_REGEX, "[#\\1](#{issues_uri}/\\1)")
    .gsub(issue_uri_regex, "[#\\1](#{issues_uri}/\\1)")
    .gsub(pull_uri_regex, "[#\\1](#{pull_uri}/\\1)")
end
linkify_github_usernames(markdown) click to toggle source
# File lib/hoe/markdown/util.rb, line 64
def self.linkify_github_usernames(markdown)
  markdown.gsub(GITHUB_USER_REGEX, "[@\\1](https://github.com/\\1)")
end