leeoniya / reMarked.js

client-side HTML > markdown
http://leeoniya.github.io/reMarked.js/
396 stars 97 forks source link

list breaker comment after list #43

Closed s1rd4v3 closed 9 years ago

s1rd4v3 commented 10 years ago

i convert the html:

<ul>
  <li>ul list elem</li>
  <li>ul list elem</li>
</ul>
<ol>
  <li>ol list elem</li>
  <li>ol list elem</li>
</ol>

to:

* ul list elem
* ul list elem

1. ol list elem
2. ol list elem

the ouput with the official daringfireball md2html converter is:


<ul>
  <li>ul list elem</li>
  <li>ul list elem</li>
  <li>ol list elem</li>
  <li>ol list elem</li>
</ul>

this is an known issue of md and can be fixed by placing a \n\n<!-- --> after each list or just if theres a list after a list ;-) to split theme clearly.

this should ouput:

* ul list elem
* ul list elem

<!-- list-breaker -->

1.  ol list elem
2.  ol list elem

<!-- list-breaker -->

so i've changed your reMarked.js on line 402 to

wrap: [function(){return this.p instanceof lib.li ? "\n" : "\n\n";}, "\n\n<!-- list-breaker -->"]

in my local code.

cheers and thx for your work

leeoniya commented 10 years ago

i'm not sure it's an issue with markdown in general. it's just the nature of the base parser which is not designed to detect the list type change. many modern parsers are able to handle lists like this, including Github's and https://github.com/chjj/marked will also render these lists correctly if smartLists: true.

i've never heard of this before and it appears to be an ugly "feature" added to accommodate the original parser's illogical choice to not split obviously different lists. there is no good reason to use the original parser instead of any of the newer ones that easily handle obvious cases like this.

the goal of reMarked is to output clean markdown and this feature adds extra cruft that is not necessary if using a modern parser.

thanks for the suggestion, but i see not good reason to add this.

s1rd4v3 commented 10 years ago

I've just created this issue because of:

The ultimate goal is integration with existing WYSIWYG html editors (eg: Redactor, TinyMCE, CKeditor, Loki, CLeditor) to produce Markdown output.

In your readme.md.

I am using TinyMCE with your parser and i think it's essential to be able to write an odered list followed by an unordered list without taking care of this on the backend.

I'm not a fan of hacks. but in this case i realy think that there's no way around this as it doesnt make sense for me to not be able to break a list, to start another type of list.

But up to you. Thx anyway.

leeoniya commented 10 years ago

reMarked does not parse markdown, it parses html. if TinyMCE can create 2 different list types, then reMarked will show you 2 different lists in the generated markdown. if you are converting that markdown back to html, then you need to use a parser library that can recognize the different list types without explicit list breaks.

as i mentioned, https://github.com/chjj/marked is easily able to do this on the front-end (or backend via npm) with the smartLists: true option. try this bidirectional markdown <> html demo i made using redactor.js, reMarked and marked: http://leeoniya.github.io/redactor-js/

s1rd4v3 commented 9 years ago

Ok. You're right.