diff options
author | Lukas '+ alert('Eipi') + ' Eipert <leipert@gitlab.com> | 2019-08-02 17:38:50 +0300 |
---|---|---|
committer | Fatih Acet <acetfatih@gmail.com> | 2019-08-02 17:38:50 +0300 |
commit | fc9f099884f6b98dea3f4e6110ecba6151fa75b8 (patch) | |
tree | 037c50677bea22d8e0b1733f210e08de01e32962 /lib | |
parent | 0fec9a4fc7fae7480a92d6402d3ad144b4bd7233 (diff) |
Prevent empty classes in ansi2html conversion
Currently we write out empty CSS classes (`class=""`) every time we
create a new tag. This adds 9 unnecessary bytes per span element. In a
recent trace, I have counted 11950 span elements. So we transported 105
unnecessary kilobytes!
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/ci/ansi2html.rb | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/lib/gitlab/ci/ansi2html.rb b/lib/gitlab/ci/ansi2html.rb index fc3223e7442..7e348763e81 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? + + close_open_tags if @sections.any? && @lineno_in_section == 0 @lineno_in_section += 1 - open_new_tag end def handle_section(scanner) @@ -310,11 +304,24 @@ module Gitlab if @sections.any? css_classes << "section" - css_classes << "js-section-header section-header" if @lineno_in_section == 0 + + css_classes << if @lineno_in_section == 0 + "js-section-header section-header" + else + "line" + end + css_classes += sections.map { |section| "js-s-#{section}" } end - @out << %{<span class="#{css_classes.join(' ')}">} + close_open_tags + + @out << if css_classes.any? + %{<span class="#{css_classes.join(' ')}">} + else + %{<span>} + end + @n_open_tags += 1 end |