I have taken a few more thoughts:
[h]Sample Formatted Text[/h]
# Heading 1
[PS:Name]At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
## Heading 2
Lorem ipsum dolor sit amet, [TS:My Style]consetetur [TS:Cite]sadipscing[/TS] elitr,[/TS] sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum.
[PS:Name]Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
- You see, Users can define Headings (1-6) like the MarkDown-Syntax defined it “# Heading 1”.
- Paragraphs will create after a blank Line i[/i] and a Linebreak and they have an optional Style-Definition at the beginning “[PS:Name]”.
- within Paragraphs it’s possible to use optional Text-Styles “[TS:Name]consetetur [/TS]”.
[h]Parsing[/h]
1. Step: Split into Heading and Paragraph-Objects (RegEx)
(?:\\R*)?(?:(#{1,6})\\s*|\\[PS:(.*)\\])?(.*)(?:\\R)?
Using this, i got 6 Matches. Why? The last match is empty (no need). How to edit the RegEx to get the 5 Matches?
I added a TextArea with the Sample Content from above and a ListBox to a Window. TextAreas1.TextChance looks this:
[code]Listbox1.DeleteAllRows
Dim headingLevel, paragraphStyle, content As String
Dim s As String = Me.Text
Dim rx As New RegEx
rx.SearchPattern = “(?mi-Us)(?:\R*)?(?:(#{1,6})\s*|\[PS:(.)\])?(.)(?:\R)?”
Dim rxOptions As RegExOptions = rx.Options
rxOptions.LineEndType = 4
Dim match As RegExMatch = rx.Search( s )
Do
If match <> Nil Then
headingLevel = match.SubExpressionString(1)
paragraphStyle = match.SubExpressionString(2)
content = match.SubExpressionString(3)
If headingLevel <> "" And content <> "" Then
Listbox1.AddRow(content + " (Heading)")
ElseIf content <> "" Then
Listbox1.AddRow(c)
End If
End If
match = rx.Search
Loop Until match Is Nil[/code]
This code freezes the program, why? Isn’t the loop right?
2. Step (ToDo): Parse the content of each paragraph to get Text-Styles
Don’t know how