Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose the number of lines in a document #241

Merged
merged 1 commit into from
Sep 4, 2018

Conversation

MihaZupan
Copy link
Collaborator

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;
    }
}

@xoofx
Copy link
Owner

xoofx commented Aug 29, 2018

Why not. By curiosity, in which case you are using this?

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better use LineCount instead (Lines can imply that it would return an array). You can also leave it public get set (not internal). It is not something important to protect and doesn't hurt if someone wants to change it (create a MarkdownDocument manually...etc.)

Copy link
Collaborator Author

@MihaZupan MihaZupan Aug 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit amended.
As to why, I wrote a tool that checks a bunch of things about markdown 'codebases', and emits warnings. I wrote my own regex-y parser to detect the structures I needed, but now I decided it would be much easier and much more reliable if I just use a well-established parser.

On another note, I was going to accept a pipeline builder, but now I realize that it's not designed for use over multiple files. Should I make users implement some sort of class that returns fresh instances of pipeline/pipeline builder every time? Or is there a cleaner solution I'm missing here?

@xoofx xoofx merged commit 1fe0563 into xoofx:master Sep 4, 2018
@xoofx
Copy link
Owner

xoofx commented Sep 4, 2018

Thanks!

@MihaZupan MihaZupan deleted the document-lines branch October 7, 2018 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants