~jan0sch/smederee
Showing details for patch 2349733a35d70db277e3fccfde6e1387057ba54d.
diff -rN -u old-smederee/modules/hub/src/main/resources/assets/css/main.css new-smederee/modules/hub/src/main/resources/assets/css/main.css --- old-smederee/modules/hub/src/main/resources/assets/css/main.css 2025-01-31 13:44:46.321038978 +0000 +++ new-smederee/modules/hub/src/main/resources/assets/css/main.css 2025-01-31 13:44:46.321038978 +0000 @@ -456,11 +456,35 @@ vertical-align: top; } -tr.code-line-todo { +tr.code-line.todo-default { background-color: var(--nord15); } -tr.code-line-todo:hover { +tr.code-line.todo-default:hover { + background-color: transparent; +} + +tr.code-line.todo-error { + background-color: var(--nord11); +} + +tr.code-line.todo-error:hover { + background-color: transparent; +} + +tr.code-line.todo-info { + background-color: var(--nord14); +} + +tr.code-line.todo-info:hover { + background-color: transparent; +} + +tr.code-line.todo-warning { + background-color: var(--nord13); +} + +tr.code-line.todo-warning:hover { background-color: transparent; } diff -rN -u old-smederee/modules/hub/src/main/scala/de/smederee/hub/MarkdownRenderer.scala new-smederee/modules/hub/src/main/scala/de/smederee/hub/MarkdownRenderer.scala --- old-smederee/modules/hub/src/main/scala/de/smederee/hub/MarkdownRenderer.scala 2025-01-31 13:44:46.321038978 +0000 +++ new-smederee/modules/hub/src/main/scala/de/smederee/hub/MarkdownRenderer.scala 2025-01-31 13:44:46.321038978 +0000 @@ -103,21 +103,10 @@ * A context for an html node renderer that is needed to extract the html writer from it. */ class ToDoTextRenderer(context: HtmlNodeRendererContext) extends NodeRenderer { + import ToDoTextCssMapping._ + private final val htmlWriter: HtmlWriter = context.getWriter() - /* We want to match either on specific words followed by a colon (`:`) and also on complete text nodes - * which can be created if markdown rendering is involved. - * For example a `**WORD** some text` will produce two text nodes (`WORD` and ` some text`) - * while `WORD: some text` will only produce one. - */ - private final val isToDoItem: Regex = "(?i)(.*)(DEBUG|FIXME|HACK|TODO):(.*)|^(DEBUG|FIXME|HACK|TODO)$".r - private final val log: Logger = LoggerFactory.getLogger(getClass()) - - private final val todoCssClasses: Map[String, String] = Map( - "todo" -> "todo-default", - "fixme" -> "todo-error", - "debug" -> "todo-info", - "hack" -> "todo-warning" - ).withDefaultValue("todo-default") + private final val log: Logger = LoggerFactory.getLogger(getClass()) override def getNodeTypes(): java.util.Set[Class[? <: Node]] = Set(classOf[Text]).asJava @@ -150,3 +139,21 @@ } } + +object ToDoTextCssMapping { + /* We want to match either on specific words followed by a colon (`:`) and also on complete text nodes + * which can be created if markdown rendering is involved. + * For example a `**WORD** some text` will produce two text nodes (`WORD` and ` some text`) + * while `WORD: some text` will only produce one. + */ + val isToDoItem: Regex = "(?i)(.*)(DEBUG|FIXME|HACK|TODO):(.*)|^(DEBUG|FIXME|HACK|TODO)$".r + + // Mapping of todo item (words) to css classes for highlighting. + val todoCssClasses: Map[String, String] = Map( + "todo" -> "todo-default", + "fixme" -> "todo-error", + "debug" -> "todo-info", + "hack" -> "todo-warning" + ).withDefaultValue("todo-default") + +} diff -rN -u old-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryFiles.scala.html new-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryFiles.scala.html --- old-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryFiles.scala.html 2025-01-31 13:44:46.321038978 +0000 +++ new-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryFiles.scala.html 2025-01-31 13:44:46.321038978 +0000 @@ -1,3 +1,6 @@ +@import java.util.Locale +@import de.smederee.hub.ToDoTextCssMapping._ + @(baseUri: Uri, lang: LanguageCode = LanguageCode("en") )(actionBaseUri: Uri, @@ -75,14 +78,20 @@ @for(tuple <- fileContent.zipWithIndex) { @defining(tuple._1) { content => @defining(tuple._2) { lineNumber => - @if(content.matches("(?i)(.*)(DEBUG|FIXME|HACK|TODO):(.*)")) { - <tr class="code-line code-line-todo"> - } else { - <tr class="code-line"> + @defining(isToDoItem.findFirstMatchIn(content)) { matchedItem => + @if(matchedItem.nonEmpty) { + @for(todoItem <- matchedItem) { + @defining(todoCssClasses(Option(todoItem.group(4)).getOrElse(todoItem.group(2)).toLowerCase(Locale.ROOT))) { cssClass => + <tr class="code-line @cssClass"> + } + } + } else { + <tr class="code-line"> + } + <td class="code-line-number" id="L@lineNumber"><a href="#L@lineNumber">@lineNumber</a></td> + <td class="code-line"><code class="code-line">@content</code></td> + </tr> } - <td class="code-line-number" id="L@lineNumber"><a href="#L@lineNumber">@lineNumber</a></td> - <td class="code-line"><code class="code-line">@content</code></td> - </tr> } } }