Sub ProcessMarkdownToCSBuilder(markdown As String) As CSBuilder
Dim cs As CSBuilder
cs.Initialize
Dim boldPattern As String = "\*\*(.*?)\*\*" ' Regex for **Text**
Dim italicPattern As String = "\*(.*?)\*" ' Regex for *Text*
Dim underlinePattern As String = "\_(.*?)\_" ' Regex for _Text_
Dim urlPattern As String = "\[(.*?)\]\((.*?)\)" ' Regex for [Text](URL)
Dim combinedPattern As String = boldPattern & "|" & italicPattern & "|" & underlinePattern & "|" & urlPattern
Dim matcher As Matcher = Regex.Matcher(combinedPattern, markdown)
Dim lastEnd As Int = 0
Do While matcher.Find
cs.Append(markdown.SubString2(lastEnd, matcher.GetStart(0)))
If matcher.Group(1) <> Null Then
cs.Typeface(Typeface.DEFAULT_BOLD).Append(matcher.Group(1)).PopAll
Else If matcher.Group(2) <> Null Then
cs.Typeface(Typeface.CreateNew(Typeface.DEFAULT, Typeface.STYLE_ITALIC)).Append(matcher.Group(2)).PopAll
Else If matcher.Group(3) <> Null Then
cs.Underline.Append(matcher.Group(3)).PopAll
Else If matcher.Group(4) <> Null And matcher.Group(5) <> Null Then
cs.Color(Colors.Blue).Clickable("cs", matcher.Group(5)).Append(matcher.Group(4)).PopAll
End If
lastEnd = matcher.GetEnd(0)
Loop
cs.Append(markdown.SubString(lastEnd))
Return cs
End Sub