Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@phillip-haydon
Copy link
Contributor

This addresses the issue in #504 using the example from #504 (comment)

https://gist.github.com/MihaZupan/98621af5788f570f0dd0b809f1f3489b

Not sure what the process is on contributing as there's no open PRs so I don't think this has been fixed before :)

@xoofx xoofx added the bug label Sep 21, 2025
@xoofx xoofx merged commit 0e9e80e into xoofx:master Sep 21, 2025
1 check passed
@xoofx
Copy link
Owner

xoofx commented Sep 21, 2025

Thanks for the fix!

It could be an ok fix. I will try to have a look locally. My only concern is that it is coupling the code inline parser with a potential grid table | character, but yeah, not sure there are much cleaner way.

@xoofx
Copy link
Owner

xoofx commented Sep 21, 2025

cc: @MihaZupan if you have any comments on this

@phillip-haydon
Copy link
Contributor Author

Thanks for accepting the PR ❤️ do you know when a new nuget would be available? I'm just running my app with a local nuget dir at the moment but would like ti get it from nuget.org when available.

Copy link
Collaborator

@MihaZupan MihaZupan left a comment

Choose a reason for hiding this comment

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

Table parsing is the one area of Markdig I'm not that familiar with unfortunately.

I fear this change is going to break otherwise valid inputs, e.g.

`
|| hidden text ||
`

is currently a perfectly valid CodeInline (and all parsers agree on that), but this change turns it into a literal instead.

Since this is clearly a targeted fix for table weirdness, I wonder if we should embrace that and add a && processor.Inline?.ContainsParentOfType<PipeTableDelimiterInline>() == true check before breaking the CodeInline?

Comment on lines +199 to +208
if (tableState is not null)
{
foreach (var inline in tableState.ColumnAndLineDelimiters)
{
if (inline is PipeTableDelimiterInline pipeDelimiter)
{
pipeDelimiter.ReplaceByLiteral();
}
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is merely cleanup so that the syntax tree doesn't have random pipe delimiters even if we didn't have a table in the end, right?

None of the tests seem to care since the literal renders the same either way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah it's just cleanup, it swaps the left over | nodes back to plain text so the tree looks tidy. I did run the benchmark against it and there was no impact on perf so kept it in.

@phillip-haydon
Copy link
Contributor Author

Table parsing is the one area of Markdig I'm not that familiar with unfortunately.

I fear this change is going to break otherwise valid inputs, e.g.

`
|| hidden text ||
`

is currently a perfectly valid CodeInline (and all parsers agree on that), but this change turns it into a literal instead.

Since this is clearly a targeted fix for table weirdness, I wonder if we should embrace that and add a && processor.Inline?.ContainsParentOfType<PipeTableDelimiterInline>() == true check before breaking the CodeInline?

I tested:

        const string markdown = "`|| hidden text ||`";

and

        const string markdown = """
                                `
                                || hidden text ||
                                `
                                """;

Both produced:

<p><code>|| hidden text ||</code></p>

@phillip-haydon
Copy link
Contributor Author

Would you like me to add a follow up PR with unit tests for the code snippets?

@MihaZupan
Copy link
Collaborator

MihaZupan commented Sep 22, 2025

The second case (with new lines) isn't a code inline anymore after your change.

[Test]
public void Test()
{
    TestParser.TestSpec(
        """
        `
        || hidden text ||
        `
        """,
        "<p><code> || hidden text || </code></p>");
}

fails with

       ```````````````````Source
       `
       ||·hidden·text·||
       `
       ```````````````````Result
       <p>`
       ||·hidden·text·||
       `</p>
       ```````````````````Expected
       <p><code>·||·hidden·text·||·</code></p>
       ```````````````````

More unit tests could be useful (e.g. to also check cases with leading spaces), but I think we should tweak behavior here.

@phillip-haydon
Copy link
Contributor Author

The second case (with new lines) isn't a code inline anymore after your change.

[Test]
public void Test()
{
    TestParser.TestSpec(
        """
        `
        || hidden text ||
        `
        """,
        "<p><code> || hidden text || </code></p>");
}

fails with

       ```````````````````Source
       `
       ||·hidden·text·||
       `
       ```````````````````Result
       <p>`
       ||·hidden·text·||
       `</p>
       ```````````````````Expected
       <p><code>·||·hidden·text·||·</code></p>
       ```````````````````

More unit tests could be useful (e.g. to also check cases with leading spaces), but I think we should tweak behavior here.

OH, ok leave that to me, ill get a unit test in and fix tonight.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants