Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop SyntaxHighlightFilter #372

Merged
merged 3 commits into from
Dec 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
62 changes: 0 additions & 62 deletions lib/html_pipeline/node_filter/syntax_highlight_filter.rb

This file was deleted.

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
62 changes: 0 additions & 62 deletions test/html_pipeline/node_filter/syntax_highlight_filter_test.rb

This file was deleted.

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 @@ -189,18 +189,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 @@ -210,21 +210,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