\League\HTMLToMarkdownHtmlConverter

Class HtmlConverter

A helper class to convert HTML to Markdown.

Summary

Methods
Properties
Constants
__construct()
getEnvironment()
getConfig()
__invoke()
convert()
setOptions()
No public properties found
No constants found
convertToMarkdown()
sanitize()
$environment
N/A
createDOMDocument()
convertChildren()
No private properties found
N/A

Properties

Methods

__construct()

__construct(\League\HTMLToMarkdown\Environment|array  $options = array()) 

Constructor

Parameters

\League\HTMLToMarkdown\Environment|array $options

Environment object or configuration options

__invoke()

__invoke(string  $html) : string

Convert

Parameters

string $html

Returns

string —

The Markdown version of the html

convert()

convert(string  $html) : string

Convert

Loads HTML and passes to getMarkdown()

Parameters

string $html

Throws

\InvalidArgumentException

Returns

string —

The Markdown version of the html

setOptions()

setOptions(array  $options) 

Pass a series of key-value pairs in an array; these will be passed through the config and set.

The advantage of this is that it can allow for static use (IE in Laravel). An example being:

HtmlConverter::setOptions(['strip_tags' => true])->convert('

test

');

Parameters

array $options

convertToMarkdown()

convertToMarkdown(\League\HTMLToMarkdown\ElementInterface  $element) : string

Convert to Markdown

Converts an individual node into a #text node containing a string of its Markdown equivalent.

Example: An

node with text content of 'Title' becomes a text node with content of '### Title'

Parameters

\League\HTMLToMarkdown\ElementInterface $element

Returns

string —

The converted HTML as Markdown

sanitize()

sanitize(string  $markdown) : string

Parameters

string $markdown

Returns

string

createDOMDocument()

createDOMDocument(string  $html) : \DOMDocument

Parameters

string $html

Returns

\DOMDocument

convertChildren()

convertChildren(\League\HTMLToMarkdown\ElementInterface  $element) 

Convert Children

Recursive function to drill into the DOM and convert each node into Markdown from the inside out.

Finds children of each node and convert those to #text nodes containing their Markdown equivalent, starting with the innermost element and working up to the outermost element.

Parameters

\League\HTMLToMarkdown\ElementInterface $element