HtmlConverter
A helper class to convert HTML to Markdown.
- Full name:
\League\HTMLToMarkdown\HtmlConverter
- This class implements:
\League\HTMLToMarkdown\HtmlConverterInterface
See Also:
- https://github.com/thephpleague/html-to-markdown/ - Latest version on GitHub.
Properties
environment
Methods
__construct
Constructor
public __construct(\League\HTMLToMarkdown\Environment|array<string,mixed> $options = []): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$options |
\League\HTMLToMarkdown\Environment|array |
Environment object or configuration options |
getEnvironment
getConfig
__invoke
Convert
Parameters:
Parameter | Type | Description |
---|---|---|
$html |
string |
Return Value:
The Markdown version of the html
See Also:
- \League\HTMLToMarkdown\HtmlConverter::convert -
convert
Convert
Loads HTML and passes to getMarkdown()
Parameters:
Parameter | Type | Description |
---|---|---|
$html |
string |
Return Value:
The Markdown version of the html
Throws:
createDOMDocument
Parameters:
Parameter | Type | Description |
---|---|---|
$html |
string |
replaceMisplacedComments
Finds any comment nodes outside element and moves them into
.Parameters:
Parameter | Type | Description |
---|---|---|
$document |
\DOMDocument |
See Also:
- https://github.com/thephpleague/html-to-markdown/issues/212 - * https://3v4l.org/7bC33 -
convertChildren
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:
Parameter | Type | Description |
---|---|---|
$element |
\League\HTMLToMarkdown\ElementInterface |
convertToMarkdown
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:
Parameter | Type | Description |
---|---|---|
$element |
\League\HTMLToMarkdown\ElementInterface |
Return Value:
The converted HTML as Markdown
sanitize
Parameters:
Parameter | Type | Description |
---|---|---|
$markdown |
string |
setOptions
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:
Parameter | Type | Description |
---|---|---|
$options |
array |
Automatically generated on 2025-03-18