Skip to content

Commit

Permalink
Expose the number of lines in a document
Browse files Browse the repository at this point in the history
  • Loading branch information
MihaZupan committed Aug 29, 2018
1 parent 6947474 commit 790427c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/Markdig/Parsers/MarkdownParser.cs
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -87,6 +87,9 @@ private MarkdownDocument Parse()
{
ProcessBlocks();
ProcessInlines();

// At this point the LineIndex is the same as the number of lines in the document
document.Lines = blockProcessor.LineIndex;

// Allow to call a hook after processing a document
documentProcessed?.Invoke(document);
Expand Down Expand Up @@ -146,8 +149,7 @@ private void ProcessInlines()
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)
Expand Down
7 changes: 6 additions & 1 deletion src/Markdig/Syntax/MarkdownDocument.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,5 +15,10 @@ public class MarkdownDocument : ContainerBlock
public MarkdownDocument() : base(null)
{
}

/// <summary>
/// Gets the number of lines in this <see cref="MarkdownDocument"/>
/// </summary>
public int Lines { get; internal set; }
}
}

0 comments on commit 790427c

Please sign in to comment.