Why convert HTML to Markdown?
"What alchemy is this?" you mutter. "I can see why you'd convert Markdown to HTML," you continue, already labouring the question somewhat, "but why go the other way?"
Typically you would convert HTML to Markdown if:
- You have an existing HTML document that needs to be edited by people with good taste.
- You want to store new content in HTML format but edit it as Markdown.
- You want to convert HTML email to plain text email.
- 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.
- You just really like Markdown.
How to use it
<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);
Top comments (0)