public static function hyphenate($strBuffer) { global $objPage; $arrSkipPages = \Config::get('hyphenator_skipPages'); if (is_array($arrSkipPages) && in_array($objPage->id, $arrSkipPages)) { return $strBuffer; } $o = new \Org\Heigl\Hyphenator\Options(); $o->setHyphen(\Config::get('hyphenator_hyphen'))->setDefaultLocale(static::getLocaleFromLanguage($objPage->language))->setRightMin(\Config::get('hyphenator_rightMin'))->setLeftMin(\Config::get('hyphenator_leftMin'))->setWordMin(\Config::get('hyphenator_wordMin'))->setFilters(\Config::get('hyphenator_filter'))->setQuality(\Config::get('hyphenator_quality'))->setTokenizers(\Config::get('hyphenator_tokenizers')); $h = new \Org\Heigl\Hyphenator\Hyphenator(); $h->setOptions($o); $doc = \phpQuery::newDocumentHTML($strBuffer); foreach (pq('body')->find(\Config::get('hyphenator_tags')) as $n => $item) { $strText = pq($item)->html(); // ignore html tags, otherwise ­ will be added to links for example if ($strText != strip_tags($strText)) { continue; } $strText = str_replace('­', '', $strText); // remove manual ­ html entities before $strText = $h->hyphenate($strText); if (is_array($strText)) { $strText = current($strText); } pq($item)->html($strText); } return $doc->htmlOuter(); }
public function testSettingTokenizers2() { $options = M::mock('\\Org\\Heigl\\Hyphenator\\Options'); $options->shouldReceive('getTokenizers')->once()->andReturn(array('Whitespace', 'Punctuation')); $h = new \Org\Heigl\Hyphenator\Hyphenator(); $h->setOptions($options); $ref = new \ReflectionClass($h); $prop = $ref->getProperty('_tokenizers'); $prop->setAccessible(true); $prop->setValue($h, new \Org\Heigl\Hyphenator\Tokenizer\TokenizerRegistry()); $result = $h->getTokenizers(); $this->assertEquals(2, $result->count()); $this->assertInstanceof('\\Org\\Heigl\\Hyphenator\\Tokenizer\\WhitespaceTokenizer', $result->current()); }