gjtorikian / commonmarker

Ruby wrapper for the comrak (CommonMark parser) Rust crate
MIT License
416 stars 80 forks source link

Add option to disable indented code blocs #138

Closed xplosionmind closed 3 years ago

xplosionmind commented 3 years ago

I am getting crazy. I have a lot of indented <ul> lists, where I need to use HTML since I am adding classes to single lists elements.

I write them like this, in markdown files:

<ul>
    <li>blah blax</li>
    <li>blah blax</li>
</ul>

and they are parsed like this:

    <li>blah blax</li>
    <li>blah blax</li>

I can’t therefore indent anything, not even in divs or in ols, since they are parsed as codeblocks.

I would really love the capability of disabling this.

Thanks a lot in advance!

gjtorikian commented 3 years ago

It's really unlikely that the option to disable indented Commonmark behavior will ever be added. If it's in the spec, it must be supported.

But let's see if we can't figure out a solution here. Is there a reason the lists need to be indented by four spaces? Would two spaces work for you? That would "turn off" the indented code blocks.

Also, I just tried this as a markdown doc:

text = <<~EOS
<ul>
    <li>blah blax</li>
    <li>blah blax</li>
</ul>
EOS

A call to CommonMarker.render_html(text, :UNSAFE) properly returns "<ul>\n <li>blah blax</li>\n <li>blah blax</li>\n</ul>\n" (no code blocks). Is it possible there's something else going on in the way your doc is being rendered/called?

xplosionmind commented 3 years ago

Thanks a lot for your prompt answer, @gjtorikian.

Actually, I never indent my code with spaces, but with tabs. Furthermore, i found out what simple <ul> lists do work, even with a tab, as your test proved. The trouble happens when I use Liquid for loops in Jekyll, since I am using commonmarker via the jekyll-commonmark plugin. In that case, a lot of whitespace is generated and, even if it is still enclosed in <ul> and </ul> it is rendered as markdown…

Could I do something to prevent this? The only way I found out up to now is to remove all indentation. Using fewer spaces is useless since for sub-lists are still needed four spaces of indentation…

gjtorikian commented 3 years ago

Do you have a sample site I could look into? I might be able to reproduce the problem and implement a fix to minimize the whitespaces.

xplosionmind commented 3 years ago

Right now I have no website using Commonmark, since it does not generate IDs for headings, and I need them to generate TOCs. As soon as automatic ID generation will be implemented, I will use jekyll-commonmarker for my website and I will ping you by writing here