Skip to content

Commit

Permalink
Decorate code in html report (#779)
Browse files Browse the repository at this point in the history
* decorate code in html report

* Revert the empty line
  • Loading branch information
eugene-sy authored Sep 9, 2023
1 parent 0325ec1 commit 756847b
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/main/scala/com/sksamuel/scapegoat/io/HtmlReportWriter.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.sksamuel.scapegoat.io

import scala.xml.{Elem, Unparsed}
import scala.xml.{Elem, Unparsed, XML}

import com.sksamuel.scapegoat.{Feedback, Levels}

Expand Down Expand Up @@ -38,13 +38,13 @@ object HtmlReportWriter extends ReportWriter {
| }
|
| .title {
| color: #616161;
| font-size: 16px;
| color: #616161;
| font-size: 16px;
| }
|
| .source {
| float: right;
| font-style: italic;
| font-style: italic;
| color: #868686;
| }
|
Expand All @@ -55,6 +55,12 @@ object HtmlReportWriter extends ReportWriter {
| font-size: 12px;
| }
|
| code {
| color: #0C0C0C;
| font-weight: 300;
| font-size: 12px;
| }
|
| .inspection {
| padding-left: 10px;
| font-style:italic;
Expand Down Expand Up @@ -111,12 +117,12 @@ object HtmlReportWriter extends ReportWriter {
case Levels.Warning => <span class="label label-warning">Warning</span>
case Levels.Error => <span class="label label-danger">Error</span>
}
}&nbsp;{warning.text}&nbsp; <span class="inspection">
}&nbsp;{decorateCode(warning.text)}&nbsp; <span class="inspection">
{warning.inspection}
</span>
</div>
<div>
{warning.explanation}
{decorateCode(warning.explanation)}
</div>{
warning.snippet match {
case None =>
Expand All @@ -135,5 +141,8 @@ object HtmlReportWriter extends ReportWriter {
{header}{body(reporter)}
</html>

private def decorateCode(text: String): Elem =
XML.loadString(s"<span>${text.replaceAll("`([^`]*)`", "<code>$1</code>")}</span>")

override protected def generate(feedback: Feedback): String = toHTML(feedback).toString()
}

0 comments on commit 756847b

Please sign in to comment.