Skip to content

Commit

Permalink
Merge pull request #372 from gjtorikian/syn-high
Browse files Browse the repository at this point in the history
Drop SyntaxHighlightFilter
  • Loading branch information
gjtorikian committed Jan 26, 2023
2 parents 8f8572e + 21117b3 commit 8304776
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 22 deletions.
13 changes: 13 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,16 @@ inherit_gem:
rubocop-standard:
- config/default.yml
- config/minitest.yml

inherit_mode:
merge:
- Exclude

AllCops:
Exclude:
- test/progit/**/*
- "pkg/**/*"
- "ext/**/*"
- "vendor/**/*"
- "tmp/**/*"
- "test/progit/**/*"
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ group :development do
end

group :test do
gem "commonmarker", "~> 1.0.0.pre3", require: false
gem "commonmarker", "~> 1.0.0.pre4", require: false
gem "gemoji", "~> 3.0", require: false
gem "gemojione", "~> 4.3", require: false
gem "minitest"

gem "minitest-bisect", "~> 1.6"

gem "nokogiri", "~> 1.13"

gem "rinku", "~> 1.7", require: false
gem "sanitize", "~> 5.2", require: false

gem "escape_utils", "~> 1.0", require: false
gem "minitest-focus", "~> 1.1"
gem "rouge", "~> 3.1", require: false
end
3 changes: 2 additions & 1 deletion lib/html_pipeline/convert_filter/markdown_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def initialize(context: {}, result: {})
# Convert Commonmark to HTML using the best available implementation.
def call(text)
options = @context.fetch(:markdown, {})
Commonmarker.to_html(text, options: options).rstrip!
plugins = options.fetch(:plugins, {})
Commonmarker.to_html(text, options: options, plugins: plugins).rstrip!
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/html_pipeline/node_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ def call(html, context: {}, result: {})
node_filter = new(context: context, result: result)
Selma::Rewriter.new(sanitizer: nil, handlers: [node_filter]).rewrite(html)
end
end
end
end
end
2 changes: 0 additions & 2 deletions lib/html_pipeline/node_filter/table_of_contents_filter.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

HTMLPipeline.require_dependency("escape_utils", "TableOfContentsFilter")

class HTMLPipeline
class NodeFilter
# Generates a Table of Contents: an array of hashes containing:
Expand Down
2 changes: 0 additions & 2 deletions lib/html_pipeline/sanitization_filter.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

HTMLPipeline.require_dependency("sanitize", "SanitizationFilter")

class HTMLPipeline
# A special filter with sanization routines and allowlists. This module defines
# what HTML is allowed in user provided content and fixes up issues with
Expand Down
2 changes: 0 additions & 2 deletions lib/html_pipeline/text_filter/plain_text_input_filter.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

HTMLPipeline.require_dependency("escape_utils", "PlainTextInputFilter")

class HTMLPipeline
class TextFilter
# Simple filter for plain text input. HTML escapes the text input and wraps it
Expand Down
2 changes: 1 addition & 1 deletion lib/html_pipeline/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

class HTMLPipeline
VERSION = "2.13.2"
VERSION = "3.0.0.pre1"
end
2 changes: 1 addition & 1 deletion test/html_pipeline/convert_filter/markdown_filter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def test_without_tagfilter
class GFMTest < Minitest::Test
def setup
@gfm = MarkdownFilter
@context = { markdown: { render: { unsafe_: true } } }
@context = { markdown: { render: { unsafe_: true }, plugins: { syntax_highlighter: nil } } }
end

def test_not_touch_single_underscores_inside_words
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require "test_helper"
require "escape_utils"

SyntaxHighlightFilter = HTMLPipeline::NodeFilter::SyntaxHighlightFilter

Expand Down
2 changes: 1 addition & 1 deletion test/html_pipeline_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def test_setup_instrumentation

def test_incorrect_text_filters
assert_raises(HTMLPipeline::InvalidFilterError) do
HTMLPipeline.new(text_filters: [HTMLPipeline::NodeFilter::SyntaxHighlightFilter], default_context: @default_context)
HTMLPipeline.new(text_filters: [HTMLPipeline::NodeFilter::MentionFilter], default_context: @default_context)
end
end

Expand Down
14 changes: 7 additions & 7 deletions test/sanitization_filter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,18 +216,18 @@ def test_sanitization_pipeline_can_be_configured
HTMLPipeline::ConvertFilter::MarkdownFilter.new,
sanitization_config: config,
node_filters: [
HTMLPipeline::NodeFilter::SyntaxHighlightFilter.new,
HTMLPipeline::NodeFilter::MentionFilter.new,
],
)

result = pipeline.call(<<~CODE)
This is *great*:
This is *great*, @balevine:
some_code(:first)
CODE

expected = <<~HTML
<p>This is great:</p>
<p>This is great, <a href="/balevine" class="user-mention">@balevine</a>:</p>
<pre><code>some_code(:first)
</code></pre>
HTML
Expand All @@ -237,21 +237,21 @@ def test_sanitization_pipeline_can_be_configured

def test_sanitization_pipeline_can_be_removed
pipeline = HTMLPipeline.new(\
convert_filter: HTMLPipeline::ConvertFilter::MarkdownFilter.new,
convert_filter: HTMLPipeline::ConvertFilter::MarkdownFilter.new(context: { markdown: { plugins: { syntax_highlighter: nil } } }),
sanitization_config: nil,
node_filters: [
HTMLPipeline::NodeFilter::SyntaxHighlightFilter.new,
HTMLPipeline::NodeFilter::MentionFilter.new,
],
)

result = pipeline.call(<<~CODE)
This is *great*:
This is *great*, @balevine:
some_code(:first)
CODE

expected = <<~HTML
<p>This is <em>great</em>:</p>
<p>This is <em>great</em>, <a href="/balevine" class="user-mention">@balevine</a>:</p>
<pre><code>some_code(:first)
</code></pre>
HTML
Expand Down
2 changes: 2 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

require "awesome_print"

require "nokogiri"

module TestHelpers
end

Expand Down

0 comments on commit 8304776

Please sign in to comment.