-
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.
[build command] enable to generate a rss feed and a JSON index of doc…
…uments
- Loading branch information
1 parent
0416a19
commit a522897
Showing
6 changed files
with
493 additions
and
5 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,125 @@ | ||
using System.Text; | ||
using NAsciidoc.Model; | ||
using NAsciidoc.Renderer; | ||
|
||
namespace SBSharp.Core.Asciidoc; | ||
|
||
// todo: enhance for cases where part of words are formatted, ex: *S*BSharp, shouldn't render as "S\nBSharp" but "SBSHarp" | ||
public class TextRenderer : Visitor<string> | ||
{ | ||
private readonly StringBuilder builder = new(); | ||
|
||
public override void VisitAdmonition(Admonition element) | ||
{ | ||
string name = Enum.GetName(element.Level)!; | ||
builder.Append(name).Append(": "); | ||
VisitElement(element.Content); | ||
builder.Append('\n'); | ||
} | ||
|
||
public override void VisitHeader(Header header) | ||
{ | ||
builder.Append(header.Title).Append('\n'); | ||
} | ||
|
||
public override void VisitSection(Section element) | ||
{ | ||
VisitElement(element.Title); | ||
builder.Append('\n'); | ||
base.VisitSection(element); | ||
builder.Append('\n'); | ||
} | ||
|
||
public override void VisitLink(Link element) | ||
{ | ||
builder.Append(element.Label).Append('\n'); | ||
} | ||
|
||
public override void VisitDescriptionList(DescriptionList element) | ||
{ | ||
foreach (var it in element.Children) | ||
{ | ||
VisitElement(it.Key); | ||
VisitElement(it.Value); | ||
} | ||
builder.Append('\n'); | ||
} | ||
|
||
public override void VisitUnOrderedList(UnOrderedList element) | ||
{ | ||
foreach (var it in element.Children) | ||
{ | ||
VisitElement(it); | ||
} | ||
builder.Append('\n'); | ||
} | ||
|
||
public override void VisitOrderedList(OrderedList element) | ||
{ | ||
foreach (var it in element.Children) | ||
{ | ||
VisitElement(it); | ||
} | ||
builder.Append('\n'); | ||
} | ||
|
||
public override void VisitText(Text element) | ||
{ | ||
builder.Append(element.Value).Append('\n'); | ||
} | ||
|
||
public override void VisitQuote(Quote element) | ||
{ | ||
foreach (var it in element.Children) | ||
{ | ||
VisitElement(it); | ||
} | ||
builder.Append('\n'); | ||
} | ||
|
||
public override void VisitCode(Code element) | ||
{ | ||
builder.Append(element.Value).Append('\n'); | ||
} | ||
|
||
public override void VisitTable(Table element) | ||
{ | ||
foreach (var it in element.Elements) | ||
{ | ||
foreach (var e in it) | ||
{ | ||
VisitElement(e); | ||
} | ||
builder.Append('\n'); | ||
} | ||
builder.Append("\n\n"); | ||
} | ||
|
||
public override void VisitAnchor(Anchor element) | ||
{ | ||
builder.Append(element.Label).Append('\n'); | ||
} | ||
|
||
public override void VisitPassthroughBlock(PassthroughBlock element) | ||
{ | ||
// skipped for now since it is generally code/internals | ||
} | ||
|
||
public override void VisitListing(Listing element) | ||
{ | ||
builder.Append(element.Value).Append('\n'); | ||
} | ||
|
||
public override void VisitMacro(Macro element) | ||
{ | ||
if (element.Label.Length > 0) | ||
{ | ||
builder.Append(element.Label).Append('\n'); | ||
} | ||
} | ||
|
||
public override string Result() | ||
{ | ||
return builder.ToString().Trim(); | ||
} | ||
} |
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
Oops, something went wrong.