github / markup

Determines which markup library to use to render a content file (e.g. README) on GitHub
MIT License
5.84k stars 3.4k forks source link

C# code block rendering problem (using statement) #1402

Open mikernet opened 3 years ago

mikernet commented 3 years ago

Not sure where to post this, so my apologies if this is the wrong place. Please let me know where to redirect this issue if this isn't the correct spot.

Markdown rendering for using statements seems buggy on GitHub, especially when the { } blocks are empty. See the following examples:

using (lock.EnterReadGuard())
{
    // Safe to read here
}

using (lock.EnterWriteGuard())
{
    // Safe to write here
}

using (var upgradeableGuard = lock.EnterUpgradeableReadGuard())
{
    // Safe to read here

    if (someCondition)
    {
        upgradeableGuard.UpgradeToWriteGuard();
        // Safe to write here
    }
}

Compare that to:

using (lock.EnterReadGuard())
{
    // Safe to read here
    ReadData();
}

using (lock.EnterWriteGuard())
{
    // Safe to write here
    WriteData();
}

using (var upgradeableGuard = lock.EnterUpgradeableReadGuard())
{
    // Safe to read here
    ReadData();

    if (someCondition)
    {
        upgradeableGuard.UpgradeToWriteGuard();
        // Safe to write here
        WriteData();
    }
}
am11 commented 3 years ago

"It is a bit complicated" ™️ 🙂 Syntax highlighting is covered by https://github.com/github/linguist repo. Linguist supports PCRE grammar. .NET foundation provides oniguruma (or TextMate) grammar via https://github.com/dotnet/csharp-tmLanguage repository. To use that grammar in linguist, there is a middle repository https://github.com/atom/language-csharp, which does the oniguruma to PCRE conversion. Since the delta between the two grammars -- pertaining to the usage of oniguruma-specific syntax in csharp-tmLanguage -- is negligible and safe (no breakages for TextMate parsers to read PCRE syntax), I opened a PR https://github.com/dotnet/csharp-tmLanguage/pull/187 (still awaiting some love from reviewers..) so we could get rid of the dependency on middle repository and catch up with new language features fast. Current pace of development dotnet/csharp-tmLanguage and atom/language-csharp is super slow (if not completely dead), which is unfortunate..