1
- Syllable
2
- ========
1
+ # Syllable
2
+
3
3
Version 1.6
4
4
5
5
[ ![ Tests] ( https://github.com/vanderlee/phpSyllable/actions/workflows/tests.yml/badge.svg )] ( https://github.com/vanderlee/phpSyllable/actions/workflows/tests.yml )
6
6
7
7
Copyright © ; 2011-2023 Martijn van der Lee.
8
8
MIT Open Source license applies.
9
9
10
- Introduction
11
- ------------
10
+
11
+ ## Introduction
12
+
12
13
PHP Syllable splitting and hyphenation.
13
14
or rather...
14
15
PHP Syl-la-ble split-ting and hy-phen-ation.
@@ -23,8 +24,8 @@ Language sources: http://tug.org/tex-hyphen/#languages
23
24
24
25
Supports PHP 5.6 and up, so you can use it on older servers.
25
26
26
- Quick start
27
- -----------
27
+
28
+ ## Installation
28
29
29
30
Install phpSyllable via Composer
30
31
@@ -35,7 +36,10 @@ composer require vanderlee/syllable
35
36
or simply add phpSyllable to your project and set up the project's
36
37
autoloader for phpSyllable's src/ directory.
37
38
38
- Then instantiate a Syllable object and start hyphenation.
39
+
40
+ ## Usage
41
+
42
+ Instantiate a Syllable object and start hyphenation.
39
43
40
44
Minimal example:
41
45
@@ -51,6 +55,9 @@ use Vanderlee\Syllable\Syllable;
51
55
use Vanderlee\Syllable\Hyphen;
52
56
53
57
// Globally set the directory where Syllable can store cache files.
58
+ // By default, this is the cache/ folder in this package, but usually
59
+ // you want to have the folder outside the package. Note that the cache
60
+ // folder must be created beforehand.
54
61
Syllable::setCacheDir(__DIR__ . '/cache');
55
62
56
63
// Globally set the directory where the .tex files are stored.
@@ -75,137 +82,139 @@ echo $syllable->hyphenateText('Provide your own paragraphs...');
75
82
76
83
See the [ demo.php] ( demo.php ) file for a working example.
77
84
78
- ` Syllable ` class reference
79
- --------------------------
80
- The following is an incomplete list, containing only the most common methods.
81
- For a complete documentation of all classes, read the generated [ PHPDoc] ( doc ) .
82
85
83
- ### public __ construct($language = 'en', string|Hyphen $hyphen = null)
86
+ ## ` Syllable ` API reference
87
+
88
+ The following describes the API of the main Syllable class. In most cases,
89
+ you will not use any other functions. Browse the code under src/ for all
90
+ available functions.
91
+
92
+ #### public __ construct($language = 'en-us', string|Hyphen $hyphen = null)
84
93
85
94
Create a new Syllable class, with defaults.
86
95
87
- ### public static setCacheDir(string $dir)
96
+ #### public static setCacheDir(string $dir)
88
97
89
98
Set the directory where compiled language files may be stored.
90
99
Default to the ` cache ` subdirectory of the current directory.
91
100
92
- ### public static setEncoding(string|null $encoding = null)
101
+ #### public static setEncoding(string|null $encoding = null)
93
102
94
103
Set the character encoding to use.
95
104
Specify ` null ` encoding to not apply any encoding at all.
96
105
97
- ### public static setLanguageDir(string $dir)
106
+ #### public static setLanguageDir(string $dir)
98
107
99
108
Set the directory where language source files can be found.
100
109
Default to the ` languages ` subdirectory of the current directory.
101
110
102
- ### public setLanguage(string $language)
111
+ #### public setLanguage(string $language)
103
112
104
113
Set the language whose rules will be used for hyphenation.
105
114
106
- ### public setHyphen(mixed $hyphen)
115
+ #### public setHyphen(mixed $hyphen)
107
116
108
117
Set the hyphen text or object to use as a hyphen marker.
109
118
110
- ### public getHyphen(): Hyphen
119
+ #### public getHyphen(): Hyphen
111
120
112
121
Get the current hyphen object.
113
122
114
- ### public setCache(Cache $cache = null)
123
+ #### public setCache(Cache $cache = null)
115
124
116
- ### public getCache(): Cache
125
+ #### public getCache(): Cache
117
126
118
- ### public setSource($source)
127
+ #### public setSource($source)
119
128
120
- ### public getSource(): Source
129
+ #### public getSource(): Source
121
130
122
- ### public setMinWordLength(int $length = 0)
131
+ #### public setMinWordLength(int $length = 0)
123
132
124
133
Words need to contain at least this many character to be hyphenated.
125
134
126
- ### public getMinWordLength(): int
135
+ #### public getMinWordLength(): int
127
136
128
- ### public setLibxmlOptions(int $libxmlOptions)
137
+ #### public setLibxmlOptions(int $libxmlOptions)
129
138
130
139
Options to use for HTML parsing by libxml.
131
140
See https://www.php.net/manual/de/libxml.constants.php .
132
141
133
- ### public excludeAll()
142
+ #### public excludeAll()
134
143
135
144
Exclude all elements.
136
145
137
- ### public excludeElement(string|string[ ] $elements)
146
+ #### public excludeElement(string|string[ ] $elements)
138
147
139
148
Add one or more elements to exclude from HTML.
140
149
141
- ### public excludeAttribute(string|string[ ] $attributes, $value = null)
150
+ #### public excludeAttribute(string|string[ ] $attributes, $value = null)
142
151
143
152
Add one or more elements with attributes to exclude from HTML.
144
153
145
- ### public excludeXpath(string|string[ ] $queries)
154
+ #### public excludeXpath(string|string[ ] $queries)
146
155
147
156
Add one or more xpath queries to exclude from HTML.
148
157
149
- ### public includeElement(string|string[ ] $elements)
158
+ #### public includeElement(string|string[ ] $elements)
150
159
151
160
Add one or more elements to include from HTML.
152
161
153
- ### public includeAttribute(string|string[ ] $attributes, $value = null)
162
+ #### public includeAttribute(string|string[ ] $attributes, $value = null)
154
163
155
164
Add one or more elements with attributes to include from HTML.
156
165
157
- ### public includeXpath(string|string[ ] $queries)
166
+ #### public includeXpath(string|string[ ] $queries)
158
167
159
168
Add one or more xpath queries to include from HTML.
160
169
161
- ### public splitWord(string $word): array
170
+ #### public splitWord(string $word): array
162
171
163
172
Split a single word on where the hyphenation would go.
164
173
Punctuation is not supported, only simple words. For parsing whole sentences
165
174
please use Syllable::splitWords() or Syllable::splitText().
166
175
167
- ### public splitWords(string $text): array
176
+ #### public splitWords(string $text): array
168
177
169
178
Split a text into an array of punctuation marks and words,
170
179
splitting each word on where the hyphenation would go.
171
180
172
- ### public splitText(string $text): array
181
+ #### public splitText(string $text): array
173
182
174
183
Split a text on where the hyphenation would go.
175
184
176
- ### public hyphenateWord(string $word): string
185
+ #### public hyphenateWord(string $word): string
177
186
178
187
Hyphenate a single word.
179
188
180
- ### public hyphenateText(string $text): string
189
+ #### public hyphenateText(string $text): string
181
190
182
191
Hyphenate all words in the plain text.
183
192
184
- ### public hyphenateHtml(string $html): string
193
+ #### public hyphenateHtml(string $html): string
185
194
186
195
Hyphenate all readable text in the HTML, excluding HTML tags and
187
196
attributes.
188
197
189
- ### public histogramText(string $text): array
198
+ #### public histogramText(string $text): array
190
199
191
200
Count the number of syllables in the text and return a map with
192
201
syllable count as key and number of words for that syllable count as
193
202
the value.
194
203
195
- ### public countWordsText(string $text): int
204
+ #### public countWordsText(string $text): int
196
205
197
206
Count the number of words in the text.
198
207
199
- ### public countSyllablesText(string $text): int
208
+ #### public countSyllablesText(string $text): int
200
209
201
210
Count the number of syllables in the text.
202
211
203
- ### public countPolysyllablesText(string $text): int
212
+ #### public countPolysyllablesText(string $text): int
204
213
205
214
Count the number of polysyllables in the text.
206
215
207
- Development
208
- -----------
216
+
217
+ ## Development
209
218
210
219
### Update language files
211
220
@@ -312,8 +321,8 @@ composer install
312
321
to execute the tests.
313
322
314
323
315
- Changes
316
- -------
324
+ ## Changes
325
+
317
326
1.6
318
327
- Revert renaming of API method names
319
328
- Use cache version as string instead of number
0 commit comments