showdownjs / showdown

A bidirectional Markdown to HTML to Markdown converter written in Javascript
http://www.showdownjs.com/
MIT License
14.26k stars 1.56k forks source link

Showdown generates incorrect markdown for tasklists #773

Closed orangelabs-dev closed 4 years ago

orangelabs-dev commented 4 years ago

I'm using GFM and tasklists with Showdown and it creates incorrect markdown from html.

Showdown Setup

Version: 1.9.1

var converter = new showdown.Converter({
  tasklists: true
})
converter.setFlavor('github')

converter.makeHtml

const initialValue = `
- [x] This task is done
- [ ] This is still pending`

const htmlString = converter.makeHtml(initialValue)
console.log(htmlString)
Output
<ul>
<li class="task-list-item" style="list-style-type: none;"><input type="checkbox" disabled style="margin: 0px 0.35em 0.25em -1.6em; vertical-align: middle;" checked> This task is done</li>
<li class="task-list-item" style="list-style-type: none;"><input type="checkbox" disabled style="margin: 0px 0.35em 0.25em -1.6em; vertical-align: middle;"> This is still pending</li>
</ul> 

converter.makeMarkdown

const markdown = converter.makeMarkdown(htmlString)
console.log(markdown)
Output
- <input type="checkbox" disabled="" style="margin: 0px 0.35em 0.25em -1.6em; vertical-align: middle;" checked="">

 This task is done
- <input type="checkbox" disabled="" style="margin: 0px 0.35em 0.25em -1.6em; vertical-align: middle;">

 This is still pending

<!-- -->

As you can see, converting back to markdown generates a mix of markdown and html.

Complete code at https://codesandbox.io/s/showdown-example-n3dyv. Check the output in the Sandbox console