Skip to content

Commit

Permalink
feat: 重命名 LineInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
CYJB committed Mar 17, 2024
1 parent fa83b6d commit 667fa8e
Show file tree
Hide file tree
Showing 20 changed files with 49 additions and 49 deletions.
4 changes: 2 additions & 2 deletions Cyjb.Markdown/ParseBlock/BlockParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public BlockParser(TextReader text, ParseOptions? options)
public Document Parse()
{
Token<BlockKind> token;
LineInfo line = new(this, locator);
BlockText line = new(this, locator);
while (true)
{
// 清除行的旧数据。
Expand Down Expand Up @@ -204,7 +204,7 @@ public Document Parse()
/// 解析指定行。
/// </summary>
/// <param name="line">要解析的行。</param>
private void ParseLine(LineInfo line)
private void ParseLine(BlockText line)
{
int lineStart = line.Start;
// 栈底总是 document,总是可以接受任何行,因此总是跳过。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Cyjb.Markdown.ParseBlock;
/// <summary>
/// 行的信息。
/// </summary>
internal sealed class LineInfo
internal sealed class BlockText
{
/// <summary>
/// 代码缩进长度。
Expand Down Expand Up @@ -64,11 +64,11 @@ internal sealed class LineInfo
private int indentEndColumn;

/// <summary>
/// 使用指定的行定位器初始化 <see cref="LineInfo"/> 类的新实例。
/// 使用指定的行定位器初始化 <see cref="BlockText"/> 类的新实例。
/// </summary>
/// <param name="parser">块解析器。</param>
/// <param name="locator">行定位器。</param>
internal LineInfo(BlockParser parser, LineLocator locator)
internal BlockText(BlockParser parser, LineLocator locator)
{
this.parser = parser;
this.locator = locator;
Expand Down
4 changes: 2 additions & 2 deletions Cyjb.Markdown/ParseBlock/Processors/ATXHeadingProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private ATXHeadingProcessor(int start, int depth, MappedText text, HtmlAttribute
/// </summary>
/// <param name="line">要检查的行。</param>
/// <returns>当前节点是否可以延伸到下一行。</returns>
public override BlockContinue TryContinue(LineInfo line)
public override BlockContinue TryContinue(BlockText line)
{
return BlockContinue.None;
}
Expand Down Expand Up @@ -91,7 +91,7 @@ private sealed class BlockFactory : IBlockFactory
/// <param name="line">要检查的行。</param>
/// <param name="matchedProcessor">当前匹配到的块处理器。</param>
/// <returns>如果能够开始当前块的解析,则返回解析器序列。否则返回空序列。</returns>
public IEnumerable<BlockProcessor> TryStart(LineInfo line, BlockProcessor matchedProcessor)
public IEnumerable<BlockProcessor> TryStart(BlockText line, BlockProcessor matchedProcessor)
{
if (line.IsCodeIndent)
{
Expand Down
4 changes: 2 additions & 2 deletions Cyjb.Markdown/ParseBlock/Processors/BlockProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ public void NeedReplace()
/// </summary>
/// <param name="line">要检查的行。</param>
/// <returns>当前节点是否可以延伸到下一行。</returns>
public abstract BlockContinue TryContinue(LineInfo line);
public abstract BlockContinue TryContinue(BlockText line);

/// <summary>
/// 添加一个新行。
/// </summary>
/// <param name="line">新添加的行。</param>
public virtual void AddLine(LineInfo line) { }
public virtual void AddLine(BlockText line) { }

/// <summary>
/// 返回当前节点是否可以包含指定类型的子节点。
Expand Down
6 changes: 3 additions & 3 deletions Cyjb.Markdown/ParseBlock/Processors/BlockquoteProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private BlockquoteProcessor(int start) : base(MarkdownKind.Blockquote)
/// </summary>
/// <param name="line">要检查的行。</param>
/// <returns>当前节点是否可以延伸到下一行。</returns>
public override BlockContinue TryContinue(LineInfo line)
public override BlockContinue TryContinue(BlockText line)
{
return CheckQuoteStart(line) ? BlockContinue.Continue : BlockContinue.None;
}
Expand Down Expand Up @@ -81,7 +81,7 @@ public override void AddNode(Node node)
/// </summary>
/// <param name="line">要检查的行。</param>
/// <returns>如果找到了块引用起始标记,则为 <c>true</c>;否则为 <c>false</c>。</returns>
private static bool CheckQuoteStart(LineInfo line)
private static bool CheckQuoteStart(BlockText line)
{
if (line.IsCodeIndent || line.Peek().Kind != BlockKind.QuoteStart)
{
Expand All @@ -107,7 +107,7 @@ private sealed class BlockFactory : IBlockFactory
/// <param name="line">要检查的行。</param>
/// <param name="matchedProcessor">当前匹配到的块处理器。</param>
/// <returns>如果能够开始当前块的解析,则返回解析器序列。否则返回空序列。</returns>
public IEnumerable<BlockProcessor> TryStart(LineInfo line, BlockProcessor matchedProcessor)
public IEnumerable<BlockProcessor> TryStart(BlockText line, BlockProcessor matchedProcessor)
{
int start = line.Peek().Span.Start;
if (CheckQuoteStart(line))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private CustomContainerProcessor(int start, int fenceLength, string? info, HtmlA
/// </summary>
/// <param name="line">要检查的行。</param>
/// <returns>当前节点是否可以延伸到下一行。</returns>
public override BlockContinue TryContinue(LineInfo line)
public override BlockContinue TryContinue(BlockText line)
{
if (!line.IsCodeIndent)
{
Expand Down Expand Up @@ -111,7 +111,7 @@ private sealed class BlockFactory : IBlockFactory
/// <param name="line">要检查的行。</param>
/// <param name="matchedProcessor">当前匹配到的块处理器。</param>
/// <returns>如果能够开始当前块的解析,则返回解析器序列。否则返回空序列。</returns>
public IEnumerable<BlockProcessor> TryStart(LineInfo line, BlockProcessor matchedProcessor)
public IEnumerable<BlockProcessor> TryStart(BlockText line, BlockProcessor matchedProcessor)
{
if (line.IsCodeIndent)
{
Expand Down
2 changes: 1 addition & 1 deletion Cyjb.Markdown/ParseBlock/Processors/DocumentProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public DocumentProcessor() : base(MarkdownKind.Document) { }
/// </summary>
/// <param name="line">要检查的行。</param>
/// <returns>当前节点是否可以延伸到下一行。</returns>
public override BlockContinue TryContinue(LineInfo line)
public override BlockContinue TryContinue(BlockText line)
{
return BlockContinue.Continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private FencedCodeBlockProcessor(int start,
/// </summary>
/// <param name="line">要检查的行。</param>
/// <returns>当前节点是否可以延伸到下一行。</returns>
public override BlockContinue TryContinue(LineInfo line)
public override BlockContinue TryContinue(BlockText line)
{
if (!line.IsCodeIndent)
{
Expand All @@ -87,7 +87,7 @@ public override BlockContinue TryContinue(LineInfo line)
/// 添加一个新行。
/// </summary>
/// <param name="line">新添加的行。</param>
public override void AddLine(LineInfo line)
public override void AddLine(BlockText line)
{
line.AppendTo(builder);
}
Expand Down Expand Up @@ -117,7 +117,7 @@ private sealed class BlockFactory : IBlockFactory
/// <param name="line">要检查的行。</param>
/// <param name="matchedProcessor">当前匹配到的块处理器。</param>
/// <returns>如果能够开始当前块的解析,则返回解析器序列。否则返回空序列。</returns>
public IEnumerable<BlockProcessor> TryStart(LineInfo line, BlockProcessor matchedProcessor)
public IEnumerable<BlockProcessor> TryStart(BlockText line, BlockProcessor matchedProcessor)
{
if (line.IsCodeIndent)
{
Expand Down
6 changes: 3 additions & 3 deletions Cyjb.Markdown/ParseBlock/Processors/FootnoteProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ private FootnoteProcessor(int start, int end, string label)
/// </summary>
/// <param name="line">要检查的行。</param>
/// <returns>当前节点是否可以延伸到下一行。</returns>
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
Expand Down Expand Up @@ -108,7 +108,7 @@ private sealed class BlockFactory : IBlockFactory
/// <param name="line">要检查的行。</param>
/// <param name="matchedProcessor">当前匹配到的块处理器。</param>
/// <returns>如果能够开始当前块的解析,则返回解析器序列。否则返回空序列。</returns>
public IEnumerable<BlockProcessor> TryStart(LineInfo line, BlockProcessor matchedProcessor)
public IEnumerable<BlockProcessor> TryStart(BlockText line, BlockProcessor matchedProcessor)
{
if (line.IsCodeIndent)
{
Expand Down
6 changes: 3 additions & 3 deletions Cyjb.Markdown/ParseBlock/Processors/HtmlBlockProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private HtmlBlockProcessor(int start, HtmlInfo info)
/// </summary>
/// <param name="line">要检查的行。</param>
/// <returns>当前节点是否可以延伸到下一行。</returns>
public override BlockContinue TryContinue(LineInfo line)
public override BlockContinue TryContinue(BlockText line)
{
if (finished)
{
Expand All @@ -70,7 +70,7 @@ public override BlockContinue TryContinue(LineInfo line)
/// 添加一个新行。
/// </summary>
/// <param name="line">新添加的行。</param>
public override void AddLine(LineInfo line)
public override void AddLine(BlockText line)
{
int start = builder.Length;
line.AppendTo(builder);
Expand Down Expand Up @@ -101,7 +101,7 @@ private sealed class BlockFactory : IBlockFactory
/// <param name="line">要检查的行。</param>
/// <param name="matchedProcessor">当前匹配到的块处理器。</param>
/// <returns>如果能够开始当前块的解析,则返回解析器序列。否则返回空序列。</returns>
public IEnumerable<BlockProcessor> TryStart(LineInfo line, BlockProcessor matchedProcessor)
public IEnumerable<BlockProcessor> TryStart(BlockText line, BlockProcessor matchedProcessor)
{
if (line.IsCodeIndent)
{
Expand Down
2 changes: 1 addition & 1 deletion Cyjb.Markdown/ParseBlock/Processors/IBlockFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ internal interface IBlockFactory
/// <param name="line">要检查的行。</param>
/// <param name="matchedProcessor">当前匹配到的块处理器。</param>
/// <returns>如果能够开始当前块的解析,则返回解析器序列。否则返回空序列。</returns>
IEnumerable<BlockProcessor> TryStart(LineInfo line, BlockProcessor matchedProcessor);
IEnumerable<BlockProcessor> TryStart(BlockText line, BlockProcessor matchedProcessor);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal class IndentedCodeBlockProcessor : BlockProcessor
/// </summary>
/// <param name="line">要检查的行。</param>
/// <returns>新的块处理器数组,若未能成功解析,则返回空数组。</returns>
public static IEnumerable<BlockProcessor> TryStart(LineInfo line)
public static IEnumerable<BlockProcessor> TryStart(BlockText line)
{
// 缩进代码块不会中断段落。
if (line.IsCodeIndent && !line.IsBlank() &&
Expand All @@ -24,7 +24,7 @@ public static IEnumerable<BlockProcessor> TryStart(LineInfo line)
// 代码块的起始位置包含缩进位置。
int start = line.Start;
// 跳过空白部分。
line.SkipIndent(LineInfo.CodeIndent);
line.SkipIndent(BlockText.CodeIndent);
yield return new IndentedCodeBlockProcessor(start, line.End);
}
}
Expand Down Expand Up @@ -62,19 +62,19 @@ private IndentedCodeBlockProcessor(int start, int end) : base(MarkdownKind.CodeB
/// </summary>
/// <param name="line">要检查的行。</param>
/// <returns>当前节点是否可以延伸到下一行。</returns>
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
Expand All @@ -87,7 +87,7 @@ public override BlockContinue TryContinue(LineInfo line)
/// 添加一个新行。
/// </summary>
/// <param name="line">新添加的行。</param>
public override void AddLine(LineInfo line)
public override void AddLine(BlockText line)
{
line.AppendTo(builder);
if (!line.IsBlank())
Expand Down
2 changes: 1 addition & 1 deletion Cyjb.Markdown/ParseBlock/Processors/ListItemProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public bool? Checked
/// </summary>
/// <param name="line">要检查的行。</param>
/// <returns>当前节点是否可以延伸到下一行。</returns>
public override BlockContinue TryContinue(LineInfo line)
public override BlockContinue TryContinue(BlockText line)
{
if (line.IsBlank())
{
Expand Down
8 changes: 4 additions & 4 deletions Cyjb.Markdown/ParseBlock/Processors/ListProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void MarkLoose()
/// </summary>
/// <param name="line">要检查的行。</param>
/// <returns>当前节点是否可以延伸到下一行。</returns>
public override BlockContinue TryContinue(LineInfo line)
public override BlockContinue TryContinue(BlockText line)
{
if (line.IsBlank())
{
Expand Down Expand Up @@ -175,7 +175,7 @@ private sealed class BlockFactory : IBlockFactory
/// <param name="line">要检查的行。</param>
/// <param name="matchedProcessor">当前匹配到的块处理器。</param>
/// <returns>如果能够开始当前块的解析,则返回解析器序列。否则返回空序列。</returns>
public IEnumerable<BlockProcessor> TryStart(LineInfo line, BlockProcessor matchedProcessor)
public IEnumerable<BlockProcessor> TryStart(BlockText line, BlockProcessor matchedProcessor)
{
if (line.IsCodeIndent)
{
Expand Down Expand Up @@ -203,7 +203,7 @@ public IEnumerable<BlockProcessor> 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 后的一个空白。
Expand Down Expand Up @@ -307,7 +307,7 @@ private static int ParseRomain(ReadOnlySpan<char> text)
/// <param name="line">要检查的行。</param>
/// <returns>如果当前行包含任务列表项,根据是否勾选返回 <c>true</c> 或 <c>false</c>;
/// 如果不包含任务列表项,返回 <c>null</c>。</returns>
private static bool? CheckTaskListItem(LineInfo line)
private static bool? CheckTaskListItem(BlockText line)
{
// 检查包含任务列表项标志
if (line.Indent >= 4 || line.IsBlank())
Expand Down
6 changes: 3 additions & 3 deletions Cyjb.Markdown/ParseBlock/Processors/MathBlockProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private MathBlockProcessor(int start, int fenceLength, int indent, string? info,
/// </summary>
/// <param name="line">要检查的行。</param>
/// <returns>当前节点是否可以延伸到下一行。</returns>
public override BlockContinue TryContinue(LineInfo line)
public override BlockContinue TryContinue(BlockText line)
{
if (!line.IsCodeIndent)
{
Expand All @@ -80,7 +80,7 @@ public override BlockContinue TryContinue(LineInfo line)
/// 添加一个新行。
/// </summary>
/// <param name="line">新添加的行。</param>
public override void AddLine(LineInfo line)
public override void AddLine(BlockText line)
{
line.AppendTo(builder);
}
Expand Down Expand Up @@ -110,7 +110,7 @@ private sealed class BlockFactory : IBlockFactory
/// <param name="line">要检查的行。</param>
/// <param name="matchedProcessor">当前匹配到的块处理器。</param>
/// <returns>如果能够开始当前块的解析,则返回解析器序列。否则返回空序列。</returns>
public IEnumerable<BlockProcessor> TryStart(LineInfo line, BlockProcessor matchedProcessor)
public IEnumerable<BlockProcessor> TryStart(BlockText line, BlockProcessor matchedProcessor)
{
if (line.IsCodeIndent)
{
Expand Down
4 changes: 2 additions & 2 deletions Cyjb.Markdown/ParseBlock/Processors/ParagraphProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public ParagraphProcessor(ParseOptions options) : base(MarkdownKind.Paragraph)
/// </summary>
/// <param name="line">要检查的行。</param>
/// <returns>当前节点是否可以延伸到下一行。</returns>
public override BlockContinue TryContinue(LineInfo line)
public override BlockContinue TryContinue(BlockText line)
{
return line.IsBlank() ? BlockContinue.None : BlockContinue.Continue;
}
Expand All @@ -80,7 +80,7 @@ public override BlockContinue TryContinue(LineInfo line)
/// 添加一个新行。
/// </summary>
/// <param name="line">新添加的行。</param>
public override void AddLine(LineInfo line)
public override void AddLine(BlockText line)
{
// 在之前的文本被识别为链接声明后,需要移除新的行首空白。
if (trimStart)
Expand Down
4 changes: 2 additions & 2 deletions Cyjb.Markdown/ParseBlock/Processors/SetextHeadingProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private SetextHeadingProcessor(int start, int depth, IList<MappedText> text, Htm
/// </summary>
/// <param name="line">要检查的行。</param>
/// <returns>当前节点是否可以延伸到下一行。</returns>
public override BlockContinue TryContinue(LineInfo line)
public override BlockContinue TryContinue(BlockText line)
{
return BlockContinue.None;
}
Expand Down Expand Up @@ -94,7 +94,7 @@ private sealed class BlockFactory : IBlockFactory
/// <param name="line">要检查的行。</param>
/// <param name="matchedProcessor">当前匹配到的块处理器。</param>
/// <returns>如果能够开始当前块的解析,则返回解析器序列。否则返回空序列。</returns>
public IEnumerable<BlockProcessor> TryStart(LineInfo line, BlockProcessor matchedProcessor)
public IEnumerable<BlockProcessor> TryStart(BlockText line, BlockProcessor matchedProcessor)
{
// 要求 Setext 标签之前是段落,而且包含有效内容。
IList<MappedText>? lines;
Expand Down
6 changes: 3 additions & 3 deletions Cyjb.Markdown/ParseBlock/Processors/TableProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private TableProcessor(List<TableAlign> aligns, MappedText heading)
/// </summary>
/// <param name="line">要检查的行。</param>
/// <returns>当前节点是否可以延伸到下一行。</returns>
public override BlockContinue TryContinue(LineInfo line)
public override BlockContinue TryContinue(BlockText line)
{
return line.IsBlank() ? BlockContinue.None : BlockContinue.Continue;
}
Expand All @@ -72,7 +72,7 @@ public override BlockContinue TryContinue(LineInfo line)
/// 添加一个新行。
/// </summary>
/// <param name="line">新添加的行。</param>
public override void AddLine(LineInfo line)
public override void AddLine(BlockText line)
{
table.Children.Add(ParseRow(line.Text));
}
Expand Down Expand Up @@ -233,7 +233,7 @@ private sealed class BlockFactory : IBlockFactory
/// <param name="line">要检查的行。</param>
/// <param name="matchedProcessor">当前匹配到的块处理器。</param>
/// <returns>如果能够开始当前块的解析,则返回解析器序列。否则返回空序列。</returns>
public IEnumerable<BlockProcessor> TryStart(LineInfo line, BlockProcessor matchedProcessor)
public IEnumerable<BlockProcessor> TryStart(BlockText line, BlockProcessor matchedProcessor)
{
// 要求分割行之前是段落,而且包含且只包含一行。
IList<MappedText>? lines;
Expand Down
Loading

0 comments on commit 667fa8e

Please sign in to comment.