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

Apply foreach on class StringLineGroup got phantom empty line, is it expected? #757

Closed
Akarinnnnn opened this issue Dec 11, 2023 · 2 comments · Fixed by #759
Closed

Apply foreach on class StringLineGroup got phantom empty line, is it expected? #757

Akarinnnnn opened this issue Dec 11, 2023 · 2 comments · Fixed by #759

Comments

@Akarinnnnn
Copy link
Contributor

I' m writing code to dump a FencedCodeBlock, here is the function:

        private static void HandleCodeBlock(FencedCodeBlock codeblock, int level)
        {
            Console.ForegroundColor = ConsoleColor.DarkYellow;
            if (!string.IsNullOrEmpty(codeblock.Info))
            {
                PrintIndent(level);
                Console.WriteLine($"lang: {codeblock.Info}, info args: {codeblock.Arguments}");
            }
            Console.ForegroundColor = ConsoleColor.White;

            foreach (var line in codeblock.Lines)
                Console.WriteLine(line);
        }

Then I see output contains suspicious empty line like this:

  FencedCodeBlock: 36/692-735 @1
 characters.sifeng.voice("c1s1", 3)


And the corresponding markdown is:
```
characters.sifeng.voice("c1s1", 3)
```

After some investigation, I found the enumerator of StringLineGroup returns internal array's enumerator directly. The array contains reserved slot for future item adding, that's the reason why we see phantom empty lines.

Shall we change the GetEnumerator() for StringLineGroup? I can provide some help.

@xoofx
Copy link
Owner

xoofx commented Dec 11, 2023

Shall we change the GetEnumerator() for StringLineGroup? I can provide some help.

Yep most likely, you can make a PR for a fix, thanks!

Akarinnnnn pushed a commit to Akarinnnnn/markdig that referenced this issue Dec 11, 2023
Fixes xoofx#757, before we return the array enumerator directly, enumerate it will get phantom empty lines.
@Akarinnnnn
Copy link
Contributor Author

Sorry for using incorrect email address. I will use correct information to commit later.

Akarinnnnn added a commit to Akarinnnnn/markdig that referenced this issue Dec 11, 2023
Fixes xoofx#757, before we return the array enumerator directly, enumerate it will get phantom empty lines.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants