[PR #241] [MERGED] Expose the number of lines in a document #886

Open
opened 2026-01-29 14:46:50 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/xoofx/markdig/pull/241
Author: @MihaZupan
Created: 8/29/2018
Status: Merged
Merged: 9/4/2018
Merged by: @xoofx

Base: masterHead: document-lines


📝 Commits (1)

  • 8afff09 Expose the number of lines in a document

📊 Changes

2 files changed (+11 additions, -4 deletions)

View changed files

📝 src/Markdig/Parsers/MarkdownParser.cs (+5 -3)
📝 src/Markdig/Syntax/MarkdownDocument.cs (+6 -1)

📄 Description

I think this would be a nice feature to have (I know I need it).

I've tried to do it by using a block parser just to count lines, but, while it worked, it seemed overkill considering the value is already known, just hidden.

private class LineCounter : BlockParser
{
    public int Count => _count + 1;
    private int _count = -1;
    public override BlockState TryOpen(BlockProcessor processor)
    {
        _count = processor.LineIndex;
        return BlockState.None;
    }
}

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/xoofx/markdig/pull/241 **Author:** [@MihaZupan](https://github.com/MihaZupan) **Created:** 8/29/2018 **Status:** ✅ Merged **Merged:** 9/4/2018 **Merged by:** [@xoofx](https://github.com/xoofx) **Base:** `master` ← **Head:** `document-lines` --- ### 📝 Commits (1) - [`8afff09`](https://github.com/xoofx/markdig/commit/8afff09b3e5cf50439fbfe253f3901fd88267d46) Expose the number of lines in a document ### 📊 Changes **2 files changed** (+11 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `src/Markdig/Parsers/MarkdownParser.cs` (+5 -3) 📝 `src/Markdig/Syntax/MarkdownDocument.cs` (+6 -1) </details> ### 📄 Description I think this would be a nice feature to have (I know I need it). I've tried to do it by using a block parser just to count lines, but, while it worked, it seemed overkill considering the value is already known, just hidden. ```csharp private class LineCounter : BlockParser { public int Count => _count + 1; private int _count = -1; public override BlockState TryOpen(BlockProcessor processor) { _count = processor.LineIndex; return BlockState.None; } } ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-29 14:46:50 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#886