-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMarkdownOfThings.cs
59 lines (51 loc) · 1.88 KB
/
MarkdownOfThings.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using Microsoft.DocAsCode.MarkdownLite;
using Microsoft.DocAsCode.MarkdownLite.Matchers;
namespace WPF_dnscrypt_proxy_md
{
public class SDNSBlockToken : IMarkdownToken
{
public SDNSBlockToken(IMarkdownRule rule, IMarkdownContext context, SourceInfo sourceInfo, string text)
{
Rule = rule;
Context = context;
SourceInfo = sourceInfo;
Text = text;
}
public IMarkdownRule Rule { get; }
public IMarkdownContext Context { get; }
public SourceInfo SourceInfo { get; }
public string Text { get; }
}
public class SDNSBlockRule : IMarkdownRule
{
private static readonly Matcher _sdnsMatcher =
Matcher.WhiteSpacesOrEmpty +
(Matcher.String("sdns://").Repeat(1, 1) +
(Matcher.Char('-')
| Matcher.Char('_')
| Matcher.AnyCharInRange('a', 'z')
| Matcher.AnyCharInRange('A', 'Z')
| Matcher.AnyCharInRange('0', '9')).RepeatAtLeast(13)).ToGroup("text") +
Matcher.Char('\n');
public virtual string Name => "SDNS";
public virtual IMarkdownToken TryMatch(IMarkdownParser parser, IMarkdownParsingContext context)
{
var match = context.Match(_sdnsMatcher);
return match?.Length > 0 ? new SDNSBlockToken(
this,
parser.Context,
context.Consume(match.Length),
match.GetGroup("text").Value.GetValue()) : null;
}
}
/// <summary>
/// let's insist on the original style of ms renderer. have fun :)
/// </summary>
public class InsetSDNSMarkdownRenderer : MarkdownRenderer
{
public virtual StringBuffer Render(IMarkdownRenderer render, SDNSBlockToken token, IMarkdownContext context)
{
return $"{token.Text}\n";
}
}
}