dblock/jenkins-ansicolor-plugin — pull request #26 by joster-jambit (2014-05-16 11:29:45+00:00)
Title: filter stream instead of replacing whole log text with annotation

This is more or less a rewrite of this plugin.

The previous approach was to hide *all* log text using span tags with
"display: none" and readding it as markup-annotation, but with the log
text interspersed with tags as the actual markup content.

This approach, while understandable given Jenkins' limitations in
filtering and annotating log output, caused a problem for us: Now that
all content of every log line is considered "markup" by Jenkins, no
other component can match log text and add any other annotation to
it. This makes sense, because it would be wrong to "add markup to
markup".

Specifically, in our case, URLs were not transformed into links
anymore, which was a badly needed feature. Other plugins would be
affected as well.

I propose this code instead, which implements a stream filter which
removes ANSI escape sequences from the text (instead of hiding them
via CSS) and emits HTML tags as ConsoleNotes only at their proper
places, leaving the actual log text untouched as non-markup text.

Furthermore, it handles the fact that ANSI attribute changes can
overlap while HTML elements cannot. For example, the ANSI sequence
(bold on, underline on, bold off, underline off) cannot be translated
to "......

......

..." but may be translated to
"......

...

...

..." instead.