-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from Toine-db/text_to_segments
Text in segments and .Net 9 support
- Loading branch information
Showing
28 changed files
with
815 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...downParser/MarkdownReferenceDefinition.cs → ...ser/Models/MarkdownReferenceDefinition.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
namespace MarkdownParser | ||
namespace MarkdownParser.Models | ||
{ | ||
public class MarkdownReferenceDefinition | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace MarkdownParser.Models.Segments | ||
{ | ||
public abstract class BaseSegment | ||
{ | ||
public bool HasLiteralContent { get; protected set; } = false; | ||
|
||
public override string ToString() | ||
{ | ||
return string.Empty; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using MarkdownParser.Models.Segments.Indicators; | ||
|
||
namespace MarkdownParser.Models.Segments | ||
{ | ||
public class IndicatorSegment : BaseSegment | ||
{ | ||
public SegmentIndicator Indicator { get; } | ||
public SegmentIndicatorPosition IndicatorPosition { get; } | ||
|
||
public IndicatorSegment(SegmentIndicator indicator, SegmentIndicatorPosition indicatorPosition) | ||
{ | ||
Indicator = indicator; | ||
IndicatorPosition = indicatorPosition; | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return string.Empty; | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/MarkdownParser/Models/Segments/Indicators/SegmentIndicator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace MarkdownParser.Models.Segments.Indicators | ||
{ | ||
public enum SegmentIndicator | ||
{ | ||
NotSupported, | ||
Strong, | ||
Italic, | ||
Strikethrough, | ||
Code, | ||
Link, | ||
LineBreak | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/MarkdownParser/Models/Segments/Indicators/SegmentIndicatorPosition.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace MarkdownParser.Models.Segments.Indicators | ||
{ | ||
public enum SegmentIndicatorPosition | ||
{ | ||
Start, | ||
End | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using MarkdownParser.Models.Segments.Indicators; | ||
|
||
namespace MarkdownParser.Models.Segments | ||
{ | ||
public class LinkSegment : IndicatorSegment | ||
{ | ||
public string Url { get; } | ||
public string Title { get; } | ||
|
||
public LinkSegment(SegmentIndicator indicator, SegmentIndicatorPosition indicatorPosition, string url, string title) | ||
: base(indicator, indicatorPosition) | ||
{ | ||
Url = url; | ||
Title = title; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace MarkdownParser.Models.Segments | ||
{ | ||
public class TextSegment : BaseSegment | ||
{ | ||
public string Text { get; set; } | ||
|
||
public TextSegment(string text) | ||
{ | ||
Text = text; | ||
HasLiteralContent = !string.IsNullOrWhiteSpace(Text); | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return Text ?? string.Empty; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using MarkdownParser.Models.Segments; | ||
|
||
namespace MarkdownParser.Models | ||
{ | ||
public class TextBlock | ||
{ | ||
public BaseSegment[] TextSegments { get; } | ||
|
||
public TextBlock(BaseSegment[] textSegments) | ||
{ | ||
TextSegments = textSegments; | ||
} | ||
|
||
/// <summary> | ||
/// Get all text (LiteralContent) and ignoring all emphasize | ||
/// </summary> | ||
/// <param name="usedStringForLineBreaks">text used for line breaks</param> | ||
/// <returns>clean text</returns> | ||
public string ExtractLiteralContent(string usedStringForLineBreaks) | ||
{ | ||
var literalContent = TextSegmentHelper.TextSegmentsToLiteralContent(TextSegments, usedStringForLineBreaks); | ||
return literalContent; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System.Linq; | ||
using System.Text; | ||
using MarkdownParser.Models.Segments; | ||
using MarkdownParser.Models.Segments.Indicators; | ||
|
||
namespace MarkdownParser.Models | ||
{ | ||
public static class TextSegmentHelper | ||
{ | ||
public static string TextSegmentsToLiteralContent(BaseSegment[] segments, string optionalLineBreak) | ||
{ | ||
var literalContentBuilder = new StringBuilder(); | ||
|
||
if (segments == null | ||
|| !segments.Any(x => x.HasLiteralContent)) | ||
{ | ||
return string.Empty; | ||
} | ||
|
||
for (var i = 0; i < segments.Length; i++) | ||
{ | ||
var literalContent = segments[i].ToString(); | ||
if (segments[i] is IndicatorSegment indicatorSegment | ||
&& indicatorSegment.Indicator == SegmentIndicator.LineBreak) | ||
{ | ||
literalContent = optionalLineBreak; | ||
} | ||
|
||
literalContentBuilder.Append(literalContent); | ||
} | ||
|
||
return literalContentBuilder.ToString(); | ||
} | ||
} | ||
} |
Oops, something went wrong.