straschek-io / typo3-hyphenator
Provides soft-hyphen replacement for TYPO3
Package info
github.com/straschek-io/typo3-hyphenator
Type:typo3-cms-extension
pkg:composer/straschek-io/typo3-hyphenator
Requires
- typo3/cms-core: ^12.4 | ^13.4 | ^14.3
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.75
- phpunit/phpunit: ^10.5
- typo3/cms-backend: ^12.4 | ^13.4 | ^14.3
- typo3/cms-belog: ^12.4 | ^13.4 | ^14.3
- typo3/cms-fluid-styled-content: ^12.4 | ^13.4 | ^14.3
- typo3/cms-frontend: ^12.4 | ^13.4 | ^14.3
- typo3/cms-install: ^12.4 | ^13.4 | ^14.3
README
This extension allows you to add soft-hyphen definitions to your TYPO3.
Those rules will be applied to the frontend at the end of your middleware stack.
This extension aims to give you full control about HOW you want specific terms to break in case of having limited space. There are other client- & server-side solutions out there which do all the magic w/o you having to provide specifications, but they may result in endlessly huge pain on designer and customer sites.
So as a simple example, this extension allows you to NOT have break like this:
... ... .. ..... ... Ar-
beiterunfallversicherungsgesetz
... ... .. ..... Arbeiterun-
fallversicherungsgesetz
Arbeiterun-
fallver-
sicherungsge-
setz
You can have this:
... ... .. ..... ... Arbeiter-
unfallversicherungsgesetz
... ... .. ..... Arbeiterunfall-
versicherungsgesetz
Arbeiter-
unfall-
versicherungs-
gesetz
YAY!
How to install
composer require straschek-io/typo3-hyphenator
vendor/bin/typo3 extension:activate typo3_hyphenator
No further configuration needed.
How to use
- Just add a "Hyphenator term" record and clear the TYPO3 cache
- Reload your frontend
The pid field is not evaluated, so simply drop the records into a
sys folder to your liking.
Good to know
- Replacement happens in a PSR-15 middleware and only touches
text/htmlresponses. JSON, XML sitemaps and other content types pass through untouched. - The parser works in a single
preg_replace_callback()pass over the rendered HTML. Tags and their attributes,<head>,<script>,<style>,<textarea>and HTML comments are never touched. - Terms are matched literally (no regular expressions in the "from" field) and must start at a word boundary.
- Prefix matching is intended behavior: a term like
Arbeitalso hyphenates the beginning ofArbeitsamt. If several terms match, the longest one wins. - DOM-based parsing (libxml
DOMDocument,Masterminds\HTML5) was evaluated and benchmarked, but both were orders of magnitude slower than the single regex pass: simple & fast still wins.
Development
./Build/dev-setup.sh
Bootstraps a full TYPO3 dev instance (DDEV required) with a seeded test page,
demo content and hyphenation terms.
Frontend: https://typo3-hyphenator.ddev.site/ — Backend: /typo3 (admin / Hyphenator14!)
Run tests with ddev composer test, code style with ddev composer cs.
Compatibility
Compatible with TYPO3 12.4, 13.4 and 14.3
Parser and middleware are covered by PHPUnit tests (composer test),
running in CI on PHP 8.2 – 8.5 against all three supported TYPO3 versions.
Works for me, may work for you.
