コード例 #1
0
 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();
 }
コード例 #2
0
 public function testSpecialSpaceChar()
 {
     $o = new \Org\Heigl\Hyphenator\Options();
     $o->setHyphen('-')->setDefaultLocale('fr')->setFilters('Simple')->setTokenizers('Whitespace', 'Punctuation');
     $h = new \Org\Heigl\Hyphenator\Hyphenator();
     $h->setOptions($o);
     $this->assertEquals('Ceci est à rem-pla-cer par une fâble' . " " . ':p', $h->hyphenate('Ceci est à remplacer par une fâble' . " " . ':p'));
 }