Skip to content

[pull] master from increments:master #12

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

Merged
merged 6 commits into from
May 11, 2024
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## Unreleased

## 1.1.2

- Add test for code_block filter
- Upgrade github-linguist from 4.x to 7.x

## 1.1.1

- Allow open attribute on details
Expand Down
2 changes: 1 addition & 1 deletion lib/qiita/markdown/filters/code_block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def has_only_filename?
end

def linguist_language
@linguist_language ||= Linguist::Language.find_by_filename(filename).first
@linguist_language ||= Linguist::Language.find_by_extension(filename).first
end

def sections
Expand Down
2 changes: 1 addition & 1 deletion lib/qiita/markdown/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Qiita
module Markdown
VERSION = "1.1.1"
VERSION = "1.1.2"
end
end
2 changes: 1 addition & 1 deletion qiita-markdown.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Gem::Specification.new do |spec|

spec.add_dependency "addressable"
spec.add_dependency "gemoji"
spec.add_dependency "github-linguist", "~> 4.0"
spec.add_dependency "github-linguist", "~> 7.0"
spec.add_dependency "html-pipeline", "~> 2.0"
spec.add_dependency "mem"
spec.add_dependency "qiita_marker", "~> 0.23.9"
Expand Down
126 changes: 126 additions & 0 deletions spec/qiita/markdown/filters/code_block_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# frozen_string_literal: true

describe Qiita::Markdown::Filters::CodeBlock do
subject(:filter) { described_class.new(input_html) }

let(:context) { nil }

context "without code" do
let(:input_html) do
<<~HTML
<pre>
</pre>
HTML
end

it "does not change" do
expect(filter.call.to_s).to eq(input_html)
end
end

context "with code" do
let(:input_html) do
<<~HTML
<pre><code>
</code></pre>
HTML
end

it "does not change" do
expect(filter.call.to_s).to eq(input_html)
end

context "with data-metadata" do
let(:input_html) do
<<~HTML
<pre><code data-metadata>
</code></pre>
HTML
end

it "does not change" do
expect(filter.call.to_s).to eq(input_html)
end

context "with data-metadata value" do
let(:input_html) do
<<~HTML
<pre><code data-metadata="ruby">
</code></pre>
HTML
end

let(:output_html) do
<<~HTML
<pre lang="ruby"><code data-metadata="ruby">
</code></pre>
HTML
end

it "adds lang on pre" do
expect(filter.call.to_s).to eq(output_html)
end

context "with value include filename" do
let(:input_html) do
<<~HTML
<pre><code data-metadata="ruby:abc.rb">
</code></pre>
HTML
end

let(:output_html) do
<<~HTML
<pre filename="abc.rb" lang="ruby"><code data-metadata="ruby:abc.rb">
</code></pre>
HTML
end

it "adds lang and filename on pre" do
expect(filter.call.to_s).to eq(output_html)
end
end
end

context "with data-metadata value like filename" do
let(:input_html) do
<<~HTML
<pre><code data-metadata="abc.rb">
</code></pre>
HTML
end

let(:output_html) do
<<~HTML
<pre filename="abc.rb" lang="ruby"><code data-metadata="abc.rb">
</code></pre>
HTML
end

it "adds lang and filename on pre" do
expect(filter.call.to_s).to eq(output_html)
end
end

context "with data-metadata value like filename without extension" do
let(:input_html) do
<<~HTML
<pre><code data-metadata="Dockerfile">
</code></pre>
HTML
end

let(:output_html) do
<<~HTML
<pre lang="Dockerfile"><code data-metadata="Dockerfile">
</code></pre>
HTML
end

it "adds lang and filename on pre" do
expect(filter.call.to_s).to eq(output_html)
end
end
end
end
end
Loading