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

Closed
opened 2026-01-29 14:41:56 +00:00 by claunia · 2 comments
Owner

Originally created by @Akarinnnnn on GitHub (Dec 11, 2023).

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.

Originally created by @Akarinnnnn on GitHub (Dec 11, 2023). I' m writing code to dump a `FencedCodeBlock`, here is the function: ```csharp 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: ```plaintext 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.
claunia added the bugPR Welcome! labels 2026-01-29 14:41:56 +00:00
Author
Owner

@xoofx commented on GitHub (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!

@xoofx commented on GitHub (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!
Author
Owner

@Akarinnnnn commented on GitHub (Dec 11, 2023):

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

@Akarinnnnn commented on GitHub (Dec 11, 2023): Sorry for using incorrect email address. I will use correct information to commit later.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#645