@@ -35,4 +36,8 @@
+
+
+
+
\ No newline at end of file
diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php
new file mode 100644
index 0000000..926c844
--- /dev/null
+++ b/src/DependencyInjection/Configuration.php
@@ -0,0 +1,44 @@
+root(static::ROOT_ID);
+ } else {
+ $rootNode = $treeBuilder->getRootNode();
+ }
+
+// $rootNode = $treeBuilder->root(static::ROOT_ID);
+ $rootNode
+ ->children()
+ ->arrayNode('skip_tags')
+ ->scalarPrototype()
+ ->defaultValue(['script'])
+ ->end()
+ ->end()
+ ->end();
+
+ return $treeBuilder;
+ }
+}
diff --git a/src/DependencyInjection/HyphenatorExtension.php b/src/DependencyInjection/HyphenatorExtension.php
index d65ac6c..386c145 100644
--- a/src/DependencyInjection/HyphenatorExtension.php
+++ b/src/DependencyInjection/HyphenatorExtension.php
@@ -20,8 +20,15 @@ class HyphenatorExtension extends Extension
*/
public function load(array $configs, ContainerBuilder $container)
{
- $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
+ $configuration = new Configuration();
+ $container->setParameter(Configuration::ROOT_ID, $this->processConfiguration($configuration, $configs));
+ $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
}
+
+ public function getAlias()
+ {
+ return Configuration::ROOT_ID;
+ }
}
diff --git a/src/Hyphenator/FrontendHyphenator.php b/src/Hyphenator/FrontendHyphenator.php
index 063b220..437022e 100644
--- a/src/Hyphenator/FrontendHyphenator.php
+++ b/src/Hyphenator/FrontendHyphenator.php
@@ -1,7 +1,7 @@
handleLineBreakExceptions($html, $objPage);
if (!$this->isHyphenationDisabled($objPage, Config::get('hyphenator_skipPages'))) {
+ // mask tags configured to be skipped
+ $skipTagCache = [];
+ $skipTagCacheIndex = 0;
+
+ foreach ($this->container->getParameter('huh_hyphenator')['skip_tags'] as $tag) {
+ if (\in_array($tag, $this->voidElements)) {
+ $html = preg_replace_callback(
+ '#<\s*?'.$tag.'\b[^>]*>#s',
+ function ($matches) use (&$skipTagCache, $skipTagCacheIndex) {
+ $skipTagCache[$skipTagCacheIndex] = $matches[0];
+ ++$skipTagCacheIndex;
+
+ return '####skip:open####'.($skipTagCacheIndex - 1).'####skip:close####';
+ }, $html
+ );
+ } else {
+ $html = preg_replace_callback(
+ '#<\s*?'.$tag.'\b[^>]*>(.*?)'.$tag.'\b[^>]*>#s',
+ function ($matches) use (&$skipTagCache, &$skipTagCacheIndex) {
+ $skipTagCache[$skipTagCacheIndex] = $matches[0];
+ ++$skipTagCacheIndex;
+
+ return '####skip:open####'.($skipTagCacheIndex - 1).'####skip:close####';
+ }, $html
+ );
+ }
+ }
+
// if html contains nested tags, use the hyphenateHtml that excludes HTML tags and attributes
libxml_use_internal_errors(true); // disable error reporting when potential using HTML5 tags
$html = $h->hyphenateHtml($html);
libxml_clear_errors();
+
+ // replace skipped tags
+ $html = preg_replace_callback(
+ '/####skip:open####(.*)####skip:close####/',
+ function ($matches) use ($skipTagCache) {
+ return $skipTagCache[$matches[1]];
+ },
+ $html
+ );
}
if (false === preg_match('#()?(?.+?)(<\/p>)?<\/body>#is', $html, $matches) || !isset($matches['content'])) {
diff --git a/tests/Hyphenator/FrontendHyphenatorTest.php b/tests/Hyphenator/FrontendHyphenatorTest.php
index e46bdda..ed3cb96 100644
--- a/tests/Hyphenator/FrontendHyphenatorTest.php
+++ b/tests/Hyphenator/FrontendHyphenatorTest.php
@@ -1,7 +1,7 @@
createMock(ModelUtil::class);
$this->container->set('huh.utils.model', $modelUtil);
+ $this->container->setParameter('huh_hyphenator', ['skip_tags' => ['script', 'img']]);
$listener = new FrontendHyphenator($this->container);
@@ -171,6 +172,18 @@ public function hyphenationProvider()
$this->getConfig(),
'
',
],
+ [
+ '',
+ $this->getPage(),
+ $this->getConfig(),
+ '',
+ ],
+ [
+ '
',
+ $this->getPage(),
+ $this->getConfig(),
+ '
',
+ ],
];
}