From c232c0dc63f3066bc4d54e60a04b7925e7aa14b2 Mon Sep 17 00:00:00 2001 From: Fabio Pitino Date: Sun, 23 Jun 2019 17:22:45 +0100 Subject: Remove unnecessary span tags With this change we translate a simple line break to
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. --- lib/gitlab/ci/ansi2html.rb | 12 +++--------- spec/lib/gitlab/ci/ansi2html_spec.rb | 21 ++++++++++----------- 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 %{
} - write_raw %{} if css_classes.any? @lineno_in_section += 1 - open_new_tag + close_open_tags + write_in_tag %{
} + 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('Hello') 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('
') + expect(convert_html("\n")).to eq('
') end it "groups carriage returns with newlines" do - expect(convert_html("\r\n")).to eq('
') + expect(convert_html("\r\n")).to eq('
') end describe "incremental update" do @@ -193,7 +193,7 @@ describe Gitlab::Ci::Ansi2html do let(:pre_text) { "Hello\r" } let(:pre_html) { "Hello\r" } let(:text) { "\nWorld" } - let(:html) { "
World
" } + let(:html) { "
World" } 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 = %{Hello} - line_break = %{
} - line = %{} - empty_line = %{} - 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 = %{The Header} + line_break = %{
} + line = %{the line} + html = "#{section_start_html}#{header}#{line_break}#{line}#{section_end_html}" expect(convert_html(text)).to eq(html) end -- cgit v1.2.1