`.
To strip HTML tags that don't have a Markdown equivalent while preserving the content inside them, set `strip_tags` to true, like this:
```php
$converter = new HtmlConverter(array('strip_tags' => true));
$html = '
Turnips!';
$markdown = $converter->convert($html); // $markdown now contains "Turnips!"
```
Or more explicitly, like this:
```php
$converter = new HtmlConverter();
$converter->getConfig()->setOption('strip_tags', true);
$html = '
Turnips!';
$markdown = $converter->convert($html); // $markdown now contains "Turnips!"
```
Note that only the tags themselves are stripped, not the content they hold.
To strip tags and their content, pass a space-separated list of tags in `remove_nodes`, like this:
```php
$converter = new HtmlConverter(array('remove_nodes' => 'span div'));
$html = '
Turnips!Monkeys!
';
$markdown = $converter->convert($html); // $markdown now contains ""
```
By default, all comments are stripped from the content. To preserve them, use the `preserve_comments` option, like this:
```php
$converter = new HtmlConverter(array('preserve_comments' => true));
$html = '
Turnips!';
$markdown = $converter->convert($html); // $markdown now contains "Turnips!"
```
To preserve only specific comments, set `preserve_comments` with an array of strings, like this:
```php
$converter = new HtmlConverter(array('preserve_comments' => array('Eggs!')));
$html = '
Turnips!';
$markdown = $converter->convert($html); // $markdown now contains "Turnips!"
```
### Style options
By default bold tags are converted using the asterisk syntax, and italic tags are converted using the underlined syntax. Change these by using the `bold_style` and `italic_style` options.
```php
$converter = new HtmlConverter();
$converter->getConfig()->setOption('italic_style', '*');
$converter->getConfig()->setOption('bold_style', '__');
$html = '
Italic and a
bold';
$markdown = $converter->convert($html); // $markdown now contains "*Italic* and a __bold__"
```
### Line break options
By default, `br` tags are converted to two spaces followed by a newline character as per [traditional Markdown](https://daringfireball.net/projects/markdown/syntax#p). Set `hard_break` to `true` to omit the two spaces, as per GitHub Flavored Markdown (GFM).
```php
$converter = new HtmlConverter();
$html = '
test
line break
';
$converter->getConfig()->setOption('hard_break', true);
$markdown = $converter->convert($html); // $markdown now contains "test\nline break"
$converter->getConfig()->setOption('hard_break', false); // default
$markdown = $converter->convert($html); // $markdown now contains "test \nline break"
```
### Autolinking options
By default, `a` tags are converted to the easiest possible link syntax, i.e. if no text or title is available, then the `
` syntax will be used rather than the full `[url](url)` syntax. Set `use_autolinks` to `false` to change this behavior to always use the full link syntax.
```php
$converter = new HtmlConverter();
$html = 'https://thephpleague.com
';
$converter->getConfig()->setOption('use_autolinks', true);
$markdown = $converter->convert($html); // $markdown now contains ""
$converter->getConfig()->setOption('use_autolinks', false); // default
$markdown = $converter->convert($html); // $markdown now contains "[https://google.com](https://google.com)"
```
### Passing custom Environment object
You can pass current `Environment` object to customize i.e. which converters should be used.
```php
$environment = new Environment(array(
// your configuration here
));
$environment->addConverter(new HeaderConverter()); // optionally - add converter manually
$converter = new HtmlConverter($environment);
$html = 'Header
';
$markdown = $converter->convert($html); // $markdown now contains "### Header" and ""
```
### Limitations
- Markdown Extra, MultiMarkdown and other variants aren't supported – just Markdown.
### Known issues
- Nested lists and lists containing multiple paragraphs aren't converted correctly.
- Lists inside blockquotes aren't converted correctly.
- Any reported [open issues here](https://github.com/thephpleague/html-to-markdown/issues?state=open).
[Report your issue or request a feature here.](https://github.com/thephpleague/html-to-markdown/issues/new) Issues with patches or failing tests are especially welcome.
### Style notes
- Setext (underlined) headers are the default for H1 and H2. If you prefer the ATX style for H1 and H2 (# Header 1 and ## Header 2), set `header_style` to 'atx' in the options array when you instantiate the object:
`$converter = new HtmlConverter(array('header_style'=>'atx'));`
Headers of H3 priority and lower always use atx style.
- Links and images are referenced inline. Footnote references (where image src and anchor href attributes are listed in the footnotes) are not used.
- Blockquotes aren't line wrapped – it makes the converted Markdown easier to edit.
### Dependencies
HTML To Markdown requires PHP's [xml](http://www.php.net/manual/en/xml.installation.php), [lib-xml](http://www.php.net/manual/en/libxml.installation.php), and [dom](http://www.php.net/manual/en/dom.installation.php) extensions, all of which are enabled by default on most distributions.
Errors such as "Fatal error: Class 'DOMDocument' not found" on distributions such as CentOS that disable PHP's xml extension can be resolved by installing php-xml.
### Contributors
Many thanks to all [contributors](https://github.com/thephpleague/html-to-markdown/graphs/contributors) so far. Further improvements and feature suggestions are very welcome.
### How it works
HTML To Markdown creates a DOMDocument from the supplied HTML, walks through the tree, and converts each node to a text node containing the equivalent markdown, starting from the most deeply nested node and working inwards towards the root node.
### To-do
- Support for nested lists and lists inside blockquotes.
- Offer an option to preserve tags as HTML if they contain attributes that can't be represented with Markdown (e.g. `style`).
### Trying to convert Markdown to HTML?
Use one of these great libraries:
- [league/commonmark](https://github.com/thephpleague/commonmark) (recommended)
- [cebe/markdown](https://github.com/cebe/markdown)
- [PHP Markdown](https://michelf.ca/projects/php-markdown/)
- [Parsedown](https://github.com/erusev/parsedown)
No guarantees about the Elvish, though.