summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabio Pitino <fpitino@gitlab.com>2019-06-23 17:22:45 +0100
committerFabio Pitino <fpitino@gitlab.com>2019-06-25 08:29:00 +0100
commitc232c0dc63f3066bc4d54e60a04b7925e7aa14b2 (patch)
tree17f84127d0d933989aa18c9ba87b52ea39576ee4
parent5d2e03233686d190d015da80cc4fefbf6421611f (diff)
downloadgitlab-ce-c232c0dc63f3066bc4d54e60a04b7925e7aa14b2.tar.gz
Remove unnecessary span tags
With this change we translate a simple line break to <br/> tag and ensure we generate a header line at the beginning of a section followed by a body line if there lines inside the collapsible section.
-rw-r--r--lib/gitlab/ci/ansi2html.rb12
-rw-r--r--spec/lib/gitlab/ci/ansi2html_spec.rb21
2 files changed, 13 insertions, 20 deletions
diff --git a/lib/gitlab/ci/ansi2html.rb b/lib/gitlab/ci/ansi2html.rb
index fc3223e7442..740bcd55824 100644
--- a/lib/gitlab/ci/ansi2html.rb
+++ b/lib/gitlab/ci/ansi2html.rb
@@ -194,16 +194,10 @@ module Gitlab
end
def handle_new_line
- css_classes = []
-
- if @sections.any?
- css_classes = %w[section line] + sections.map { |section| "s_#{section}" }
- end
-
- write_in_tag %{<br/>}
- write_raw %{<span class="#{css_classes.join(' ')}"></span>} if css_classes.any?
@lineno_in_section += 1
- open_new_tag
+ close_open_tags
+ write_in_tag %{<br/>}
+ close_open_tags
end
def handle_section(scanner)
diff --git a/spec/lib/gitlab/ci/ansi2html_spec.rb b/spec/lib/gitlab/ci/ansi2html_spec.rb
index 3d57ce431ab..4303899108a 100644
--- a/spec/lib/gitlab/ci/ansi2html_spec.rb
+++ b/spec/lib/gitlab/ci/ansi2html_spec.rb
@@ -3,7 +3,7 @@ require 'spec_helper'
describe Gitlab::Ci::Ansi2html do
subject { described_class }
- it "prints non-ansi as-is" do
+ it "wraps text with span tags" do
expect(convert_html("Hello")).to eq('<span class="">Hello</span>')
end
@@ -141,11 +141,11 @@ describe Gitlab::Ci::Ansi2html do
end
it "replaces newlines with line break tags" do
- expect(convert_html("\n")).to eq('<span class=""><br/><span class=""></span></span>')
+ expect(convert_html("\n")).to eq('<span class=""><br/></span>')
end
it "groups carriage returns with newlines" do
- expect(convert_html("\r\n")).to eq('<span class=""><br/><span class=""></span></span>')
+ expect(convert_html("\r\n")).to eq('<span class=""><br/></span>')
end
describe "incremental update" do
@@ -193,7 +193,7 @@ describe Gitlab::Ci::Ansi2html do
let(:pre_text) { "Hello\r" }
let(:pre_html) { "<span class=\"\">Hello\r</span>" }
let(:text) { "\nWorld" }
- let(:html) { "<span class=\"\"><br/><span class=\"\">World</span></span>" }
+ let(:html) { "<span class=\"\"><br/></span><span class=\"\">World</span>" }
it_behaves_like 'stateable converter'
end
@@ -229,13 +229,12 @@ describe Gitlab::Ci::Ansi2html do
shared_examples 'a legit section' do
let(:text) { "#{section_start}Some text#{section_end}" }
- it 'prints light red' do
- text = "#{section_start}\e[91mHello\e[0m\n#{section_end}"
- header = %{<span class="term-fg-l-red section js-section-header section-header js-s-#{class_name(section_name)}">Hello</span>}
- line_break = %{<span class="section js-section-header section-header js-s-#{class_name(section_name)}"><br/></span>}
- line = %{<span class="section line s_#{class_name(section_name)}"></span>}
- empty_line = %{<span class="section js-s-#{class_name(section_name)}"></span>}
- html = "#{section_start_html}#{header}#{line_break}#{line}#{empty_line}#{section_end_html}"
+ it 'prints light red header line and resets color for body line' do
+ text = "#{section_start}\e[91mThe Header\e[0m\nthe line#{section_end}"
+ header = %{<span class="term-fg-l-red section js-section-header section-header js-s-#{class_name(section_name)}">The Header</span>}
+ line_break = %{<span class="section js-s-#{class_name(section_name)}"><br/></span>}
+ line = %{<span class="section js-s-#{class_name(section_name)}">the line</span>}
+ html = "#{section_start_html}#{header}#{line_break}#{line}#{section_end_html}"
expect(convert_html(text)).to eq(html)
end