Skip to content

Commit 291f20e

Browse files
Merge pull request #3 from digitalmoksha/html-pipeline-2-12-3
Apply changes from html-pipline 2.11.0 to 2.12.3
2 parents 304c8d5 + b46f6be commit 291f20e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+705
-32
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ build
66
debugger_cmds
77
Gemfile.lock
88
vendor
9+
.idea

Gemfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
# frozen_string_literal: true
2+
13
source 'https://rubygems.org'
24

35
gem 'rake'
46

5-
gemspec
7+
gemspec

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![Gem Version](https://badge.fury.io/rb/motion-html-pipeline.svg)](http://badge.fury.io/rb/motion-html-pipeline)
44
[![Build Status](https://travis-ci.org/digitalmoksha/motion-html-pipeline.svg?branch=master)](https://travis-ci.org/digitalmoksha/motion-html-pipeline)
55

6-
_This gem is a port of the [`html-pipeline` gem](https://github.com/jch/html-pipeline) to RubyMotion, for use on iOS and macOS. Currently synced with `html-pipeline` release [`v.2.11.0`](https://github.com/jch/html-pipeline/releases/tag/v2.11.0)_
6+
_This gem is a port of the [`html-pipeline` gem](https://github.com/jch/html-pipeline) to RubyMotion, for use on iOS and macOS. Currently synced with `html-pipeline` release [`v.2.12.3`](https://github.com/jch/html-pipeline/releases/tag/v2.12.3)_
77

88
GitHub HTML processing filters and utilities. This module includes a small
99
framework for defining DOM based content filters and applying them to user
@@ -164,6 +164,7 @@ EmojiPipeline = Pipeline.new [
164164
Several of the standard filters, such as `AutolinkFilter` and `EmojiFilter`, are initially disabled, as they rely on other Ruby gems that don't have RubyMotion equivalents. Please feel free to submit a pull request that enables any of them.
165165

166166
* `MentionFilter` - replace `@user` mentions with links
167+
* `TeamMentionFilter` - replace `@org/team` mentions with links
167168
* `AutolinkFilter` - auto_linking urls in HTML
168169
* `CamoFilter` - replace http image urls with [camo-fied](https://github.com/atmos/camo) https versions
169170
* `EmailReplyFilter` - util filter for working with emails

Rakefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
$:.unshift("/Library/RubyMotion/lib")
24

35
platform = ENV.fetch('platform', 'osx')

app/app_delegate.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class AppDelegate
24
# OS X entry point
35
#------------------------------------------------------------------------------

lib/motion-html-pipeline.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
unless defined?(Motion::Project::Config)
24
raise "This file must be required within a RubyMotion project Rakefile."
35
end
@@ -11,4 +13,4 @@
1113
app.pods do
1214
pod 'HTMLKit', '~> 2.1'
1315
end
14-
end
16+
end

lib/motion-html-pipeline/document_fragment.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# Gives a Nokogiri type of interface, but uses
24
# HTMLKit (https://github.com/iabudiab/HTMLKit)
35
#
@@ -24,4 +26,4 @@ def to_html
2426
end
2527
alias :to_s :to_html
2628
end
27-
end
29+
end

lib/motion-html-pipeline/pipeline.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
# require 'nokogiri'
2-
# require 'active_support/xml_mini/nokogiri' # convert Documents to hashes
1+
# frozen_string_literal: true
32

43
module MotionHTMLPipeline
54
# GitHub HTML processing filters and utilities. This module includes a small

lib/motion-html-pipeline/pipeline/absolute_source_filter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module MotionHTMLPipeline
24
class Pipeline
35
class AbsoluteSourceFilter < Filter

lib/motion-html-pipeline/pipeline/body_content.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module MotionHTMLPipeline
24
class Pipeline
35
# Public: Runs a String of content through an HTML processing pipeline,

lib/motion-html-pipeline/pipeline/disabled/@mention_filter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# TODO Requires Set (or something similar)
24
#------------------------------------------------------------------------------
35
# require 'set'
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# frozen_string_literal: true
2+
3+
# require 'set'
4+
#
5+
# module MotionHTMLPipeline
6+
# class Pipeline
7+
# # HTML filter that replaces @org/team mentions with links. Mentions within
8+
# # <pre>, <code>, <a>, <style>, and <script> elements are ignored.
9+
# #
10+
# # Context options:
11+
# # :base_url - Used to construct links to team profile pages for each
12+
# # mention.
13+
# # :team_pattern - Used to provide a custom regular expression to
14+
# # identify team names
15+
# #
16+
# class TeamMentionFilter < Filter
17+
# # Public: Find @org/team mentions in text. See
18+
# # TeamMentionFilter#team_mention_link_filter.
19+
# #
20+
# # TeamMentionFilter.mentioned_teams_in(text) do |match, org, team|
21+
# # "<a href=...>#{team}</a>"
22+
# # end
23+
# #
24+
# # text - String text to search.
25+
# #
26+
# # Yields the String match, org name, and team name. The yield's
27+
# # return replaces the match in the original text.
28+
# #
29+
# # Returns a String replaced with the return of the block.
30+
# def self.mentioned_teams_in(text, team_pattern = TeamPattern)
31+
# text.gsub team_pattern do |match|
32+
# org = $1
33+
# team = $2
34+
# yield match, org, team
35+
# end
36+
# end
37+
#
38+
# # Default pattern used to extract team names from text. The value can be
39+
# # overridden by providing the team_pattern variable in the context. To
40+
# # properly link the mention, should be in the format of /@(1)\/(2)/.
41+
# TeamPattern = /
42+
# (?<=^|\W) # beginning of string or non-word char
43+
# @([a-z0-9][a-z0-9-]*) # @organization
44+
# \/ # dividing slash
45+
# ([a-z0-9][a-z0-9\-_]*) # team
46+
# \b
47+
# /ix
48+
#
49+
# # Don't look for mentions in text nodes that are children of these elements
50+
# IGNORE_PARENTS = %w[pre code a style script].to_set
51+
#
52+
# def call
53+
# result[:mentioned_teams] ||= []
54+
#
55+
# doc.search('.//text()').each do |node|
56+
# content = node.to_html
57+
# next unless content.include?('@')
58+
# next if has_ancestor?(node, IGNORE_PARENTS)
59+
# html = mention_link_filter(content, base_url, team_pattern)
60+
# next if html == content
61+
# node.replace(html)
62+
# end
63+
# doc
64+
# end
65+
#
66+
# def team_pattern
67+
# context[:team_pattern] || TeamPattern
68+
# end
69+
#
70+
# # Replace @org/team mentions in text with links to the mentioned team's
71+
# # page.
72+
# #
73+
# # text - String text to replace @mention team names in.
74+
# # base_url - The base URL used to construct team page URLs.
75+
# # team_pattern - Regular expression used to identify teams in text
76+
# #
77+
# # Returns a string with @team mentions replaced with links. All links have a
78+
# # 'team-mention' class name attached for styling.
79+
# def mention_link_filter(text, _base_url = '/', team_pattern = TeamPattern)
80+
# self.class.mentioned_teams_in(text, team_pattern) do |match, org, team|
81+
# link = link_to_mentioned_team(org, team)
82+
#
83+
# link ? match.sub("@#{org}/#{team}", link) : match
84+
# end
85+
# end
86+
#
87+
# def link_to_mentioned_team(org, team)
88+
# result[:mentioned_teams] |= [team]
89+
#
90+
# url = base_url.dup
91+
# url << '/' unless url =~ /[\/~]\z/
92+
#
93+
# "<a href='#{url << org}/#{team}' class='team-mention'>" \
94+
# "@#{org}/#{team}" \
95+
# '</a>'
96+
# end
97+
# end
98+
# end
99+
# end

lib/motion-html-pipeline/pipeline/disabled/autolink_filter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# TODO Requires Rinku gem (or something similar)
24
#------------------------------------------------------------------------------
35
# module MotionHTMLPipeline

lib/motion-html-pipeline/pipeline/disabled/camo_filter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# require 'openssl'
24
# require 'uri'
35
#

lib/motion-html-pipeline/pipeline/disabled/email_reply_filter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# MotionHTMLPipeline::Pipeline.require_dependency('escape_utils', 'EmailReplyFilter')
24
# MotionHTMLPipeline::Pipeline.require_dependency('email_reply_parser', 'EmailReplyFilter')
35
#

lib/motion-html-pipeline/pipeline/disabled/emoji_filter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# require 'cgi'
24
# MotionHTMLPipeline::Pipeline.require_dependency('gemoji', 'EmojiFilter')
35
#

lib/motion-html-pipeline/pipeline/disabled/markdown_filter.rb

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# MotionHTMLPipeline::Pipeline.require_dependency('commonmarker', 'MarkdownFilter')
24
#
35
# module MotionHTMLPipeline
@@ -9,10 +11,12 @@
911
# # Context options:
1012
# # :gfm => false Disable GFM line-end processing
1113
# # :commonmarker_extensions => [ :table, :strikethrough,
12-
# # :tagfilter, :autolink ] Common marker extensions to include
14+
# # :tagfilter, :autolink ] Commonmarker extensions to include
1315
# #
1416
# # This filter does not write any additional information to the context hash.
1517
# class MarkdownFilter < TextFilter
18+
# DEFAULT_COMMONMARKER_EXTENSIONS = %i[table strikethrough tagfilter autolink].freeze
19+
#
1620
# def initialize(text, context = nil, result = nil)
1721
# super text, context, result
1822
# @text = @text.delete "\r"
@@ -21,14 +25,29 @@
2125
# # Convert Markdown to HTML using the best available implementation
2226
# # and convert into a DocumentFragment.
2327
# def call
24-
# options = [:GITHUB_PRE_LANG]
25-
# options << :HARDBREAKS if context[:gfm] != false
26-
# options << :UNSAFE if context[:unsafe]
2728
# extensions = context.fetch(
2829
# :commonmarker_extensions,
29-
# ['table', 'strikethrough', 'tagfilter', 'autolink']
30+
# DEFAULT_COMMONMARKER_EXTENSIONS
3031
# )
31-
# html = CommonMarker.render_html(@text, options, extensions)
32+
# html = if (renderer = context[:commonmarker_renderer])
33+
# unless renderer < CommonMarker::HtmlRenderer
34+
# raise ArgumentError, "`commonmark_renderer` must be derived from `CommonMarker::HtmlRenderer`"
35+
# end
36+
# parse_options = :DEFAULT
37+
# parse_options = [:UNSAFE] if context[:unsafe]
38+
#
39+
# render_options = [:GITHUB_PRE_LANG]
40+
# render_options << :HARDBREAKS if context[:gfm] != false
41+
# render_options = [:UNSAFE] if context[:unsafe]
42+
#
43+
# doc = CommonMarker.render_doc(@text, parse_options, extensions)
44+
# renderer.new(options: render_options, extensions: extensions).render(doc)
45+
# else
46+
# options = [:GITHUB_PRE_LANG]
47+
# options << :HARDBREAKS if context[:gfm] != false
48+
# options << :UNSAFE if context[:unsafe]
49+
# CommonMarker.render_html(@text, options, extensions)
50+
# end
3251
# html.rstrip!
3352
# html
3453
# end

lib/motion-html-pipeline/pipeline/disabled/plain_text_input_filter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# MotionHTMLPipeline::Pipeline.require_dependency('escape_utils', 'PlainTextInputFilter')
24
#
35
# module MotionHTMLPipeline

lib/motion-html-pipeline/pipeline/disabled/sanitization_filter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# MotionHTMLPipeline::Pipeline.require_dependency('sanitize', 'SanitizationFilter')
24
#
35
# module MotionHTMLPipeline

lib/motion-html-pipeline/pipeline/disabled/syntax_highlight_filter.rb

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1+
# frozen_string_literal: true
2+
13
# MotionHTMLPipeline::Pipeline.require_dependency('rouge', 'SyntaxHighlightFilter')
24
#
35
# module MotionHTMLPipeline
46
# class Pipeline
5-
# # HTML Filter that syntax highlights code blocks wrapped
6-
# # in <pre lang="...">.
7+
# # HTML Filter that syntax highlights text inside code blocks.
8+
# #
9+
# # Context options:
10+
# #
11+
# # :highlight => String represents the language to pick lexer. Defaults to empty string.
12+
# # :scope => String represents the class attribute adds to pre element after.
13+
# # Defaults to "highlight highlight-css" if highlights a css code block.
14+
# #
15+
# # This filter does not write any additional information to the context hash.
716
# class SyntaxHighlightFilter < Filter
817
# def initialize(*args)
918
# super(*args)
@@ -15,23 +24,20 @@
1524
# default = context[:highlight] && context[:highlight].to_s
1625
# next unless lang = node['lang'] || default
1726
# next unless lexer = lexer_for(lang)
18-
# text = node.inner_text
1927
#
20-
# html = highlight_with_timeout_handling(text, lang)
28+
# text = node.inner_text
29+
# html = highlight_with_timeout_handling(text, lexer)
2130
# next if html.nil?
2231
#
2332
# node.inner_html = html
24-
# klass = node['class']
25-
# scope = context[:scope] || "highlight-#{lang}"
26-
# klass = [klass, scope].compact.join ' '
27-
#
28-
# node['class'] = klass
33+
# scope = context.fetch(:scope) { 'highlight' }
34+
# node['class'] = "#{scope} #{scope}-#{lang}"
2935
# end
3036
# doc
3137
# end
3238
#
33-
# def highlight_with_timeout_handling(text, lang)
34-
# Rouge.highlight(text, lang, @formatter)
39+
# def highlight_with_timeout_handling(text, lexer)
40+
# Rouge.highlight(text, lexer, @formatter)
3541
# rescue Timeout::Error => _
3642
# nil
3743
# end

lib/motion-html-pipeline/pipeline/disabled/toc_filter.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# MotionHTMLPipeline::Pipeline.require_dependency('escape_utils', 'TableOfContentsFilter')
24
#
35
# module MotionHTMLPipeline
@@ -33,7 +35,7 @@
3335
# end
3436
#
3537
# def call
36-
# result[:toc] = ''
38+
# result[:toc] = String.new('')
3739
#
3840
# headers = Hash.new(0)
3941
# doc.css('h1, h2, h3, h4, h5, h6').each do |node|

lib/motion-html-pipeline/pipeline/filter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module MotionHTMLPipeline
24
class Pipeline
35
# Base class for user content HTML filters. Each filter takes an

lib/motion-html-pipeline/pipeline/https_filter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module MotionHTMLPipeline
24
class Pipeline
35
# HTML Filter for replacing http references to :http_url with https versions.

lib/motion-html-pipeline/pipeline/image_filter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module MotionHTMLPipeline
24
class Pipeline
35
# HTML Filter that converts image's url into <img> tag.

lib/motion-html-pipeline/pipeline/image_max_width_filter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module MotionHTMLPipeline
24
class Pipeline
35
# This filter rewrites image tags with a max-width inline style and also wraps

lib/motion-html-pipeline/pipeline/text_filter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module MotionHTMLPipeline
24
class Pipeline
35
class TextFilter < Filter

lib/motion-html-pipeline/pipeline/version.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module MotionHTMLPipeline
24
class Pipeline
35
VERSION = '0.2'.freeze

motion-html-pipeline.gemspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require File.expand_path('../lib/motion-html-pipeline/pipeline/version.rb', __FILE__)
24

35
Gem::Specification.new do |spec|

spec/motion-html-pipeline/_helpers/mock_instumentation_service.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class MockedInstrumentationService
24
attr_reader :events
35
def initialize(event = nil, events = [])

0 commit comments

Comments
 (0)