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 #774

Closed bjorntheart closed 2 years ago

bjorntheart 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

daugsbi commented 4 years ago

I can confirm the issue. Any idea for a workaround or a solution?

cjwind commented 3 years ago

I just created a PR to fix this issue. Hope it helps.

apvarun commented 3 years ago

I was trying to find the reason for this behavior and stumbled upon this PR. Anyone can get this merged? The PR looks good to me.

Georges67 commented 3 years ago

any update on this subject ?