Skip to content

Commit 8dbc323

Browse files
authored
Merge pull request #1 from dlubitz/html-hyphenation
Support for HTML
2 parents 775c13e + 1b682bd commit 8dbc323

File tree

4 files changed

+59
-6
lines changed

4 files changed

+59
-6
lines changed

Classes/Fusion/HyphenateImplementation.php

+17-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ public function getLocale()
4242
return (string) $this->localizationService->getConfiguration()->getCurrentLocale();
4343
}
4444

45+
public function getType()
46+
{
47+
return strtolower($this->fusionValue('type'));
48+
}
49+
4550
public function getThreshold()
4651
{
4752
return $this->fusionValue('threshold');
@@ -70,6 +75,17 @@ public function evaluate()
7075
$syllable->setHyphen(new \Syllable_Hyphen_Soft);
7176
$syllable->setMinWordLength($this->getThreshold());
7277

73-
return $syllable->hyphenateText($this->getContent());
78+
switch ($this->getType()) {
79+
case 'html':
80+
$html = mb_convert_encoding($this->getContent(), 'HTML-ENTITIES', "UTF-8");
81+
$result = $syllable->hyphenateHtml($html);
82+
break;
83+
case 'test':
84+
// Break missing intendedly
85+
default:
86+
$result = $syllable->hyphenateText($this->getContent());
87+
break;
88+
}
89+
return $result;
7490
}
7591
}

Configuration/Settings.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Neos:
2+
Neos:
3+
fusion:
4+
autoInclude:
5+
PackageFactory.Hyphenate: true

README.md

+28-4
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,40 @@ to the require-section of the composer.json or run `composer require packagefact
99

1010
## Usage
1111

12-
Just use the `PackageFactory.Hyphenate:Hyphenate` Fusion object as a processor on the fusion value that should be hyphenated.
12+
### Text
13+
Just use the `PackageFactory.Hyphenate:HyphenateText` Fusion object as a processor on the fusion value that should be hyphenated.
1314

1415
```
1516
someFusionValue = 'Grund­stücks­ver­kehrs­ge­neh­mi­gungs­zu­stän­dig­keits­über­tra­gungs­ver­ord­nung'
16-
[email protected] = PackageFactory.Hyphenate:Hyphenate {
17-
locale = 'de'
17+
[email protected] = PackageFactory.Hyphenate:HyphenateText {
18+
locale = 'de'
1819
}
1920
```
2021

21-
**!!! Warning: !!!** This mechanism breaks HTML code. There's no support for hyphenating HTML Strings yet (PRs are welcome ;) ).
22+
### HTML
23+
Similar to text elements you can use `PackageFactory.Hyphenate:HyphenateHtml` for HTML elements.
24+
25+
```
26+
[email protected] = PackageFactory.Hyphenate:HyphenateHtml {
27+
locale = 'de'
28+
}
29+
```
30+
31+
## Neos CMS integration example
32+
33+
You can easily activate hyphenation for all Neos CMS text- and headline nodetypes with following Fusion code:
34+
35+
```
36+
prototype(Neos.NodeTypes:Text) {
37+
[email protected] = PackageFactory.Hyphenate:HyphenateHtml
38+
}
39+
40+
prototype(Neos.NodeTypes:Headline) {
41+
[email protected] = PackageFactory.Hyphenate:HyphenateHtml
42+
}
43+
44+
```
45+
2246

2347
## Parameters
2448

Resources/Private/Fusion/Root.fusion

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
prototype(PackageFactory.Hyphenate:Hyphenate) {
22
@class = 'PackageFactory\\Hyphenate\\Fusion\\HyphenateImplementation'
3-
3+
type = 'text'
44
content = ${value}
5+
6+
@if.onlyRenderWhenNotInBackend = ${!documentNode.context.inBackend}
7+
}
8+
9+
prototype(PackageFactory.Hyphenate:HyphenateText) < prototype(PackageFactory.Hyphenate:Hyphenate)
10+
11+
prototype(PackageFactory.Hyphenate:HyphenateHtml) < prototype(PackageFactory.Hyphenate:Hyphenate) {
12+
type = 'html'
513
}

0 commit comments

Comments
 (0)