Skip to content

Commit

Permalink
Merge pull request #274 from statikbe/KarelJanVanHaute/issue123
Browse files Browse the repository at this point in the history
Add soft hyphens to the base install
  • Loading branch information
Numkil authored Feb 1, 2024
2 parents 87e222f + 90c5242 commit f5c623b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions modules/statik/src/web/twig/HyphenateExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ public function hyphenate(string|Asset $source, array $attributes = []): Markup
$minimumWordLength = $attributes['wordLength'] ?? 12;

$output = Craft::$app->getCache()->getOrSet(
"hypen-" . substr(ElementHelper::generateSlug($source), 0, 40),
"hypen-" . base64_encode($source),
function () use ($source, $minimumWordLength) {
$source = preg_replace('/&(?!amp)/', '&', $source);
$language = strtolower(explode('-', Craft::$app->language)[0]);
$language = $language === 'en' ? 'en-us' : $language;
$syllable = new Syllable($language);
$syllable->getCache()->setPath(Craft::$app->getPath()->getTempPath());
$syllable->setMinWordLength($minimumWordLength);
return $syllable->hyphenateText($source);
return $syllable->hyphenateHtmlText($source);
});

return new Markup($output, 'UTF-8');
Expand Down

0 comments on commit f5c623b

Please sign in to comment.