thephpleague / commonmark

Highly-extensible PHP Markdown parser which fully supports the CommonMark and GFM specs.
https://commonmark.thephpleague.com
BSD 3-Clause "New" or "Revised" License
2.68k stars 189 forks source link

HTML to Markdown #719

Open colinodell opened 2 years ago

colinodell commented 2 years ago

419 and #511 require the ability to render the AST to Markdown. If we also add the ability to parse HTML into the AST then we could replace league/html-to-markdown with this package! Using an intermediate AST would also help with some of the issues/challenges in the other library.

stefanzweifel commented 11 months ago

Just came across this issue and wanted to share, that I've written an extension that can convert an AST back to Markdown back in August 2021: https://github.com/stefanzweifel/commonmark-markdown-renderer

(I use this in a CLI to add release notes to CHANGELOG files with GitHub Actions.)

As you mentioned in https://github.com/thephpleague/commonmark/issues/419#issuecomment-835916625, such a renderer has quite a lot of edge cases. My package isn't perfect by any means. (Currently struggling to support multi-line list items for example)