Expose the number of lines in a document

This commit is contained in:
Miha Zupan
2018-08-29 17:54:56 +02:00
parent 694747471a
commit 8afff09b3e
2 changed files with 11 additions and 4 deletions

View File

@@ -1,4 +1,4 @@
// Copyright (c) Alexandre Mutel. All rights reserved.
// Copyright (c) Alexandre Mutel. All rights reserved.
// This file is licensed under the BSD-Clause 2 license.
// See the license.txt file in the project root for more information.
@@ -87,6 +87,9 @@ namespace Markdig.Parsers
{
ProcessBlocks();
ProcessInlines();
// At this point the LineIndex is the same as the number of lines in the document
document.LineCount = blockProcessor.LineIndex;
// Allow to call a hook after processing a document
documentProcessed?.Invoke(document);
@@ -146,8 +149,7 @@ namespace Markdig.Parsers
for (; item.Index < container.Count; item.Index++)
{
var block = container[item.Index];
var leafBlock = block as LeafBlock;
if (leafBlock != null)
if (block is LeafBlock leafBlock)
{
leafBlock.OnProcessInlinesBegin(inlineProcessor);
if (leafBlock.ProcessInlines)

View File

@@ -1,4 +1,4 @@
// Copyright (c) Alexandre Mutel. All rights reserved.
// Copyright (c) Alexandre Mutel. All rights reserved.
// This file is licensed under the BSD-Clause 2 license.
// See the license.txt file in the project root for more information.
namespace Markdig.Syntax
@@ -15,5 +15,10 @@ namespace Markdig.Syntax
public MarkdownDocument() : base(null)
{
}
/// <summary>
/// Gets the number of lines in this <see cref="MarkdownDocument"/>
/// </summary>
public int LineCount;
}
}