pax_global_header 0000666 0000000 0000000 00000000064 13630145505 0014514 g ustar 00root root 0000000 0000000 52 comment=96efdd10cb0f629d05717c3fe6ee6dde6ed15aa7 jekyll-mentions-1.6.0/ 0000775 0000000 0000000 00000000000 13630145505 0014644 5 ustar 00root root 0000000 0000000 jekyll-mentions-1.6.0/.gitignore 0000664 0000000 0000000 00000000146 13630145505 0016635 0 ustar 00root root 0000000 0000000 .bundle /*.gem /tmp /vendor/gems bin Gemfile.lock pkg/*.gem spec/fixtures/.jekyll-cache vendor/bundle jekyll-mentions-1.6.0/.rspec 0000664 0000000 0000000 00000000055 13630145505 0015761 0 ustar 00root root 0000000 0000000 --color --require spec_helper --order random jekyll-mentions-1.6.0/.rubocop.yml 0000664 0000000 0000000 00000000343 13630145505 0017116 0 ustar 00root root 0000000 0000000 require: rubocop-jekyll inherit_gem: rubocop-jekyll: .rubocop.yml AllCops: TargetRubyVersion: 2.4 Exclude: - vendor/**/* Metrics/BlockLength: Exclude: - spec/**/* Metrics/LineLength: Exclude: - spec/**/* jekyll-mentions-1.6.0/.travis.yml 0000664 0000000 0000000 00000001267 13630145505 0016763 0 ustar 00root root 0000000 0000000 language: ruby cache: bundler rvm: - &latest_ruby 2.6 - 2.4 before_install: - gem update --system - gem install bundler script: script/cibuild env: global: - NOKOGIRI_USE_SYSTEM_LIBRARIES=true matrix: - JEKYLL_VERSION="~> 3.8" matrix: include: # GitHub Pages - rvm: 2.5.3 env: - JEKYLL_VERSION="~> 3.8.5" - GITHUB_PAGES=1 # Only set on one build in matrix - rvm: *latest_ruby env: JEKYLL_VERSION="~> 4.0" notifications: irc: on_success: change on_failure: change channels: - irc.freenode.org#jekyll template: - '%{repository}#%{build_number} (%{branch}) %{message} %{build_url}' email: on_success: never on_failure: never jekyll-mentions-1.6.0/Gemfile 0000664 0000000 0000000 00000000203 13630145505 0016132 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true source "https://rubygems.org" gemspec gem "jekyll", ENV["JEKYLL_VERSION"] if ENV["JEKYLL_VERSION"] jekyll-mentions-1.6.0/History.markdown 0000664 0000000 0000000 00000004771 13630145505 0020062 0 ustar 00root root 0000000 0000000 ## 1.6.0 / 2020-03-05 ### Minor Enhancements * Allow configuring base URL in page front matter (#72) * Incorporate document data only if it has override (#73) ### Development Fixes * ci: test against Jekyll 4.0 * style: target Ruby 2.4 * ignore vendor/bundle ### Bug Fixes * Support handling body tag across multiple lines (#70) ## 1.5.1 / 2019-03-23 ### Bug Fixes * Re-introduce Ruby 2.3 support and test with Jekyll 3.7 and beyond (#69) ## 1.5.0 / 2019-03-22 ### Development Fixes * Allow Jekyll v4 (still alpha) * Drop support for Ruby 2.3 * chore(deps): rubocop-jekyll 0.3 (#65) * Reintroduce style checks (#67) ## 1.4.1 / 2018-08-08 ### Bug Fixes * Do not match the body tag eagerly (#64) ## 1.4.0 / 2018-05-02 ### Minor Enhancements * Drop support for Ruby 2.2.x (#61) * Relax version constraint on ActiveSupport (#60) * Bump Rubocop to 0.55 (#61) * Drop dependency on ActiveSupport (#63) * Parse only content necessary to mentionify doc (#59) ## 1.3.0 / 2018-03-14 ### Development Fixes * Add rubocop to script/cibuild (#44) * Rubocop: autocorrect (#49) * Define path with __dir__ (#46) * Test against latest Rubies (#53) * Use a version constant (#54) * Use default Rake tasks and scripts (#55) ### Documentation * Use `plugins` key by default (#50) ### Minor Enhancements * Allow underscores in usernames (#57) * Mentionify only relevant docs or pages (#56) ## 1.2.0 / 2016-08-29 ### Development Fixes * Inherit Jekyll's rubocop config for consistency (#38) ### Minor Enhancements * Add support for building the base URL from ENV on Enterprise (#40) ## 1.1.3 / 2016-06-28 * Allow uppercase chars in username (#33) ## 1.1.2 / 2016-03-19 * Don't strip html, body, and head tags (#29) ## 1.1.1 / 2016-03-09 * Handle subclassing of Jekyll::Page (#28) ## 1.1.0 / 2016-03-08 * jekyll-mentions as a hook: better guarding against accidents (#27) ## 1.0.1 / 2016-02-16 * Don't double-mention in Jekyll > 3.0.0 (#25) ## 1.0.0 / 2015-10-30 * Jekyll 3.x support (#22) * HTML Pipeline 2.2 (#22) ## 0.2.1 / 2014-12-18 * Fix for undefined variable error (#20) ## 0.2.0 / 2014-12-01 * Mentionify collection documents. (#19) ## 0.1.3 / 2014-07-30 * Allow mention from a different base url than https://github.com (#14) ## 0.1.2 / 2014-07-10 * URLs ending in '/' also indicate and HTML page. (#13) ## 0.1.1 / 2014-06-23 * Only mentionify the page if it's an HTML page (#11) ## 0.1.0 / 2014-05-06 * Support for Jekyll 2.0 (#8) jekyll-mentions-1.6.0/LICENSE 0000664 0000000 0000000 00000002144 13630145505 0015652 0 ustar 00root root 0000000 0000000 The MIT License (MIT) Copyright (c) 2014-present GitHub, Inc. and the jekyll-mentions contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. jekyll-mentions-1.6.0/README.md 0000664 0000000 0000000 00000004611 13630145505 0016125 0 ustar 00root root 0000000 0000000 # Jekyll Mentions @mentionable support for your Jekyll site [](http://badge.fury.io/rb/jekyll-mentions) [](https://travis-ci.org/jekyll/jekyll-mentions) ## Usage Add the following to your site's `Gemfile` ``` gem 'jekyll-mentions' ``` And add the following to your site's `_config.yml` ```yml plugins: - jekyll-mentions ``` Note: if `jekyll --version` is less than `3.5` use: ```yml gems: - jekyll-mentions ``` In any page or post, use @mentions as you would normally, e.g. ```markdown Hey @benbalter, what do you think of this? ``` **Note**: Jekyll Mentions simply turns the @mentions into links, it does not notify the mentioned user. ## Configuration ### Within the `_config.yml` Have your own social network? No problem. We allow you to configure the base URL of all the mentions. To change it, add the following to your Jekyll configuration: ```yaml jekyll-mentions: base_url: https://twitter.com ``` If you're lazy like me, you can use this shorthand: ```yaml jekyll-mentions: https://twitter.com ``` An example of Twitter mentions using jekyll-mentions: ```yaml plugins: - jekyll-mentions jekyll-mentions: base_url: https://twitter.com ``` Et voilĂ ! Your mentions will now use that base URL instead of the default of `https://github.com`. ### Within a page's front matter Now do you want to override the base URL for just a single page/post? No problem. Just set the base URL for that specific page in the front matter: ```yaml jekyll-mentions: base_url: https://facebook.com ``` You also can use this shorthand: ```yaml jekyll-mentions: https://facebook.com ``` Now, every single mentions in the site will use the base URL defined in the `_config.yml`, _except_ in the file where you set the base URL to be something different. If you wish to change the base URL for a single mention, but not every mentions in that file, then you'll have to link to the URL the old-fashioned way: ```markdown [@benbalter](https://instagram.com/benbalter) ``` Now, let's say you have a single file where you _don't_ want your mentions to become mentionable, AKA you want that to stay plain text. You can do that by specifying `false` in the front matter of that file: ```yaml jekyll-mentions: false ``` Now that page/post's mentions will not link to the profiles. jekyll-mentions-1.6.0/Rakefile 0000664 0000000 0000000 00000000224 13630145505 0016307 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true require "bundler/gem_tasks" require "rspec/core/rake_task" RSpec::Core::RakeTask.new(:spec) task :default => :spec jekyll-mentions-1.6.0/jekyll-mentions.gemspec 0000664 0000000 0000000 00000001474 13630145505 0021343 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true $LOAD_PATH.unshift File.expand_path("lib", __dir__) require("jekyll-mentions/version") Gem::Specification.new do |s| s.name = "jekyll-mentions" s.summary = "@mention support for your Jekyll site" s.version = JekyllMentions::VERSION s.authors = ["GitHub, Inc."] s.email = "support@github.com" s.homepage = "https://github.com/jekyll/jekyll-mentions" s.licenses = ["MIT"] s.files = ["lib/jekyll-mentions.rb"] s.required_ruby_version = ">= 2.4.0" s.add_dependency "html-pipeline", "~> 2.3" s.add_dependency "jekyll", ">= 3.7", "< 5.0" s.add_development_dependency "bundler" s.add_development_dependency "rake", "~> 12.0" s.add_development_dependency "rspec", "~> 3.0" s.add_development_dependency "rubocop-jekyll", "~> 0.4" end jekyll-mentions-1.6.0/lib/ 0000775 0000000 0000000 00000000000 13630145505 0015412 5 ustar 00root root 0000000 0000000 jekyll-mentions-1.6.0/lib/jekyll-mentions.rb 0000664 0000000 0000000 00000010050 13630145505 0021057 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true require "jekyll" require "html/pipeline" module Jekyll class Mentions GITHUB_DOT_COM = "https://github.com" BODY_START_TAG = "
\s*!m.freeze InvalidJekyllMentionConfig = Class.new(Jekyll::Errors::FatalException) class << self # rubocop:disable Metrics/AbcSize def mentionify(doc) content = doc.output return unless content.include?("@") config = doc.site.config config = config.merge(doc.data) if doc.data.key?("jekyll-mentions") src = mention_base(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&.match?(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&.match?(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 either the site config or a document's # front matter 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 effective configuration that includes configurations for mentions. # # 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 mentionable. # # 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?("/"))) && (doc.data["jekyll-mentions"] != false) 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.6.0/lib/jekyll-mentions/ 0000775 0000000 0000000 00000000000 13630145505 0020536 5 ustar 00root root 0000000 0000000 jekyll-mentions-1.6.0/lib/jekyll-mentions/version.rb 0000664 0000000 0000000 00000000115 13630145505 0022545 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true module JekyllMentions VERSION = "1.6.0" end jekyll-mentions-1.6.0/script/ 0000775 0000000 0000000 00000000000 13630145505 0016150 5 ustar 00root root 0000000 0000000 jekyll-mentions-1.6.0/script/bootstrap 0000775 0000000 0000000 00000000042 13630145505 0020107 0 ustar 00root root 0000000 0000000 #! /bin/sh bundle install -j8 $@ jekyll-mentions-1.6.0/script/cibuild 0000775 0000000 0000000 00000000102 13630145505 0017502 0 ustar 00root root 0000000 0000000 #! /bin/sh set -e script/test script/fmt bundle exec rake build jekyll-mentions-1.6.0/script/fmt 0000775 0000000 0000000 00000000340 13630145505 0016661 0 ustar 00root root 0000000 0000000 #!/bin/bash set -e echo "Rubocop $(bundle exec rubocop --version)" bundle exec rubocop -D -E $@ success=$? if ((success != 0)); then echo -e "\nTry running \`script/fmt -a\` to automatically fix errors" fi exit $success jekyll-mentions-1.6.0/script/release 0000775 0000000 0000000 00000000125 13630145505 0017514 0 ustar 00root root 0000000 0000000 #!/bin/sh # Tag and push a release. set -e script/cibuild bundle exec rake release jekyll-mentions-1.6.0/script/test 0000775 0000000 0000000 00000000054 13630145505 0017054 0 ustar 00root root 0000000 0000000 #!/bin/bash set -ex bundle exec rspec "$@" jekyll-mentions-1.6.0/spec/ 0000775 0000000 0000000 00000000000 13630145505 0015576 5 ustar 00root root 0000000 0000000 jekyll-mentions-1.6.0/spec/fixtures/ 0000775 0000000 0000000 00000000000 13630145505 0017447 5 ustar 00root root 0000000 0000000 jekyll-mentions-1.6.0/spec/fixtures/_config.yml 0000664 0000000 0000000 00000000046 13630145505 0021576 0 ustar 00root root 0000000 0000000 collections: docs: output: true jekyll-mentions-1.6.0/spec/fixtures/_docs/ 0000775 0000000 0000000 00000000000 13630145505 0020536 5 ustar 00root root 0000000 0000000 jekyll-mentions-1.6.0/spec/fixtures/_docs/dont_touch_me.txt 0000664 0000000 0000000 00000000062 13630145505 0024124 0 ustar 00root root 0000000 0000000 --- title: Don't Touch Me --- test @TestUser test jekyll-mentions-1.6.0/spec/fixtures/_docs/file.md 0000664 0000000 0000000 00000000035 13630145505 0021775 0 ustar 00root root 0000000 0000000 --- --- test @TestUser test jekyll-mentions-1.6.0/spec/fixtures/_docs/special_characters.md 0000664 0000000 0000000 00000000230 13630145505 0024672 0 ustar 00root root 0000000 0000000 --- title: Unconventional Names --- Howdy @-pardner! @haTTric- sez you are quite the @task-master.. Checkout @Casino_Royale The Original @_Bat_Cave jekyll-mentions-1.6.0/spec/fixtures/_docs/with_liquid.md 0000664 0000000 0000000 00000000135 13630145505 0023401 0 ustar 00root root 0000000 0000000 --- title: With Liquid --- test @TestUser test {{ page.path }} jekyll-mentions-1.6.0/spec/fixtures/_layouts/ 0000775 0000000 0000000 00000000000 13630145505 0021306 5 ustar 00root root 0000000 0000000 jekyll-mentions-1.6.0/spec/fixtures/_layouts/default.html 0000664 0000000 0000000 00000000453 13630145505 0023622 0 ustar 00root root 0000000 0000000