Skip to content

Commit da606a7

Browse files
Merge pull request #26 from jolicode/feature/10
Deprecate English/French/German smart quoters, introduce SmartQuote
2 parents 1c0aad6 + c3d6fc8 commit da606a7

16 files changed

+312
-90
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ CHANGELOG
77
* PSR2 and Symfony coding standard applied everywhere
88
* add `fixString` method to bypass the DomDocument parsing and directly run the fixers on a string
99
* better handling of common spaces in texts to fix (do not use `\s` anymore)
10+
* :warning: replace `EnglishQuotes`, `FrenchQuotes`, `GermanQuotes` by the new `SmartQuotes`! A BC layer is provided.
1011

1112
### 0.2.0 (2015-07-13) ###
1213

README.md

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ JoliTypo is a tool fixing [Microtypography](https://en.wikipedia.org/wiki/Microt
88
```php
99
use JoliTypo\Fixer;
1010

11-
$fixer = new Fixer(array('Ellipsis', 'Dash', 'EnglishQuotes', 'CurlyQuote', 'Hyphen'));
11+
$fixer = new Fixer(array('Ellipsis', 'Dash', 'SmartQuotes', 'CurlyQuote', 'Hyphen'));
1212
$fixed_content = $fixer->fix('<p>"Tell me Mr. Anderson... what good is a phone call... if you\'re unable to speak?" -- Agent Smith, <em>Matrix</em>.</p>');
1313
```
1414
```html
@@ -40,7 +40,8 @@ Just tell the Fixer class [which Fixer](#available-fixers) you want to run on yo
4040
```php
4141
use JoliTypo\Fixer;
4242

43-
$fixer = new Fixer(array("FrenchQuotes", "FrenchNoBreakSpace"));
43+
$fixer = new Fixer(array("SmartQuotes", "FrenchNoBreakSpace"));
44+
$fixer->setLocale('fr_FR');
4445
$fixed_content = $fixer->fix('<p>Je suis "très content" de t\'avoir invité sur <a href="http://jolicode.com/">Jolicode.com</a> !</p>');
4546
```
4647

@@ -55,7 +56,7 @@ To fix non HTML content, use the `fixString()` method:
5556
```php
5657
use JoliTypo\Fixer;
5758

58-
$fixer = new Fixer(array("Trademark", "EnglishQuotes"));
59+
$fixer = new Fixer(array("Trademark", "SmartQuotes"));
5960
$fixed_content = $fixer->fixString('Here is a "protip(c)"!'); // Here is a “protip©”!
6061
```
6162

@@ -95,21 +96,16 @@ Ellipsis
9596

9697
Replace the three dot `...` by an ellipsis ``.
9798

98-
EnglishQuotes
99-
-------------
100-
101-
Convert dumb quotes `" "` to smart English style quotation marks `“ ”`.
102-
103-
FrenchQuotes
104-
------------
99+
SmartQuotes
100+
-----------
105101

106-
Convert dumb quotes `" "` to smart French style quotation marks `« »` and use a no break space.
102+
Convert dumb quotes `" "` to all kind of smart style quotation marks (`“ ”`, `« »`, `„ “`...). Handle a good variety of locales,
103+
like English, Arabic, French, Italian, Spanish, Irish, German...
107104

108-
GermanQuotes
109-
------------
105+
See [the code](https://github.com/jolicode/JoliTypo/blob/master/src/JoliTypo/Fixer/SmartQuotes.php) for more details,
106+
and do not forget to specify a locale on the Fixer instance.
110107

111-
Convert dumb quotes `" "` to smart German style quotation marks `„ “` (Anführungszeichen).
112-
Some fonts (Verdana) are typographically incompatible with German.
108+
This Fixer replace legacy `EnglishQuotes`, `FrenchQuotes` and `GermanQuotes`.
113109

114110
FrenchNoBreakSpace
115111
------------------
@@ -163,8 +159,8 @@ en_GB
163159
-----
164160

165161
```php
166-
$fixer = new Fixer(array('Ellipsis', 'Dimension', 'Numeric', 'Dash', 'EnglishQuotes', 'NoSpaceBeforeComma', 'CurlyQuote', 'Hyphen', 'Trademark'));
167-
$fixer->setLocale('en_GB'); // Needed by the Hyphen Fixer
162+
$fixer = new Fixer(array('Ellipsis', 'Dimension', 'Numeric', 'Dash', 'SmartQuotes', 'NoSpaceBeforeComma', 'CurlyQuote', 'Hyphen', 'Trademark'));
163+
$fixer->setLocale('en_GB');
168164
```
169165

170166
fr_FR
@@ -173,8 +169,8 @@ fr_FR
173169
Those rules apply most of the recommendations of "Abrégé du code typographique à l'usage de la presse", ISBN: 9782351130667.
174170

175171
```php
176-
$fixer = new Fixer(array('Ellipsis', 'Dimension', 'Numeric', 'Dash', 'FrenchQuotes', 'FrenchNoBreakSpace', 'NoSpaceBeforeComma', 'CurlyQuote', 'Hyphen', 'Trademark'));
177-
$fixer->setLocale('fr_FR'); // Needed by the Hyphen Fixer
172+
$fixer = new Fixer(array('Ellipsis', 'Dimension', 'Numeric', 'Dash', 'SmartQuotes', 'FrenchNoBreakSpace', 'NoSpaceBeforeComma', 'CurlyQuote', 'Hyphen', 'Trademark'));
173+
$fixer->setLocale('fr_FR');
178174
```
179175

180176
fr_CA
@@ -183,8 +179,8 @@ fr_CA
183179
Mostly the same as fr_FR, but the space before punctuation points is not mandatory.
184180

185181
```php
186-
$fixer = new Fixer(array('Ellipsis', 'Dimension', 'Numeric', 'Dash', 'FrenchQuotes', 'NoSpaceBeforeComma', 'CurlyQuote', 'Hyphen', 'Trademark'));
187-
$fixer->setLocale('fr_CA'); // Needed by the Hyphen Fixer
182+
$fixer = new Fixer(array('Ellipsis', 'Dimension', 'Numeric', 'Dash', 'SmartQuotes', 'NoSpaceBeforeComma', 'CurlyQuote', 'Hyphen', 'Trademark'));
183+
$fixer->setLocale('fr_CA');
188184
```
189185

190186
de_DE
@@ -193,8 +189,8 @@ de_DE
193189
Mostly the same as en_GB, according to [Typefacts](http://typefacts.com/) and [Wikipedia](http://de.wikipedia.org/wiki/Typografie_f%C3%BCr_digitale_Texte).
194190

195191
```php
196-
$fixer = new Fixer(array('Ellipsis', 'Dimension', 'Numeric', 'Dash', 'GermanQuotes', 'NoSpaceBeforeComma', 'CurlyQuote', 'Hyphen', 'Trademark'));
197-
$fixer->setLocale('de_DE'); // Needed by the Hyphen Fixer
192+
$fixer = new Fixer(array('Ellipsis', 'Dimension', 'Numeric', 'Dash', 'SmartQuotes', 'NoSpaceBeforeComma', 'CurlyQuote', 'Hyphen', 'Trademark'));
193+
$fixer->setLocale('de_DE');
198194
```
199195

200196
More to come (contributions welcome!).
@@ -207,14 +203,14 @@ Default usage
207203
-------------
208204

209205
```php
210-
$fixer = new Fixer(array('Ellipsis', 'Dimension', 'Dash', 'EnglishQuotes', 'CurlyQuote', 'Hyphen'));
206+
$fixer = new Fixer(array('Ellipsis', 'Dimension', 'Dash', 'SmartQuotes', 'CurlyQuote', 'Hyphen'));
211207
$fixed_content = $fixer->fix("<p>Some user contributed HTML which does not use proper glyphs.</p>");
212208

213209
$fixer->setRules(array('CurlyQuote'));
214210
$fixed_content = $fixer->fix("<p>I'm only replacing single quotes.</p>");
215211

216212
$fixer->setRules(array('Hyphen'));
217-
$fixer->setLocale('en_GB'); // I tell which locale to use for Hyphenation
213+
$fixer->setLocale('en_GB'); // I tell which locale to use for Hyphenation and SmartQuotes
218214
$fixed_content = $fixer->fix("<p>Very long words like Antidisestablishmentarianism.</p>");
219215
```
220216

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
/*
4+
* This file is part of JoliTypo - a project by JoliCode.
5+
*
6+
* This software consists of voluntary contributions made by many individuals
7+
* and is licensed under the MIT license.
8+
*/
9+
10+
namespace JoliTypo\Exception;
11+
12+
class BadFixerConfigurationException extends \Exception
13+
{
14+
protected $message = 'Fixer needs configuration.';
15+
}

src/JoliTypo/Fixer/EnglishQuotes.php

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,13 @@
99

1010
namespace JoliTypo\Fixer;
1111

12-
use JoliTypo\Fixer;
13-
use JoliTypo\FixerInterface;
14-
use JoliTypo\StateBag;
15-
1612
/**
17-
* Convert dumb quotes (" ") to smart quotes (“ ”).
13+
* @deprecated Use SmartQuotes, to be removed in 2.0
1814
*/
19-
class EnglishQuotes extends BaseOpenClosePair implements FixerInterface
15+
class EnglishQuotes extends SmartQuotes
2016
{
21-
public function fix($content, StateBag $stateBag = null)
17+
public function __construct($locale = null)
2218
{
23-
// Fix complex siblings cases
24-
if ($stateBag) {
25-
$content = $this->fixViaState($content, $stateBag, 'EnglishQuotesOpenSolo',
26-
'@(^|\s|\()"([^"]*)$@', '@(^|[^"]+)"@im', Fixer::LDQUO, Fixer::RDQUO);
27-
}
28-
29-
$content = preg_replace(
30-
'@(^|\s|\()"([^"]+)"@im',
31-
'$1'.Fixer::LDQUO.'$2'.Fixer::RDQUO,
32-
$content);
33-
34-
return $content;
19+
parent::__construct('en');
3520
}
3621
}

src/JoliTypo/Fixer/FrenchQuotes.php

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,13 @@
99

1010
namespace JoliTypo\Fixer;
1111

12-
use JoliTypo\Fixer;
13-
use JoliTypo\FixerInterface;
14-
use JoliTypo\StateBag;
15-
1612
/**
17-
* Use NO_BREAK_SPACE between the « » and the text as
18-
* recommended by "Abrégé du code typographique à l'usage de la presse", ISBN: 978-2351130667.
13+
* @deprecated Use SmartQuotes, to be removed in 2.0
1914
*/
20-
class FrenchQuotes extends BaseOpenClosePair implements FixerInterface
15+
class FrenchQuotes extends SmartQuotes
2116
{
22-
public function fix($content, StateBag $stateBag = null)
17+
public function __construct($locale = null)
2318
{
24-
// Fix complex siblings cases
25-
if ($stateBag) {
26-
$content = $this->fixViaState($content, $stateBag, 'FrenchQuotesOpenSolo',
27-
'@(^|\s|\()"([^"]*)$@im', '@(^|[^"]+)"@im', Fixer::LAQUO.Fixer::NO_BREAK_SPACE,
28-
Fixer::NO_BREAK_SPACE.Fixer::RAQUO);
29-
}
30-
31-
// Fix simple cases
32-
$content = preg_replace('@(^|\s|\()"([^"]+)"@im',
33-
'$1'.Fixer::LAQUO.Fixer::NO_BREAK_SPACE.'$2'.Fixer::NO_BREAK_SPACE.Fixer::RAQUO,
34-
$content);
35-
36-
return $content;
19+
parent::__construct('fr');
3720
}
3821
}

src/JoliTypo/Fixer/GermanQuotes.php

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,13 @@
99

1010
namespace JoliTypo\Fixer;
1111

12-
use JoliTypo\Fixer;
13-
use JoliTypo\FixerInterface;
14-
use JoliTypo\StateBag;
15-
1612
/**
17-
* Convert dumb quotes (" ") to smart quotes („ “).
13+
* @deprecated Use SmartQuotes, to be removed in 2.0
1814
*/
19-
class GermanQuotes extends BaseOpenClosePair implements FixerInterface
15+
class GermanQuotes extends SmartQuotes
2016
{
21-
public function fix($content, StateBag $stateBag = null)
17+
public function __construct($locale = null)
2218
{
23-
// Fix complex siblings cases
24-
if ($stateBag) {
25-
$content = $this->fixViaState($content, $stateBag, 'GermanQuotesOpenSolo',
26-
'@(^|\s|\()"([^"]*)$@', '@(^|[^"]+)"@im', Fixer::BDQUO, Fixer::LDQUO);
27-
}
28-
29-
$content = preg_replace(
30-
'@(^|\s|\()"([^"]+)"@im',
31-
'$1'.Fixer::BDQUO.'$2'.Fixer::LDQUO,
32-
$content);
33-
34-
return $content;
19+
parent::__construct('de');
3520
}
3621
}

src/JoliTypo/Fixer/Hyphen.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ class Hyphen implements FixerInterface, LocaleAwareFixerInterface
3131

3232
public function __construct($locale)
3333
{
34-
$this->hyphenator = Hyphenator::factory(null, $this->fixLocale($locale));
35-
$this->setOptions();
34+
$this->setLocale($locale);
3635
}
3736

3837
/**

0 commit comments

Comments
 (0)