This bundle offers Symfony integration of the bicpi/HtmlConverter library.
Please also refer to the bicpi/HtmlConverter documentation.
See http://getcomposer.org for details.
"require" : {
// ...
"bicpi/html-converter-bundle": "^2.0",
}
Register the bundle in app/AppKernel.php
.
public function registerBundles()
{
$bundles = array(
// ...
new bicpi\Bundle\HtmlConverterBundle\BicpiHtmlConverterBundle(),
);
// ...
}
The bundle's default configuration is listed below. These defaults will be used if you do not change the configuration.
bicpi_html_converter:
guesser_chain:
- lynx
- html2text
- simple
You can use all the converters of the HtmlConverter
library as services:
$html = '... <h1>... you HTML content ...</h1> ...';
// lynx converter
$lynxConverter = $this->container->get('bicpi.html_converter.lynx');
$plainByLxnx = $converter->convert($html);
// html2text converter
$html2textConverter = $this->container->get('bicpi.html_converter.html2text');
$plainByHtml2Text = $converter->convert($html);
// simple converter
$simpleConverter = $this->container->get('bicpi.html_converter.simple');
$plainBySimple = $converter->convert($html);
You can use the special Guesser converter which chains all available converters in a reasonable order. The
Guesser converter is an implementation of the ChainConverter
. The available converters are registered
automatically by the bundle configuration in the following order:
lynx
html2text
simple
$html = '... <h1>... you HTML content ...</h1> ...';
$converter = $this->container->get('bicpi.html_converter.guesser');
$plain = $converter->convert($html);
For convenience you may use the service alias bicpi.html_converter
:
$html = '... <h1>... you HTML content ...</h1> ...';
$converter = $this->container->get('bicpi.html_converter');
$plain = $converter->convert($html);
You can customize the guesser chain in your config.yml
:
bicpi_html_converter:
guesser_chain:
- lynx
- simple
The above example only register the LynxConverter
and the SimpleConverter
.
To setup and run tests follow these steps:
- Go to the root directory of this library
- Run:
composer install
- Run:
./vendor/bin/phpunit