jekyll-mentions-1.5.1/0000755000004100000410000000000013567567211014707 5ustar www-datawww-datajekyll-mentions-1.5.1/lib/0000755000004100000410000000000013567567211015455 5ustar www-datawww-datajekyll-mentions-1.5.1/lib/jekyll-mentions.rb0000644000004100000410000000746313567567211021140 0ustar www-datawww-data# frozen_string_literal: true require "jekyll" require "html/pipeline" module Jekyll class Mentions GITHUB_DOT_COM = "https://github.com" BODY_START_TAG = "\s*!.freeze InvalidJekyllMentionConfig = Class.new(Jekyll::Errors::FatalException) class << self # rubocop:disable Metrics/AbcSize 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) body_content, *rest = tail.partition("") return unless body_content =~ filter_regex processed_markup = filter_with_mention(src).call(body_content)[:output].to_s 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 # rubocop:enable Metrics/AbcSize # Public: Create or fetch the filter for the given {{src}} base URL. # # src - the base URL (e.g. https://github.com) # # Returns an HTML::Pipeline instance for the given base URL. def filter_with_mention(src) filters[src] ||= HTML::Pipeline.new([ HTML::Pipeline::MentionFilter, ], :base_url => src, :username_pattern => mention_username_pattern) end def mention_username_pattern @mention_username_pattern ||= %r![\w][\w-]*! end # Public: Filters hash where the key is the mention base URL. # Effectively a cache. def filters @filters ||= {} end # Public: Calculate the base URL to use for mentioning. # The custom base URL can be defined in the config as # jekyll-mentions.base_url or jekyll-mentions, and must # be a valid URL (i.e. it must include a protocol and valid domain) # It should _not_ have a trailing slash. # # config - the hash-like configuration of the document's site # # Returns a URL to use as the base URL for mentions. # Defaults to the https://github.com. def mention_base(config = {}) mention_config = config["jekyll-mentions"] case mention_config when nil, NilClass default_mention_base when String mention_config.to_s when Hash mention_config.fetch("base_url", default_mention_base) else raise InvalidJekyllMentionConfig, "Your jekyll-mentions config has to either be a string or a hash. " \ "It's a #{mention_config.class} right now." end end # Public: Defines the conditions for a document to be emojiable. # # doc - the Jekyll::Document or Jekyll::Page # # Returns true if the doc is written & is HTML. def mentionable?(doc) (doc.is_a?(Jekyll::Page) || doc.write?) && doc.output_ext == ".html" || (doc.permalink&.end_with?("/")) end private def filter_regex @filter_regex ||= begin Regexp.new( HTML::Pipeline::MentionFilter::MentionPatterns[mention_username_pattern] ) rescue TypeError %r!@\w+! end end def default_mention_base if !ENV["SSL"].to_s.empty? && !ENV["GITHUB_HOSTNAME"].to_s.empty? scheme = ENV["SSL"] == "true" ? "https://" : "http://" "#{scheme}#{ENV["GITHUB_HOSTNAME"].chomp("/")}" else GITHUB_DOT_COM end end end end end Jekyll::Hooks.register [:pages, :documents], :post_render do |doc| Jekyll::Mentions.mentionify(doc) if Jekyll::Mentions.mentionable?(doc) end jekyll-mentions-1.5.1/jekyll-mentions.gemspec0000644000004100000410000000416413567567211021405 0ustar www-datawww-data######################################################### # This file has been automatically generated by gem2tgz # ######################################################### # -*- encoding: utf-8 -*- # stub: jekyll-mentions 1.5.1 ruby lib Gem::Specification.new do |s| s.name = "jekyll-mentions".freeze s.version = "1.5.1" s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version= s.require_paths = ["lib".freeze] s.authors = ["GitHub, Inc.".freeze] s.date = "2019-03-23" s.email = "support@github.com".freeze s.files = ["lib/jekyll-mentions.rb".freeze] s.homepage = "https://github.com/jekyll/jekyll-mentions".freeze s.licenses = ["MIT".freeze] s.required_ruby_version = Gem::Requirement.new(">= 2.3.0".freeze) s.rubygems_version = "2.5.2.1".freeze s.summary = "@mention support for your Jekyll site".freeze if s.respond_to? :specification_version then s.specification_version = 4 if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then s.add_development_dependency(%q.freeze, [">= 0"]) s.add_runtime_dependency(%q.freeze, ["~> 2.3"]) s.add_runtime_dependency(%q.freeze, ["< 5.0", ">= 3.7"]) s.add_development_dependency(%q.freeze, ["~> 12.0"]) s.add_development_dependency(%q.freeze, ["~> 3.0"]) s.add_development_dependency(%q.freeze, ["~> 0.4"]) else s.add_dependency(%q.freeze, [">= 0"]) s.add_dependency(%q.freeze, ["~> 2.3"]) s.add_dependency(%q.freeze, ["< 5.0", ">= 3.7"]) s.add_dependency(%q.freeze, ["~> 12.0"]) s.add_dependency(%q.freeze, ["~> 3.0"]) s.add_dependency(%q.freeze, ["~> 0.4"]) end else s.add_dependency(%q.freeze, [">= 0"]) s.add_dependency(%q.freeze, ["~> 2.3"]) s.add_dependency(%q.freeze, ["< 5.0", ">= 3.7"]) s.add_dependency(%q.freeze, ["~> 12.0"]) s.add_dependency(%q.freeze, ["~> 3.0"]) s.add_dependency(%q.freeze, ["~> 0.4"]) end end