diff --git a/Cyjb.Markdown/ParseBlock/BlockParser.cs b/Cyjb.Markdown/ParseBlock/BlockParser.cs index 1b2d351..7856aa0 100644 --- a/Cyjb.Markdown/ParseBlock/BlockParser.cs +++ b/Cyjb.Markdown/ParseBlock/BlockParser.cs @@ -130,7 +130,7 @@ public BlockParser(TextReader text, ParseOptions? options) public Document Parse() { Token token; - LineInfo line = new(this, locator); + BlockText line = new(this, locator); while (true) { // 清除行的旧数据。 @@ -204,7 +204,7 @@ public Document Parse() /// 解析指定行。 /// /// 要解析的行。 - private void ParseLine(LineInfo line) + private void ParseLine(BlockText line) { int lineStart = line.Start; // 栈底总是 document,总是可以接受任何行,因此总是跳过。 diff --git a/Cyjb.Markdown/ParseBlock/LineInfo.cs b/Cyjb.Markdown/ParseBlock/BlockText.cs similarity index 94% rename from Cyjb.Markdown/ParseBlock/LineInfo.cs rename to Cyjb.Markdown/ParseBlock/BlockText.cs index 7fbb48e..6cc42aa 100644 --- a/Cyjb.Markdown/ParseBlock/LineInfo.cs +++ b/Cyjb.Markdown/ParseBlock/BlockText.cs @@ -7,7 +7,7 @@ namespace Cyjb.Markdown.ParseBlock; /// /// 行的信息。 /// -internal sealed class LineInfo +internal sealed class BlockText { /// /// 代码缩进长度。 @@ -64,11 +64,11 @@ internal sealed class LineInfo private int indentEndColumn; /// - /// 使用指定的行定位器初始化 类的新实例。 + /// 使用指定的行定位器初始化 类的新实例。 /// /// 块解析器。 /// 行定位器。 - internal LineInfo(BlockParser parser, LineLocator locator) + internal BlockText(BlockParser parser, LineLocator locator) { this.parser = parser; this.locator = locator; diff --git a/Cyjb.Markdown/ParseBlock/Processors/ATXHeadingProcessor.cs b/Cyjb.Markdown/ParseBlock/Processors/ATXHeadingProcessor.cs index 392fe19..839224f 100644 --- a/Cyjb.Markdown/ParseBlock/Processors/ATXHeadingProcessor.cs +++ b/Cyjb.Markdown/ParseBlock/Processors/ATXHeadingProcessor.cs @@ -53,7 +53,7 @@ private ATXHeadingProcessor(int start, int depth, MappedText text, HtmlAttribute /// /// 要检查的行。 /// 当前节点是否可以延伸到下一行。 - public override BlockContinue TryContinue(LineInfo line) + public override BlockContinue TryContinue(BlockText line) { return BlockContinue.None; } @@ -91,7 +91,7 @@ private sealed class BlockFactory : IBlockFactory /// 要检查的行。 /// 当前匹配到的块处理器。 /// 如果能够开始当前块的解析,则返回解析器序列。否则返回空序列。 - public IEnumerable TryStart(LineInfo line, BlockProcessor matchedProcessor) + public IEnumerable TryStart(BlockText line, BlockProcessor matchedProcessor) { if (line.IsCodeIndent) { diff --git a/Cyjb.Markdown/ParseBlock/Processors/BlockProcessor.cs b/Cyjb.Markdown/ParseBlock/Processors/BlockProcessor.cs index 0acfaeb..47161d9 100644 --- a/Cyjb.Markdown/ParseBlock/Processors/BlockProcessor.cs +++ b/Cyjb.Markdown/ParseBlock/Processors/BlockProcessor.cs @@ -77,13 +77,13 @@ public void NeedReplace() /// /// 要检查的行。 /// 当前节点是否可以延伸到下一行。 - public abstract BlockContinue TryContinue(LineInfo line); + public abstract BlockContinue TryContinue(BlockText line); /// /// 添加一个新行。 /// /// 新添加的行。 - public virtual void AddLine(LineInfo line) { } + public virtual void AddLine(BlockText line) { } /// /// 返回当前节点是否可以包含指定类型的子节点。 diff --git a/Cyjb.Markdown/ParseBlock/Processors/BlockquoteProcessor.cs b/Cyjb.Markdown/ParseBlock/Processors/BlockquoteProcessor.cs index ac658eb..e117e70 100644 --- a/Cyjb.Markdown/ParseBlock/Processors/BlockquoteProcessor.cs +++ b/Cyjb.Markdown/ParseBlock/Processors/BlockquoteProcessor.cs @@ -37,7 +37,7 @@ private BlockquoteProcessor(int start) : base(MarkdownKind.Blockquote) /// /// 要检查的行。 /// 当前节点是否可以延伸到下一行。 - public override BlockContinue TryContinue(LineInfo line) + public override BlockContinue TryContinue(BlockText line) { return CheckQuoteStart(line) ? BlockContinue.Continue : BlockContinue.None; } @@ -81,7 +81,7 @@ public override void AddNode(Node node) /// /// 要检查的行。 /// 如果找到了块引用起始标记,则为 true;否则为 false - private static bool CheckQuoteStart(LineInfo line) + private static bool CheckQuoteStart(BlockText line) { if (line.IsCodeIndent || line.Peek().Kind != BlockKind.QuoteStart) { @@ -107,7 +107,7 @@ private sealed class BlockFactory : IBlockFactory /// 要检查的行。 /// 当前匹配到的块处理器。 /// 如果能够开始当前块的解析,则返回解析器序列。否则返回空序列。 - public IEnumerable TryStart(LineInfo line, BlockProcessor matchedProcessor) + public IEnumerable TryStart(BlockText line, BlockProcessor matchedProcessor) { int start = line.Peek().Span.Start; if (CheckQuoteStart(line)) diff --git a/Cyjb.Markdown/ParseBlock/Processors/CustomContainerProcessor.cs b/Cyjb.Markdown/ParseBlock/Processors/CustomContainerProcessor.cs index 62a2caa..3accbb5 100644 --- a/Cyjb.Markdown/ParseBlock/Processors/CustomContainerProcessor.cs +++ b/Cyjb.Markdown/ParseBlock/Processors/CustomContainerProcessor.cs @@ -55,7 +55,7 @@ private CustomContainerProcessor(int start, int fenceLength, string? info, HtmlA /// /// 要检查的行。 /// 当前节点是否可以延伸到下一行。 - public override BlockContinue TryContinue(LineInfo line) + public override BlockContinue TryContinue(BlockText line) { if (!line.IsCodeIndent) { @@ -111,7 +111,7 @@ private sealed class BlockFactory : IBlockFactory /// 要检查的行。 /// 当前匹配到的块处理器。 /// 如果能够开始当前块的解析,则返回解析器序列。否则返回空序列。 - public IEnumerable TryStart(LineInfo line, BlockProcessor matchedProcessor) + public IEnumerable TryStart(BlockText line, BlockProcessor matchedProcessor) { if (line.IsCodeIndent) { diff --git a/Cyjb.Markdown/ParseBlock/Processors/DocumentProcessor.cs b/Cyjb.Markdown/ParseBlock/Processors/DocumentProcessor.cs index f44914d..7273016 100644 --- a/Cyjb.Markdown/ParseBlock/Processors/DocumentProcessor.cs +++ b/Cyjb.Markdown/ParseBlock/Processors/DocumentProcessor.cs @@ -28,7 +28,7 @@ public DocumentProcessor() : base(MarkdownKind.Document) { } /// /// 要检查的行。 /// 当前节点是否可以延伸到下一行。 - public override BlockContinue TryContinue(LineInfo line) + public override BlockContinue TryContinue(BlockText line) { return BlockContinue.Continue; } diff --git a/Cyjb.Markdown/ParseBlock/Processors/FencedCodeBlockProcessor.cs b/Cyjb.Markdown/ParseBlock/Processors/FencedCodeBlockProcessor.cs index 0096bf2..267a263 100644 --- a/Cyjb.Markdown/ParseBlock/Processors/FencedCodeBlockProcessor.cs +++ b/Cyjb.Markdown/ParseBlock/Processors/FencedCodeBlockProcessor.cs @@ -67,7 +67,7 @@ private FencedCodeBlockProcessor(int start, /// /// 要检查的行。 /// 当前节点是否可以延伸到下一行。 - public override BlockContinue TryContinue(LineInfo line) + public override BlockContinue TryContinue(BlockText line) { if (!line.IsCodeIndent) { @@ -87,7 +87,7 @@ public override BlockContinue TryContinue(LineInfo line) /// 添加一个新行。 /// /// 新添加的行。 - public override void AddLine(LineInfo line) + public override void AddLine(BlockText line) { line.AppendTo(builder); } @@ -117,7 +117,7 @@ private sealed class BlockFactory : IBlockFactory /// 要检查的行。 /// 当前匹配到的块处理器。 /// 如果能够开始当前块的解析,则返回解析器序列。否则返回空序列。 - public IEnumerable TryStart(LineInfo line, BlockProcessor matchedProcessor) + public IEnumerable TryStart(BlockText line, BlockProcessor matchedProcessor) { if (line.IsCodeIndent) { diff --git a/Cyjb.Markdown/ParseBlock/Processors/FootnoteProcessor.cs b/Cyjb.Markdown/ParseBlock/Processors/FootnoteProcessor.cs index 2932dc1..6997dba 100644 --- a/Cyjb.Markdown/ParseBlock/Processors/FootnoteProcessor.cs +++ b/Cyjb.Markdown/ParseBlock/Processors/FootnoteProcessor.cs @@ -45,13 +45,13 @@ private FootnoteProcessor(int start, int end, string label) /// /// 要检查的行。 /// 当前节点是否可以延伸到下一行。 - public override BlockContinue TryContinue(LineInfo line) + public override BlockContinue TryContinue(BlockText line) { if (line.IsCodeIndent || line.IsBlank()) { // 缩进会被认为是脚注的一部分,这时要吃掉 4 个缩进。 // 空白行也是脚注的一部分。 - line.SkipIndent(LineInfo.CodeIndent); + line.SkipIndent(BlockText.CodeIndent); return BlockContinue.Continue; } else @@ -108,7 +108,7 @@ private sealed class BlockFactory : IBlockFactory /// 要检查的行。 /// 当前匹配到的块处理器。 /// 如果能够开始当前块的解析,则返回解析器序列。否则返回空序列。 - public IEnumerable TryStart(LineInfo line, BlockProcessor matchedProcessor) + public IEnumerable TryStart(BlockText line, BlockProcessor matchedProcessor) { if (line.IsCodeIndent) { diff --git a/Cyjb.Markdown/ParseBlock/Processors/HtmlBlockProcessor.cs b/Cyjb.Markdown/ParseBlock/Processors/HtmlBlockProcessor.cs index c4b3b38..5ec0e36 100644 --- a/Cyjb.Markdown/ParseBlock/Processors/HtmlBlockProcessor.cs +++ b/Cyjb.Markdown/ParseBlock/Processors/HtmlBlockProcessor.cs @@ -49,7 +49,7 @@ private HtmlBlockProcessor(int start, HtmlInfo info) /// /// 要检查的行。 /// 当前节点是否可以延伸到下一行。 - public override BlockContinue TryContinue(LineInfo line) + public override BlockContinue TryContinue(BlockText line) { if (finished) { @@ -70,7 +70,7 @@ public override BlockContinue TryContinue(LineInfo line) /// 添加一个新行。 /// /// 新添加的行。 - public override void AddLine(LineInfo line) + public override void AddLine(BlockText line) { int start = builder.Length; line.AppendTo(builder); @@ -101,7 +101,7 @@ private sealed class BlockFactory : IBlockFactory /// 要检查的行。 /// 当前匹配到的块处理器。 /// 如果能够开始当前块的解析,则返回解析器序列。否则返回空序列。 - public IEnumerable TryStart(LineInfo line, BlockProcessor matchedProcessor) + public IEnumerable TryStart(BlockText line, BlockProcessor matchedProcessor) { if (line.IsCodeIndent) { diff --git a/Cyjb.Markdown/ParseBlock/Processors/IBlockFactory.cs b/Cyjb.Markdown/ParseBlock/Processors/IBlockFactory.cs index dc9cf3a..9d4c18a 100644 --- a/Cyjb.Markdown/ParseBlock/Processors/IBlockFactory.cs +++ b/Cyjb.Markdown/ParseBlock/Processors/IBlockFactory.cs @@ -11,5 +11,5 @@ internal interface IBlockFactory /// 要检查的行。 /// 当前匹配到的块处理器。 /// 如果能够开始当前块的解析,则返回解析器序列。否则返回空序列。 - IEnumerable TryStart(LineInfo line, BlockProcessor matchedProcessor); + IEnumerable TryStart(BlockText line, BlockProcessor matchedProcessor); } diff --git a/Cyjb.Markdown/ParseBlock/Processors/IndentedCodeBlockProcessor.cs b/Cyjb.Markdown/ParseBlock/Processors/IndentedCodeBlockProcessor.cs index 85672c4..573a50e 100644 --- a/Cyjb.Markdown/ParseBlock/Processors/IndentedCodeBlockProcessor.cs +++ b/Cyjb.Markdown/ParseBlock/Processors/IndentedCodeBlockProcessor.cs @@ -15,7 +15,7 @@ internal class IndentedCodeBlockProcessor : BlockProcessor /// /// 要检查的行。 /// 新的块处理器数组,若未能成功解析,则返回空数组。 - public static IEnumerable TryStart(LineInfo line) + public static IEnumerable TryStart(BlockText line) { // 缩进代码块不会中断段落。 if (line.IsCodeIndent && !line.IsBlank() && @@ -24,7 +24,7 @@ public static IEnumerable TryStart(LineInfo line) // 代码块的起始位置包含缩进位置。 int start = line.Start; // 跳过空白部分。 - line.SkipIndent(LineInfo.CodeIndent); + line.SkipIndent(BlockText.CodeIndent); yield return new IndentedCodeBlockProcessor(start, line.End); } } @@ -62,19 +62,19 @@ private IndentedCodeBlockProcessor(int start, int end) : base(MarkdownKind.CodeB /// /// 要检查的行。 /// 当前节点是否可以延伸到下一行。 - public override BlockContinue TryContinue(LineInfo line) + public override BlockContinue TryContinue(BlockText line) { if (line.IsCodeIndent) { // 跳过空白部分。 - line.SkipIndent(LineInfo.CodeIndent); + line.SkipIndent(BlockText.CodeIndent); end = line.End; return BlockContinue.Continue; } else if (line.IsBlank()) { // 跳过空白部分,但暂时不计入结尾。 - line.SkipIndent(LineInfo.CodeIndent); + line.SkipIndent(BlockText.CodeIndent); return BlockContinue.Continue; } else @@ -87,7 +87,7 @@ public override BlockContinue TryContinue(LineInfo line) /// 添加一个新行。 /// /// 新添加的行。 - public override void AddLine(LineInfo line) + public override void AddLine(BlockText line) { line.AppendTo(builder); if (!line.IsBlank()) diff --git a/Cyjb.Markdown/ParseBlock/Processors/ListItemProcessor.cs b/Cyjb.Markdown/ParseBlock/Processors/ListItemProcessor.cs index 1c4f754..da30ecd 100644 --- a/Cyjb.Markdown/ParseBlock/Processors/ListItemProcessor.cs +++ b/Cyjb.Markdown/ParseBlock/Processors/ListItemProcessor.cs @@ -71,7 +71,7 @@ public bool? Checked /// /// 要检查的行。 /// 当前节点是否可以延伸到下一行。 - public override BlockContinue TryContinue(LineInfo line) + public override BlockContinue TryContinue(BlockText line) { if (line.IsBlank()) { diff --git a/Cyjb.Markdown/ParseBlock/Processors/ListProcessor.cs b/Cyjb.Markdown/ParseBlock/Processors/ListProcessor.cs index f6b4154..75f1822 100644 --- a/Cyjb.Markdown/ParseBlock/Processors/ListProcessor.cs +++ b/Cyjb.Markdown/ParseBlock/Processors/ListProcessor.cs @@ -74,7 +74,7 @@ public void MarkLoose() /// /// 要检查的行。 /// 当前节点是否可以延伸到下一行。 - public override BlockContinue TryContinue(LineInfo line) + public override BlockContinue TryContinue(BlockText line) { if (line.IsBlank()) { @@ -175,7 +175,7 @@ private sealed class BlockFactory : IBlockFactory /// 要检查的行。 /// 当前匹配到的块处理器。 /// 如果能够开始当前块的解析,则返回解析器序列。否则返回空序列。 - public IEnumerable TryStart(LineInfo line, BlockProcessor matchedProcessor) + public IEnumerable TryStart(BlockText line, BlockProcessor matchedProcessor) { if (line.IsCodeIndent) { @@ -203,7 +203,7 @@ public IEnumerable TryStart(LineInfo line, BlockProcessor matche line.Read(); int contentIndent = indentAfterMarker + line.Indent; // 如果没有内容或者是代码段,那么认为内容缩进是列表项后一个字符位置。 - if (!hasContent || contentIndent - indentAfterMarker > LineInfo.CodeIndent) + if (!hasContent || contentIndent - indentAfterMarker > BlockText.CodeIndent) { contentIndent = indentAfterMarker + 1; // 只跳过 marker 后的一个空白。 @@ -307,7 +307,7 @@ private static int ParseRomain(ReadOnlySpan text) /// 要检查的行。 /// 如果当前行包含任务列表项,根据是否勾选返回 truefalse; /// 如果不包含任务列表项,返回 null - private static bool? CheckTaskListItem(LineInfo line) + private static bool? CheckTaskListItem(BlockText line) { // 检查包含任务列表项标志 if (line.Indent >= 4 || line.IsBlank()) diff --git a/Cyjb.Markdown/ParseBlock/Processors/MathBlockProcessor.cs b/Cyjb.Markdown/ParseBlock/Processors/MathBlockProcessor.cs index ffe3298..87b1e02 100644 --- a/Cyjb.Markdown/ParseBlock/Processors/MathBlockProcessor.cs +++ b/Cyjb.Markdown/ParseBlock/Processors/MathBlockProcessor.cs @@ -60,7 +60,7 @@ private MathBlockProcessor(int start, int fenceLength, int indent, string? info, /// /// 要检查的行。 /// 当前节点是否可以延伸到下一行。 - public override BlockContinue TryContinue(LineInfo line) + public override BlockContinue TryContinue(BlockText line) { if (!line.IsCodeIndent) { @@ -80,7 +80,7 @@ public override BlockContinue TryContinue(LineInfo line) /// 添加一个新行。 /// /// 新添加的行。 - public override void AddLine(LineInfo line) + public override void AddLine(BlockText line) { line.AppendTo(builder); } @@ -110,7 +110,7 @@ private sealed class BlockFactory : IBlockFactory /// 要检查的行。 /// 当前匹配到的块处理器。 /// 如果能够开始当前块的解析,则返回解析器序列。否则返回空序列。 - public IEnumerable TryStart(LineInfo line, BlockProcessor matchedProcessor) + public IEnumerable TryStart(BlockText line, BlockProcessor matchedProcessor) { if (line.IsCodeIndent) { diff --git a/Cyjb.Markdown/ParseBlock/Processors/ParagraphProcessor.cs b/Cyjb.Markdown/ParseBlock/Processors/ParagraphProcessor.cs index efd6f63..b822640 100644 --- a/Cyjb.Markdown/ParseBlock/Processors/ParagraphProcessor.cs +++ b/Cyjb.Markdown/ParseBlock/Processors/ParagraphProcessor.cs @@ -71,7 +71,7 @@ public ParagraphProcessor(ParseOptions options) : base(MarkdownKind.Paragraph) /// /// 要检查的行。 /// 当前节点是否可以延伸到下一行。 - public override BlockContinue TryContinue(LineInfo line) + public override BlockContinue TryContinue(BlockText line) { return line.IsBlank() ? BlockContinue.None : BlockContinue.Continue; } @@ -80,7 +80,7 @@ public override BlockContinue TryContinue(LineInfo line) /// 添加一个新行。 /// /// 新添加的行。 - public override void AddLine(LineInfo line) + public override void AddLine(BlockText line) { // 在之前的文本被识别为链接声明后,需要移除新的行首空白。 if (trimStart) diff --git a/Cyjb.Markdown/ParseBlock/Processors/SetextHeadingProcessor.cs b/Cyjb.Markdown/ParseBlock/Processors/SetextHeadingProcessor.cs index 99a7eab..f5b6e94 100644 --- a/Cyjb.Markdown/ParseBlock/Processors/SetextHeadingProcessor.cs +++ b/Cyjb.Markdown/ParseBlock/Processors/SetextHeadingProcessor.cs @@ -55,7 +55,7 @@ private SetextHeadingProcessor(int start, int depth, IList text, Htm /// /// 要检查的行。 /// 当前节点是否可以延伸到下一行。 - public override BlockContinue TryContinue(LineInfo line) + public override BlockContinue TryContinue(BlockText line) { return BlockContinue.None; } @@ -94,7 +94,7 @@ private sealed class BlockFactory : IBlockFactory /// 要检查的行。 /// 当前匹配到的块处理器。 /// 如果能够开始当前块的解析,则返回解析器序列。否则返回空序列。 - public IEnumerable TryStart(LineInfo line, BlockProcessor matchedProcessor) + public IEnumerable TryStart(BlockText line, BlockProcessor matchedProcessor) { // 要求 Setext 标签之前是段落,而且包含有效内容。 IList? lines; diff --git a/Cyjb.Markdown/ParseBlock/Processors/TableProcessor.cs b/Cyjb.Markdown/ParseBlock/Processors/TableProcessor.cs index a27b932..7907a1b 100644 --- a/Cyjb.Markdown/ParseBlock/Processors/TableProcessor.cs +++ b/Cyjb.Markdown/ParseBlock/Processors/TableProcessor.cs @@ -63,7 +63,7 @@ private TableProcessor(List aligns, MappedText heading) /// /// 要检查的行。 /// 当前节点是否可以延伸到下一行。 - public override BlockContinue TryContinue(LineInfo line) + public override BlockContinue TryContinue(BlockText line) { return line.IsBlank() ? BlockContinue.None : BlockContinue.Continue; } @@ -72,7 +72,7 @@ public override BlockContinue TryContinue(LineInfo line) /// 添加一个新行。 /// /// 新添加的行。 - public override void AddLine(LineInfo line) + public override void AddLine(BlockText line) { table.Children.Add(ParseRow(line.Text)); } @@ -233,7 +233,7 @@ private sealed class BlockFactory : IBlockFactory /// 要检查的行。 /// 当前匹配到的块处理器。 /// 如果能够开始当前块的解析,则返回解析器序列。否则返回空序列。 - public IEnumerable TryStart(LineInfo line, BlockProcessor matchedProcessor) + public IEnumerable TryStart(BlockText line, BlockProcessor matchedProcessor) { // 要求分割行之前是段落,而且包含且只包含一行。 IList? lines; diff --git a/Cyjb.Markdown/ParseBlock/Processors/ThematicBreakProcessor.cs b/Cyjb.Markdown/ParseBlock/Processors/ThematicBreakProcessor.cs index 531da06..5784d55 100644 --- a/Cyjb.Markdown/ParseBlock/Processors/ThematicBreakProcessor.cs +++ b/Cyjb.Markdown/ParseBlock/Processors/ThematicBreakProcessor.cs @@ -32,7 +32,7 @@ private ThematicBreakProcessor(int start) : base(MarkdownKind.ThematicBreak) /// /// 要检查的行。 /// 当前节点是否可以延伸到下一行。 - public override BlockContinue TryContinue(LineInfo line) + public override BlockContinue TryContinue(BlockText line) { return BlockContinue.None; } @@ -59,7 +59,7 @@ private sealed class BlockFactory : IBlockFactory /// 要检查的行。 /// 当前匹配到的块处理器。 /// 如果能够开始当前块的解析,则返回处理器序列。否则返回空序列。 - public IEnumerable TryStart(LineInfo line, BlockProcessor matchedProcessor) + public IEnumerable TryStart(BlockText line, BlockProcessor matchedProcessor) { if (line.IsCodeIndent) { diff --git a/Cyjb.Markdown/Utils/MarkdownUtil.Fence.cs b/Cyjb.Markdown/Utils/MarkdownUtil.Fence.cs index 42ff1b5..daf0ae1 100644 --- a/Cyjb.Markdown/Utils/MarkdownUtil.Fence.cs +++ b/Cyjb.Markdown/Utils/MarkdownUtil.Fence.cs @@ -36,7 +36,7 @@ public static int GetFenceLength(ReadOnlySpan text) /// 分隔符的长度。 /// 分隔符的信息。 /// 分隔符的属性。 - public static void ParseFenceStart(LineInfo line, out int start, out int indent, + public static void ParseFenceStart(BlockText line, out int start, out int indent, out char fenceChar, out int fenceLength, out string? info, out HtmlAttributeList? attrs) {