mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Colorify SCSI MODE PAGE 0Dh
This commit is contained in:
27
Aaru.Helpers/MarkupHelpers.cs
Normal file
27
Aaru.Helpers/MarkupHelpers.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
public static class MarkupHelper
|
||||
{
|
||||
public static string HighlightNumbers(string input, string color, bool italicize = false)
|
||||
{
|
||||
if(string.IsNullOrEmpty(input) || string.IsNullOrEmpty(color)) return input;
|
||||
|
||||
// Match integers and decimals (e.g., 42, 3.14, -7)
|
||||
string pattern = @"(?<!
|
||||
|
||||
\[" +
|
||||
Regex.Escape(color) +
|
||||
@"\]
|
||||
|
||||
)(-?\d+(\.\d+)?)(?!
|
||||
|
||||
\[/\]
|
||||
|
||||
)";
|
||||
|
||||
string openingTag = italicize ? $"[italic][{color}]" : $"[{color}]";
|
||||
string closingTag = italicize ? "[/][/]" : "[/]";
|
||||
|
||||
return Regex.Replace(input, pattern, $"{openingTag}$1{closingTag}");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user