Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2 extra leading spaces in code blocks that are within list-items #227

Closed
amitport opened this issue Aug 10, 2013 · 8 comments
Closed

2 extra leading spaces in code blocks that are within list-items #227

amitport opened this issue Aug 10, 2013 · 8 comments

Comments

@amitport
Copy link

when indenting a code block with x+1 tabs after a level x list-item the code block renders with two extra leading spaces at each line

@chjj
Copy link
Member

chjj commented Aug 10, 2013

Marked list parsing is a bit smarter than markdown.pl when it comes to the list "margin". If you want original markdown.pl behavior, you can use the pedantic option. Otherwise, if you want no spacing in a code block in a list, align it to the list margin (using the number of characters in the bullet (1. would be 3, * would be 2) as the number of first few spaces, and then a tab or 4 spaces):

1. foo

       bar

* * *

* foo

      bar

@chjj chjj closed this as completed Aug 10, 2013
@amitport
Copy link
Author

I still think it's a bug (though not a critical one):

* list-item 1

<8 spaces or 2 tabs>code 1

<4 spaces or tab>* list-item 2

<12 spaces or 3 tabs>code 2

is compiled to :

<ul>
<li><p>list-item 1</p>
<pre><code>  code 1</code></pre>
<ul>
<li><p>list-item 2</p>
<pre><code>  code 2</code></pre>
</li>
</ul>
</li>
</ul>

the extra 2 leading spaces are there

@chjj
Copy link
Member

chjj commented Aug 10, 2013

It's not a bug. This is how marked behaves. If you want the original markdown.pl behavior, you can pass pedantic: true to marked().

@amitport
Copy link
Author

OK.. I guess I want the pedantic behavior (though I don't like that it's called that way..:)
thanks

@chjj
Copy link
Member

chjj commented Aug 10, 2013

Here's a better example of what I was talking about:

$ marked
* hello

      world

  * hello

        world
^D
<ul>
<li><p>hello</p>
<pre><code>world</code></pre>
<ul>
<li><p>hello</p>
<pre><code>world</code></pre>
</li>
</ul>
</li>
</ul>

@amitport
Copy link
Author

pedantic flag gives me spaces in the end of the code though.. but in any case, I got what you meant, I will manage.
thanks again

@cirosantilli
Copy link
Contributor

@chjj I agree with @amitport. Could we have an option that turns only this single pedantic behavior on?

Advantages of the original:

  1. simpler: to remember and implement on editors.

    • original: always use 4 spaces
    • Marked: look at the line above, and copy the number of character before the first char of the list.

    First person experience with implementing in Vim.

  2. The only other major engine that behaves like this is Kramdown: GFM, Multimarkdown, Pandoc, Redcarpet and markdown-js all follow Markdown.pl on this one.

This means that people coming from other engines to Marked will have problems. Tested with karlcow/markdown-testsuite#34

Same discussion for Kramdown: gettalong/kramdown#121

@chjj
Copy link
Member

chjj commented Apr 24, 2014

@cirosantilli, I realize people do sometimes only want certain aspects of original markdown behavior. The pedantic option might be my subconscious way of passively aggressively punishing users who want poor markdown behavior ("if you want some of the bad stuff, you might as well take all of it").

I do want to split pedantic up into smaller options, but at the same time I don't want marked to become a mountain of configuration. I'll think about it.

As for making this the default, it will be hard to convince myself. I really really really dislike the original markdown list behavior and I think it's counterintuitive. I'm willing to bet most people actually instinctively used marked-like list syntax for indentation when using markdown for the first time. I don't have any real evidence for this, but I don't agree when you say it's simpler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants