2016-02-10 20:30:38 +09:00
|
|
|
using System;
|
|
|
|
|
using Textamina.Markdig.Parsing;
|
|
|
|
|
|
|
|
|
|
namespace Textamina.Markdig.Syntax
|
2016-02-10 00:54:08 +09:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Repressents a indented code block.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// Related to CommonMark spec: 4.4 Indented code blocks
|
|
|
|
|
/// </remarks>
|
|
|
|
|
public class CodeBlock : BlockLeaf
|
|
|
|
|
{
|
|
|
|
|
public static readonly BlockMatcher DefaultMatcher = new MatcherInternal();
|
|
|
|
|
|
2016-02-10 20:30:38 +09:00
|
|
|
public CodeBlock() : base(DefaultMatcher)
|
2016-02-10 00:54:08 +09:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class MatcherInternal : BlockMatcher
|
|
|
|
|
{
|
|
|
|
|
public override MatchLineState Match(ref StringLiner liner, MatchLineState matchLineState, ref object matchContext)
|
|
|
|
|
{
|
2016-02-10 20:30:38 +09:00
|
|
|
int position = liner.Column;
|
|
|
|
|
liner.SkipLeadingSpaces3();
|
|
|
|
|
|
2016-02-10 00:54:08 +09:00
|
|
|
// 4.4 Indented code blocks
|
|
|
|
|
var c = liner.Current;
|
2016-02-10 20:30:38 +09:00
|
|
|
var isTab = Utility.IsTab(c);
|
|
|
|
|
var isSpace = Utility.IsSpace(c);
|
|
|
|
|
if ((isTab || (isSpace && (liner.Column - position) == 3)) && !liner.IsBlankLine())
|
2016-02-10 00:54:08 +09:00
|
|
|
{
|
|
|
|
|
liner.NextChar();
|
|
|
|
|
return MatchLineState.Continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return matchLineState == MatchLineState.Continue
|
|
|
|
|
? MatchLineState.Break
|
|
|
|
|
: MatchLineState.Discard;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-10 20:30:38 +09:00
|
|
|
public override Block New()
|
2016-02-10 00:54:08 +09:00
|
|
|
{
|
2016-02-10 20:30:38 +09:00
|
|
|
return new CodeBlock();
|
2016-02-10 00:54:08 +09:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|