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>
|
2016-02-15 06:54:14 +09:00
|
|
|
public class CodeBlock : LeafBlock
|
2016-02-10 00:54:08 +09:00
|
|
|
{
|
2016-02-15 06:58:16 +09:00
|
|
|
public static readonly BlockParser Parser = new ParserInternal();
|
2016-02-10 00:54:08 +09:00
|
|
|
|
2016-02-17 20:45:04 +09:00
|
|
|
public CodeBlock()
|
|
|
|
|
{
|
|
|
|
|
NoInline = true;
|
|
|
|
|
}
|
2016-02-10 00:54:08 +09:00
|
|
|
|
2016-02-15 06:58:16 +09:00
|
|
|
private class ParserInternal : BlockParser
|
2016-02-10 00:54:08 +09:00
|
|
|
{
|
2016-02-15 07:28:15 +09:00
|
|
|
public ParserInternal()
|
2016-02-10 00:54:08 +09:00
|
|
|
{
|
2016-02-15 07:28:15 +09:00
|
|
|
CanInterruptParagraph = false;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-19 05:39:15 +09:00
|
|
|
public override MatchLineResult Match(MatchLineState state)
|
2016-02-15 07:28:15 +09:00
|
|
|
{
|
2016-02-17 01:00:26 +09:00
|
|
|
var liner = state.Line;
|
2016-02-15 07:28:15 +09:00
|
|
|
int position = liner.Start;
|
2016-02-10 20:30:38 +09:00
|
|
|
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);
|
2016-02-15 07:28:15 +09:00
|
|
|
if ((isTab || (isSpace && (liner.Start - position) == 3)) && !liner.IsBlankLine())
|
2016-02-10 00:54:08 +09:00
|
|
|
{
|
|
|
|
|
liner.NextChar();
|
2016-02-15 07:28:15 +09:00
|
|
|
if (state.Block == null)
|
2016-02-15 00:34:21 +09:00
|
|
|
{
|
2016-02-15 07:28:15 +09:00
|
|
|
state.Block = new CodeBlock();
|
2016-02-15 00:34:21 +09:00
|
|
|
}
|
2016-02-15 06:58:16 +09:00
|
|
|
return MatchLineResult.Continue;
|
2016-02-10 00:54:08 +09:00
|
|
|
}
|
|
|
|
|
|
2016-02-15 06:58:16 +09:00
|
|
|
return MatchLineResult.None;
|
2016-02-10 00:54:08 +09:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|