-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e773b63
commit acd1509
Showing
10 changed files
with
172 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Copyright (c) Josef Pihrt. All rights reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
namespace Orang.CommandLine; | ||
|
||
internal readonly record struct CaptureSlim(string Value, int Index, int Length); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// Copyright (c) Josef Pihrt. All rights reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using Markdig; | ||
using Markdig.Extensions.CustomContainers; | ||
using Markdig.Extensions.Tables; | ||
using Markdig.Helpers; | ||
using Markdig.Syntax; | ||
using Markdig.Syntax.Inlines; | ||
|
||
namespace Orang.CommandLine; | ||
|
||
internal static class MarkdownProcessor | ||
{ | ||
private static readonly MarkdownPipeline _pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build(); | ||
|
||
public static IEnumerable<CaptureSlim> ProcessText(string text) | ||
{ | ||
MarkdownDocument document = Markdown.Parse(text, _pipeline); | ||
|
||
foreach (MarkdownObject item in document.Descendants()) | ||
{ | ||
switch (item) | ||
{ | ||
case CodeInline code: | ||
{ | ||
yield return new CaptureSlim(code.Content, code.Span.Start + code.DelimiterCount, code.Span.Length); | ||
break; | ||
} | ||
case LiteralInline literal: | ||
{ | ||
string value = literal.Content.ToString(); | ||
SourceSpan span = literal.Span; | ||
int offset = (literal.IsFirstCharacterEscaped) ? 1 : 0; | ||
|
||
yield return new CaptureSlim(value, span.Start + offset, span.Length + offset); | ||
break; | ||
} | ||
case LinkInline link: | ||
{ | ||
string? label = link.Label; | ||
string? title = link.Title; | ||
|
||
if (!string.IsNullOrEmpty(label)) | ||
yield return new CaptureSlim(label, link.LabelSpan.Start, link.LabelSpan.Length); | ||
|
||
if (!string.IsNullOrEmpty(title)) | ||
yield return new CaptureSlim(title, link.TitleSpan.Start, link.TitleSpan.Length); | ||
|
||
break; | ||
} | ||
case LinkReferenceDefinition linkReferenceDef: | ||
{ | ||
string? label = linkReferenceDef.Label; | ||
string? title = linkReferenceDef.Title; | ||
|
||
if (!string.IsNullOrEmpty(label)) | ||
yield return new CaptureSlim(label, linkReferenceDef.LabelSpan.Start, linkReferenceDef.LabelSpan.Length); | ||
|
||
if (!string.IsNullOrEmpty(title)) | ||
yield return new CaptureSlim(title, linkReferenceDef.TitleSpan.Start, linkReferenceDef.TitleSpan.Length); | ||
|
||
break; | ||
} | ||
case CodeBlock codeBlock: | ||
{ | ||
foreach (StringLine line in codeBlock.Lines.Lines) | ||
{ | ||
StringSlice slice = line.Slice; | ||
yield return new CaptureSlim(slice.ToString(), slice.Start, slice.Length); | ||
} | ||
|
||
break; | ||
} | ||
case ContainerInline: // EmphasisInline, DelimiterInline, EmphasisDelimiterInline, LinkDelimiterInline | ||
case AutolinkInline: | ||
case HtmlEntityInline: | ||
case LineBreakInline: | ||
case HtmlInline: | ||
case HeadingBlock: | ||
case ListBlock: | ||
case ListItemBlock: | ||
case ParagraphBlock: | ||
case ThematicBreakBlock: | ||
case LinkReferenceDefinitionGroup: | ||
case Table: | ||
case TableRow: | ||
case TableCell: | ||
case QuoteBlock: | ||
case CustomContainer: | ||
{ | ||
break; | ||
} | ||
default: | ||
{ | ||
Debug.Fail(item.GetType().FullName); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright (c) Josef Pihrt. All rights reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
namespace System.Runtime.CompilerServices; | ||
|
||
using global::System.ComponentModel; | ||
|
||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
internal static class IsExternalInit | ||
{ | ||
} |