1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Typogrify plugin for Craft CMS |
4
|
|
|
* |
5
|
|
|
* Typogrify prettifies your web typography by preventing ugly quotes and 'widows' and more |
6
|
|
|
* |
7
|
|
|
* @link https://nystudio107.com/ |
|
|
|
|
8
|
|
|
* @copyright Copyright (c) nystudio107 |
|
|
|
|
9
|
|
|
*/ |
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace nystudio107\typogrify\models; |
12
|
|
|
|
13
|
|
|
use craft\base\Model; |
14
|
|
|
use craft\validators\ArrayValidator; |
15
|
|
|
use PHP_Typography\Settings\Dash_Style; |
16
|
|
|
use PHP_Typography\Settings\Quote_Style; |
17
|
|
|
|
18
|
|
|
/** |
|
|
|
|
19
|
|
|
* @author nystudio107 |
|
|
|
|
20
|
|
|
* @package Typogrify |
|
|
|
|
21
|
|
|
* @since 1.0.0 |
|
|
|
|
22
|
|
|
*/ |
|
|
|
|
23
|
|
|
class Settings extends Model |
24
|
|
|
{ |
25
|
|
|
// Public Properties |
26
|
|
|
// ========================================================================= |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* sets whether input should be escaped by default |
|
|
|
|
30
|
|
|
* |
31
|
|
|
* @var bool |
32
|
|
|
*/ |
33
|
|
|
public bool $default_escape = false; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* sets tags where typography of children will be untouched |
|
|
|
|
37
|
|
|
* |
38
|
|
|
* @var array |
39
|
|
|
*/ |
40
|
|
|
public array $set_tags_to_ignore = [ |
41
|
|
|
"code", |
42
|
|
|
"head", |
43
|
|
|
"kbd", |
44
|
|
|
"object", |
45
|
|
|
"option", |
46
|
|
|
"pre", |
47
|
|
|
"samp", |
48
|
|
|
"script", |
49
|
|
|
"noscript", |
50
|
|
|
"noembed", |
51
|
|
|
"select", |
52
|
|
|
"style", |
53
|
|
|
"textarea", |
54
|
|
|
"title", |
55
|
|
|
"var", |
56
|
|
|
"math", |
57
|
|
|
]; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* sets classes where typography of children will be untouched |
|
|
|
|
61
|
|
|
* |
62
|
|
|
* @var array |
63
|
|
|
*/ |
64
|
|
|
public array $set_classes_to_ignore = [ |
65
|
|
|
"vcard", |
66
|
|
|
"noTypo", |
67
|
|
|
]; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* sets IDs where typography of children will be untouched |
|
|
|
|
71
|
|
|
* |
72
|
|
|
* @var array |
73
|
|
|
*/ |
74
|
|
|
public array $set_ids_to_ignore = [ |
75
|
|
|
]; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* curl quotemarks |
|
|
|
|
79
|
|
|
* |
80
|
|
|
* @var bool |
81
|
|
|
*/ |
82
|
|
|
public bool $set_smart_quotes = true; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Primary quotemarks style |
86
|
|
|
* allowed values for $style |
87
|
|
|
* "doubleCurled = "“foo”", |
88
|
|
|
* "doubleCurledReversed = "”foo”", |
89
|
|
|
* "doubleLow9 = "„foo”", |
90
|
|
|
* "doubleLow9Reversed = "„foo“", |
91
|
|
|
* "singleCurled = "‘foo’", |
92
|
|
|
* "singleCurledReversed = "’foo’", |
93
|
|
|
* "singleLow9 = "‚foo’", |
94
|
|
|
* "singleLow9Reversed = "‚foo‘", |
95
|
|
|
* "doubleGuillemetsFrench = "« foo »", |
96
|
|
|
* "doubleGuillemets = "«foo»", |
97
|
|
|
* "doubleGuillemetsReversed = "»foo«", |
98
|
|
|
* "singleGuillemets = "‹foo›", |
99
|
|
|
* "singleGuillemetsReversed = "›foo‹", |
100
|
|
|
* "cornerBrackets = "「foo」", |
101
|
|
|
* "whiteCornerBracket = "『foo』", |
102
|
|
|
* |
103
|
|
|
* @var string |
104
|
|
|
*/ |
105
|
|
|
public string $set_smart_quotes_primary = Quote_Style::DOUBLE_CURLED; |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Secondary quotemarks style |
109
|
|
|
* allowed values for $style |
110
|
|
|
* "doubleCurled = "“foo”", |
111
|
|
|
* "doubleCurledReversed = "”foo”", |
112
|
|
|
* "doubleLow9 = "„foo”", |
113
|
|
|
* "doubleLow9Reversed = "„foo“", |
114
|
|
|
* "singleCurled = "‘foo’", |
115
|
|
|
* "singleCurledReversed = "’foo’", |
116
|
|
|
* "singleLow9 = "‚foo’", |
117
|
|
|
* "singleLow9Reversed = "‚foo‘", |
118
|
|
|
* "doubleGuillemetsFrench = "« foo »", |
119
|
|
|
* "doubleGuillemets = "«foo»", |
120
|
|
|
* "doubleGuillemetsReversed = "»foo«", |
121
|
|
|
* "singleGuillemets = "‹foo›", |
122
|
|
|
* "singleGuillemetsReversed = "›foo‹", |
123
|
|
|
* "cornerBrackets = "「foo」", |
124
|
|
|
* "whiteCornerBracket = "『foo』", |
125
|
|
|
* |
126
|
|
|
* @var string |
127
|
|
|
*/ |
128
|
|
|
public string $set_smart_quotes_secondary = Quote_Style::SINGLE_CURLED; |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* replaces "a--a" with En Dash " -- " and "---" with Em Dash |
|
|
|
|
132
|
|
|
* |
133
|
|
|
* @var bool |
134
|
|
|
*/ |
135
|
|
|
public bool $set_smart_dashes = true; |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Sets the typographical conventions used by smart_dashes. |
139
|
|
|
* |
140
|
|
|
* Allowed values for $style: |
141
|
|
|
* - "traditionalUS" |
142
|
|
|
* - "international" |
143
|
|
|
* |
144
|
|
|
* @var string |
145
|
|
|
*/ |
146
|
|
|
public string $set_smart_dashes_style = Dash_Style::TRADITIONAL_US; |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* replaces "..." with "…" |
|
|
|
|
150
|
|
|
* |
151
|
|
|
* @var bool |
152
|
|
|
*/ |
153
|
|
|
public bool $set_smart_ellipses = true; |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* replaces "creme brulee" with "crème brûlée" |
|
|
|
|
157
|
|
|
* |
158
|
|
|
* @var bool |
159
|
|
|
*/ |
160
|
|
|
public bool $set_smart_diacritics = true; |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* defines hyphenation language for text |
|
|
|
|
164
|
|
|
* |
165
|
|
|
* @var string |
166
|
|
|
*/ |
167
|
|
|
public string $set_diacritic_language = "en-US"; |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* $customReplacements must be |
171
|
|
|
* an array formatted array(needle=>replacement, needle=>replacement...), or |
172
|
|
|
* a string formatted `"needle"=>"replacement","needle"=>"replacement",...` |
173
|
|
|
* |
174
|
|
|
* @var array |
175
|
|
|
*/ |
176
|
|
|
public array $set_diacritic_custom_replacements = [ |
177
|
|
|
]; |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* replaces (r) (c) (tm) (sm) (p) (R) (C) (TM) (SM) (P) with ® © ™ ℠ ℗ |
|
|
|
|
181
|
|
|
* |
182
|
|
|
* @var bool |
183
|
|
|
*/ |
184
|
|
|
public bool $set_smart_marks = true; |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* replaces 1*4 with 1x4, etc. |
|
|
|
|
188
|
|
|
* |
189
|
|
|
* @var bool |
190
|
|
|
*/ |
191
|
|
|
public bool $set_smart_math = true; |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* replaces 2^4 with 2<sup>4</sup> |
|
|
|
|
195
|
|
|
* |
196
|
|
|
* @var bool |
197
|
|
|
*/ |
198
|
|
|
public bool $set_smart_exponents = true; |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* replaces 1/4 with <sup>1</sup>⁄<sub>4</sub> |
|
|
|
|
202
|
|
|
* |
203
|
|
|
* @var bool |
204
|
|
|
*/ |
205
|
|
|
public bool $set_smart_fractions = true; |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* Enables/disables replacement of 1st with 1<sup>st</sup> |
209
|
|
|
* |
210
|
|
|
* @var bool |
211
|
|
|
*/ |
212
|
|
|
public bool $set_smart_ordinal_suffix = true; |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* single character words are forced to next line with insertion of |
|
|
|
|
216
|
|
|
* |
217
|
|
|
* @var bool |
218
|
|
|
*/ |
219
|
|
|
public bool $set_single_character_word_spacing = true; |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* fractions are kept together with insertion of |
|
|
|
|
223
|
|
|
* |
224
|
|
|
* @var bool |
225
|
|
|
*/ |
226
|
|
|
public bool $set_fraction_spacing = true; |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* units and values are kept together with insertion of |
|
|
|
|
230
|
|
|
* |
231
|
|
|
* @var bool |
232
|
|
|
*/ |
233
|
|
|
public bool $set_unit_spacing = true; |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* Enables/disables extra whitespace before certain punction marks, as is the French custom. |
237
|
|
|
* |
238
|
|
|
* @var bool |
239
|
|
|
*/ |
240
|
|
|
public bool $set_french_punctuation_spacing = false; |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* a list of units to keep with their values |
|
|
|
|
244
|
|
|
* |
245
|
|
|
* @var array |
246
|
|
|
*/ |
247
|
|
|
public array $set_units = [ |
248
|
|
|
]; |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* Em and En dashes are wrapped in thin spaces |
252
|
|
|
* |
253
|
|
|
* @var bool |
254
|
|
|
*/ |
255
|
|
|
public bool $set_dash_spacing = true; |
256
|
|
|
|
257
|
|
|
/** |
258
|
|
|
* Remove extra space characters |
259
|
|
|
* |
260
|
|
|
* @var bool |
261
|
|
|
*/ |
262
|
|
|
public bool $set_space_collapse = true; |
263
|
|
|
|
264
|
|
|
/** |
265
|
|
|
* Enable usage of true "no-break narrow space" ( ) instead of the normal no-break space ( ). |
266
|
|
|
* |
267
|
|
|
* @var bool |
268
|
|
|
*/ |
269
|
|
|
public bool $set_true_no_break_narrow_space = false; |
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* enables widow handling |
|
|
|
|
273
|
|
|
* |
274
|
|
|
* @var bool |
275
|
|
|
*/ |
276
|
|
|
public bool $set_dewidow = true; |
277
|
|
|
|
278
|
|
|
/** |
279
|
|
|
* establishes maximum length of a widows that will be protected |
|
|
|
|
280
|
|
|
* |
281
|
|
|
* @var int |
282
|
|
|
*/ |
283
|
|
|
public int $set_max_dewidow_length = 5; |
284
|
|
|
|
285
|
|
|
/** |
286
|
|
|
* establishes the maximum number of words considered for dewidowing. |
|
|
|
|
287
|
|
|
* |
288
|
|
|
* @var int |
289
|
|
|
*/ |
290
|
|
|
public int $set_dewidow_word_number = 1; |
291
|
|
|
|
292
|
|
|
/** |
293
|
|
|
* establishes maximum length of pulled text to keep widows company |
|
|
|
|
294
|
|
|
* |
295
|
|
|
* @var int |
296
|
|
|
*/ |
297
|
|
|
public int $set_max_dewidow_pull = 5; |
298
|
|
|
|
299
|
|
|
/** |
300
|
|
|
* enables wrapping at hard hyphens internal to a word with the insertion of a zero-width-space |
|
|
|
|
301
|
|
|
* |
302
|
|
|
* @var bool |
303
|
|
|
*/ |
304
|
|
|
public bool $set_wrap_hard_hyphens = true; |
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* enables wrapping of urls |
|
|
|
|
308
|
|
|
* |
309
|
|
|
* @var bool |
310
|
|
|
*/ |
311
|
|
|
public bool $set_url_wrap = true; |
312
|
|
|
|
313
|
|
|
/** |
314
|
|
|
* enables wrapping of email addresses |
|
|
|
|
315
|
|
|
* |
316
|
|
|
* @var bool |
317
|
|
|
*/ |
318
|
|
|
public bool $set_email_wrap = true; |
319
|
|
|
|
320
|
|
|
/** |
321
|
|
|
* establishes minimum character requirement after a url wrapping point |
|
|
|
|
322
|
|
|
* |
323
|
|
|
* @var int |
324
|
|
|
*/ |
325
|
|
|
public int $set_min_after_url_wrap = 5; |
326
|
|
|
|
327
|
|
|
/** |
328
|
|
|
* wrap ampersands in <span class="amp"> |
|
|
|
|
329
|
|
|
* |
330
|
|
|
* @var bool |
331
|
|
|
*/ |
332
|
|
|
public bool $set_style_ampersands = true; |
333
|
|
|
|
334
|
|
|
/** |
335
|
|
|
* wrap caps in <span class="caps"> |
|
|
|
|
336
|
|
|
* |
337
|
|
|
* @var bool |
338
|
|
|
*/ |
339
|
|
|
public bool $set_style_caps = true; |
340
|
|
|
|
341
|
|
|
/** |
342
|
|
|
* wrap initial quotes in <span class="quo"> or <span class="dquo"> |
|
|
|
|
343
|
|
|
* |
344
|
|
|
* @var bool |
345
|
|
|
*/ |
346
|
|
|
public bool $set_style_initial_quotes = true; |
347
|
|
|
|
348
|
|
|
/** |
349
|
|
|
* wrap numbers in <span class="numbers"> |
|
|
|
|
350
|
|
|
* |
351
|
|
|
* @var bool |
352
|
|
|
*/ |
353
|
|
|
public bool $set_style_numbers = true; |
354
|
|
|
|
355
|
|
|
/** |
356
|
|
|
* sets tags where initial quotes and guillemets should be styled |
|
|
|
|
357
|
|
|
* |
358
|
|
|
* @var array |
359
|
|
|
*/ |
360
|
|
|
public array $set_initial_quote_tags = [ |
361
|
|
|
"p", |
362
|
|
|
"h1", |
363
|
|
|
"h2", |
364
|
|
|
"h3", |
365
|
|
|
"h4", |
366
|
|
|
"h5", |
367
|
|
|
"h6", |
368
|
|
|
"blockquote", |
369
|
|
|
"li", |
370
|
|
|
"dd", |
371
|
|
|
"dt", |
372
|
|
|
]; |
373
|
|
|
|
374
|
|
|
/** |
375
|
|
|
* enables hyphenation of text |
|
|
|
|
376
|
|
|
* |
377
|
|
|
* @var bool |
378
|
|
|
*/ |
379
|
|
|
public bool $set_hyphenation = true; |
380
|
|
|
|
381
|
|
|
/** |
382
|
|
|
* defines hyphenation language for text |
|
|
|
|
383
|
|
|
* |
384
|
|
|
* @var string |
385
|
|
|
*/ |
386
|
|
|
public string $set_hyphenation_language = "en-US"; |
387
|
|
|
|
388
|
|
|
/** |
389
|
|
|
* establishes minimum length of a word that may be hyphenated |
|
|
|
|
390
|
|
|
* |
391
|
|
|
* @var int |
392
|
|
|
*/ |
393
|
|
|
public int $set_min_length_hyphenation = 5; |
394
|
|
|
|
395
|
|
|
/** |
396
|
|
|
* establishes minimum character requirement before a hyphenation point |
|
|
|
|
397
|
|
|
* |
398
|
|
|
* @var int |
399
|
|
|
*/ |
400
|
|
|
public int $set_min_before_hyphenation = 3; |
401
|
|
|
|
402
|
|
|
/** |
403
|
|
|
* establishes minimum character requirement after a hyphenation point |
|
|
|
|
404
|
|
|
* |
405
|
|
|
* @var int |
406
|
|
|
*/ |
407
|
|
|
public int $set_min_after_hyphenation = 2; |
408
|
|
|
|
409
|
|
|
/** |
410
|
|
|
* allows/disallows hyphenation of title/heading text |
|
|
|
|
411
|
|
|
* |
412
|
|
|
* @var bool |
413
|
|
|
*/ |
414
|
|
|
public bool $set_hyphenate_headings = true; |
415
|
|
|
|
416
|
|
|
/** |
417
|
|
|
* allows hyphenation of strings of all capital characters |
|
|
|
|
418
|
|
|
* |
419
|
|
|
* @var bool |
420
|
|
|
*/ |
421
|
|
|
public bool $set_hyphenate_all_caps = true; |
422
|
|
|
|
423
|
|
|
/** |
424
|
|
|
* allows hyphenation of strings of all capital characters |
|
|
|
|
425
|
|
|
* |
426
|
|
|
* @var bool |
427
|
|
|
*/ |
428
|
|
|
public bool $set_hyphenate_title_case = true; |
429
|
|
|
|
430
|
|
|
/** |
431
|
|
|
* defines custom word hyphenations |
|
|
|
|
432
|
|
|
* expected input is an array of words with all hyphenation points marked with a hard hyphen |
433
|
|
|
* |
434
|
|
|
* @var array |
435
|
|
|
*/ |
436
|
|
|
public array $set_hyphenation_exceptions = [ |
437
|
|
|
]; |
438
|
|
|
|
439
|
|
|
/** |
440
|
|
|
* Enable lenient parser error handling (HTML is "best guess" if enabled). |
441
|
|
|
* |
442
|
|
|
* @var bool |
443
|
|
|
*/ |
444
|
|
|
public bool $set_ignore_parser_errors = true; |
445
|
|
|
|
446
|
|
|
/** |
447
|
|
|
* Sets an optional handler for parser errors. Invalid callbacks will be silently ignored |
448
|
|
|
* |
449
|
|
|
* @var callable|null |
450
|
|
|
*/ |
451
|
|
|
public $set_parser_errors_handler = null; |
452
|
|
|
|
453
|
|
|
// Public Methods |
454
|
|
|
// ========================================================================= |
455
|
|
|
|
456
|
|
|
/** |
|
|
|
|
457
|
|
|
* @inheritdoc |
458
|
|
|
*/ |
|
|
|
|
459
|
|
|
public function rules(): array |
460
|
|
|
{ |
461
|
|
|
return [ |
462
|
|
|
[ |
463
|
|
|
[ |
464
|
|
|
'set_smart_quotes_primary', |
465
|
|
|
'set_smart_quotes_secondary', |
466
|
|
|
'set_smart_quotes_secondary', |
467
|
|
|
'set_diacritic_language', |
468
|
|
|
'set_hyphenation_language', |
469
|
|
|
], |
470
|
|
|
'string', |
471
|
|
|
], |
472
|
|
|
[ |
473
|
|
|
[ |
474
|
|
|
'set_max_dewidow_length', |
475
|
|
|
'set_dewidow_word_number', |
476
|
|
|
'set_max_dewidow_pull', |
477
|
|
|
'set_min_after_url_wrap', |
478
|
|
|
'set_min_length_hyphenation', |
479
|
|
|
'set_min_before_hyphenation', |
480
|
|
|
'set_min_after_hyphenation', |
481
|
|
|
], |
482
|
|
|
'integer', |
483
|
|
|
], |
484
|
|
|
[ |
485
|
|
|
[ |
486
|
|
|
'set_smart_quotes', |
487
|
|
|
'set_smart_dashes', |
488
|
|
|
'set_smart_ellipses', |
489
|
|
|
'set_smart_diacritics', |
490
|
|
|
'set_smart_dashes', |
491
|
|
|
'set_smart_ellipses', |
492
|
|
|
'set_smart_diacritics', |
493
|
|
|
'set_smart_marks', |
494
|
|
|
'set_smart_math', |
495
|
|
|
'set_smart_exponents', |
496
|
|
|
'set_smart_fractions', |
497
|
|
|
'set_smart_ordinal_suffix', |
498
|
|
|
'set_single_character_word_spacing', |
499
|
|
|
'set_fraction_spacing', |
500
|
|
|
'set_unit_spacing', |
501
|
|
|
'set_dash_spacing', |
502
|
|
|
'set_space_collapse', |
503
|
|
|
'set_true_no_break_narrow_space', |
504
|
|
|
'set_dewidow', |
505
|
|
|
'set_wrap_hard_hyphens', |
506
|
|
|
'set_url_wrap', |
507
|
|
|
'set_email_wrap', |
508
|
|
|
'set_style_ampersands', |
509
|
|
|
'set_style_caps', |
510
|
|
|
'set_style_initial_quotes', |
511
|
|
|
'set_style_numbers', |
512
|
|
|
'set_hyphenation', |
513
|
|
|
'set_hyphenate_headings', |
514
|
|
|
'set_hyphenate_all_caps', |
515
|
|
|
'set_hyphenate_title_case', |
516
|
|
|
'set_ignore_parser_errors', |
517
|
|
|
], |
518
|
|
|
'boolean', |
519
|
|
|
], |
520
|
|
|
[ |
521
|
|
|
[ |
522
|
|
|
'set_tags_to_ignore', |
523
|
|
|
'set_classes_to_ignore', |
524
|
|
|
'set_ids_to_ignore', |
525
|
|
|
'set_diacritic_custom_replacements', |
526
|
|
|
'set_units', |
527
|
|
|
'set_initial_quote_tags', |
528
|
|
|
'set_hyphenation_exceptions', |
529
|
|
|
], |
530
|
|
|
ArrayValidator::class, |
531
|
|
|
], |
532
|
|
|
[ |
533
|
|
|
[ |
534
|
|
|
'set_parser_errors_handler', |
535
|
|
|
], |
536
|
|
|
'safe', |
537
|
|
|
], |
538
|
|
|
]; |
539
|
|
|
} |
540
|
|
|
} |
541
|
|
|
|