test post from dev api
Published: 2023-07-28 14:19:37

Library which converts HTML to [Markdown](http://daringfireball.net/projects/markdown/) for your sanity and convenience.

**Requires**: PHP 7.2+

**Lead Developer**: [@colinodell](http://twitter.com/colinodell)

**Original Author**: [@nickcernis](http://twitter.com/nickcernis)

### [](https://github.com/thephpleague/html-to-markdown#why-convert-html-to-markdown)Why convert HTML to Markdown?

*"What alchemy is this?"* you mutter. *"I can see why you'd convert [Markdown to HTML](https://github.com/thephpleague/commonmark),"* you continue, already labouring the question somewhat, *"but why go the other way?"*

Typically you would convert HTML to Markdown if:

1. You have an existing HTML document that needs to be edited by people with good taste.
2. You want to store new content in HTML format but edit it as Markdown.
3. You want to convert HTML email to plain text email.
4. You know a guy who's been converting HTML to Markdown for years, and now he can speak Elvish. You'd quite like to be able to speak Elvish.
5. You just really like Markdown.

### [](https://github.com/thephpleague/html-to-markdown#how-to-use-it)How to use it

Require the library by issuing this command:

```
<span class="line"><span style="color: #81A1C1">use</span><span style="color: #D8DEE9FF"> League</span><span style="color: #ECEFF4">\</span><span style="color: #D8DEE9FF">HTMLToMarkdown</span><span style="color: #ECEFF4">\</span><span style="color: #8FBCBB">HtmlConverter</span><span style="color: #81A1C1">;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #81A1C1">$</span><span style="color: #D8DEE9">converter</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">new</span><span style="color: #D8DEE9FF"> </span><span style="color: #8FBCBB">HtmlConverter</span><span style="color: #ECEFF4">()</span><span style="color: #81A1C1">;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #81A1C1">$</span><span style="color: #D8DEE9">html</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #ECEFF4">"</span><span style="color: #A3BE8C"><h3>Quick, to the Batpoles!</h3></span><span style="color: #ECEFF4">"</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #81A1C1">$</span><span style="color: #D8DEE9">markdown</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">$</span><span style="color: #D8DEE9">converter</span><span style="color: #81A1C1">-></span><span style="color: #88C0D0">convert</span><span style="color: #ECEFF4">(</span><span style="color: #81A1C1">$</span><span style="color: #D8DEE9">html</span><span style="color: #ECEFF4">)</span><span style="color: #81A1C1">;</span></span>
```



**and**

```
use League\HTMLToMarkdown\HtmlConverter;

$converter = new HtmlConverter();

$html = "<h3>Quick, to the Batpoles!</h3>";
$markdown = $converter->convert($html);
```

   
[*Read more posts on my blog (etanish.com)*](https://etanish.com)