How to convert HTML to markdown?

I have a website like stackoverflow for example. There is a text box in which people write answers. I use this PHP library to convert markdowns. I mean, I use this function to convert *italic* to <i>italic</i> .

 // include that library $Parsedown = new Parsedown(); echo $Parsedown->text('*italic*'); # prints: <i>italic</i> 

Well, everything is fine. It should be noted that I convert this answer (to html tags, not markup characters) for storage, in other words, all the data in the database contains HTML tags, not markup characters.

Now I want to implement a Editorial system for answers. Something like stackoverflow. So I need to convert the saved answer back to markdown style again.

Now I want to know how I can convert it? I want to convert <i>italic</i> to *italic* , how can I do this?

+5
source share
2 answers

Instead of storing the original input as a collapsible markdown, you should save the actual markdown and convert it to HTML only when rendering to a page.

This way you keep the original markdown for editing as needed. This is also more logical.

+3
source

I need this too, I found these 2 github projects:

I used the first one because it has Markdown Extra support (converted from ParsedownExtra) and it worked well for me.

+2
source

Source: https://habr.com/ru/post/1245202/