s9e / TextFormatter

Text formatting library that supports BBCode, HTML and other markup via plugins. Handles emoticons, censors words, automatically embeds media and more.
MIT License
232 stars 36 forks source link

Indentation issues with BBCode code and Litedown #170

Closed AlfredoRamos closed 3 years ago

AlfredoRamos commented 3 years ago

Hi :wave:

Someone reported me that by having Litedown enabled (from my Markdown extension for phpBB), the snippets using the [code] BBCode have some indentation issues.

Code example:

[code]
using System;

class Program{
    static void Main(string[] args){
        Console.Write("hello");

        if (1 == 1){
            Console.WriteLine("test");
        }
    }
}
[/code]

Result:

Screenshot_20210721_151613

Same example as above with Markdown disabled ![Screenshot_20210721_152803](https://user-images.githubusercontent.com/4165935/126555675-b54f5cc6-249c-4124-95cc-10aa46cc9efa.png)
This is how it looks using Markdown ![Screenshot_20210721_152223](https://user-images.githubusercontent.com/4165935/126555030-83c4dbd1-d84b-4e01-be01-a4794e7346b2.png) ~~~ ``` using System; class Program{ static void Main(string[] args){ Console.Write("hello"); if (1 == 1){ Console.WriteLine("test"); } } } ``` ~~~

Inspecting the generated XML code I see that, when Litedown is enabled, it contains <i> tags.

[code] BBCode with Litedown enabled

<CODE><s>[code]</s>using System;

class Program{
    static void Main(string[] args){
        Console.Write("hello");

<i> </i>    if (1 == 1){
<i> </i>        Console.WriteLine("test");
<i> </i>    }
<i> </i>}
}<e>[/code]</e></CODE>

[code] BBCode with Litedown disabled

<CODE><s>[code]</s>using System;

class Program{
    static void Main(string[] args){
        Console.Write("hello");

        if (1 == 1){
            Console.WriteLine("test");
        }
    }
}<e>[/code]</e></CODE>

My setup:

P.S.: I'm not sure if this is related to #169, that's why I decided to opened this new issue.

JoshyPHP commented 3 years ago

You're correct, this is the same issue. Some block-level spans of text that need to be ignored because of Markdown rules end up being ignored inside of code blocks created by BBCodes. The workaround is to use Litedown code blocks.

I might close #169 as a dupe of this one because this is the best formatted bug report I have seen in a while. 👍