1- Syllable
2- ========
1+ # Syllable
2+
33Version 1.6
44
55[ ![ Tests] ( https://github.com/vanderlee/phpSyllable/actions/workflows/tests.yml/badge.svg )] ( https://github.com/vanderlee/phpSyllable/actions/workflows/tests.yml )
66
77Copyright © ; 2011-2023 Martijn van der Lee.
88MIT Open Source license applies.
99
10- Introduction
11- ------------
10+
11+ ## Introduction
12+
1213PHP Syllable splitting and hyphenation.
1314or rather...
1415PHP Syl-la-ble split-ting and hy-phen-ation.
@@ -23,8 +24,8 @@ Language sources: http://tug.org/tex-hyphen/#languages
2324
2425Supports PHP 5.6 and up, so you can use it on older servers.
2526
26- Quick start
27- -----------
27+
28+ ## Installation
2829
2930Install phpSyllable via Composer
3031
@@ -35,7 +36,10 @@ composer require vanderlee/syllable
3536or simply add phpSyllable to your project and set up the project's
3637autoloader for phpSyllable's src/ directory.
3738
38- Then instantiate a Syllable object and start hyphenation.
39+
40+ ## Usage
41+
42+ Instantiate a Syllable object and start hyphenation.
3943
4044Minimal example:
4145
@@ -51,6 +55,9 @@ use Vanderlee\Syllable\Syllable;
5155use Vanderlee\Syllable\Hyphen;
5256
5357// 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.
5461Syllable::setCacheDir(__DIR__ . '/cache');
5562
5663// Globally set the directory where the .tex files are stored.
@@ -75,137 +82,139 @@ echo $syllable->hyphenateText('Provide your own paragraphs...');
7582
7683See the [ demo.php] ( demo.php ) file for a working example.
7784
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 ) .
8285
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)
8493
8594Create a new Syllable class, with defaults.
8695
87- ### public static setCacheDir(string $dir)
96+ #### public static setCacheDir(string $dir)
8897
8998Set the directory where compiled language files may be stored.
9099Default to the ` cache ` subdirectory of the current directory.
91100
92- ### public static setEncoding(string|null $encoding = null)
101+ #### public static setEncoding(string|null $encoding = null)
93102
94103Set the character encoding to use.
95104Specify ` null ` encoding to not apply any encoding at all.
96105
97- ### public static setLanguageDir(string $dir)
106+ #### public static setLanguageDir(string $dir)
98107
99108Set the directory where language source files can be found.
100109Default to the ` languages ` subdirectory of the current directory.
101110
102- ### public setLanguage(string $language)
111+ #### public setLanguage(string $language)
103112
104113Set the language whose rules will be used for hyphenation.
105114
106- ### public setHyphen(mixed $hyphen)
115+ #### public setHyphen(mixed $hyphen)
107116
108117Set the hyphen text or object to use as a hyphen marker.
109118
110- ### public getHyphen(): Hyphen
119+ #### public getHyphen(): Hyphen
111120
112121Get the current hyphen object.
113122
114- ### public setCache(Cache $cache = null)
123+ #### public setCache(Cache $cache = null)
115124
116- ### public getCache(): Cache
125+ #### public getCache(): Cache
117126
118- ### public setSource($source)
127+ #### public setSource($source)
119128
120- ### public getSource(): Source
129+ #### public getSource(): Source
121130
122- ### public setMinWordLength(int $length = 0)
131+ #### public setMinWordLength(int $length = 0)
123132
124133Words need to contain at least this many character to be hyphenated.
125134
126- ### public getMinWordLength(): int
135+ #### public getMinWordLength(): int
127136
128- ### public setLibxmlOptions(int $libxmlOptions)
137+ #### public setLibxmlOptions(int $libxmlOptions)
129138
130139Options to use for HTML parsing by libxml.
131140See https://www.php.net/manual/de/libxml.constants.php .
132141
133- ### public excludeAll()
142+ #### public excludeAll()
134143
135144Exclude all elements.
136145
137- ### public excludeElement(string|string[ ] $elements)
146+ #### public excludeElement(string|string[ ] $elements)
138147
139148Add one or more elements to exclude from HTML.
140149
141- ### public excludeAttribute(string|string[ ] $attributes, $value = null)
150+ #### public excludeAttribute(string|string[ ] $attributes, $value = null)
142151
143152Add one or more elements with attributes to exclude from HTML.
144153
145- ### public excludeXpath(string|string[ ] $queries)
154+ #### public excludeXpath(string|string[ ] $queries)
146155
147156Add one or more xpath queries to exclude from HTML.
148157
149- ### public includeElement(string|string[ ] $elements)
158+ #### public includeElement(string|string[ ] $elements)
150159
151160Add one or more elements to include from HTML.
152161
153- ### public includeAttribute(string|string[ ] $attributes, $value = null)
162+ #### public includeAttribute(string|string[ ] $attributes, $value = null)
154163
155164Add one or more elements with attributes to include from HTML.
156165
157- ### public includeXpath(string|string[ ] $queries)
166+ #### public includeXpath(string|string[ ] $queries)
158167
159168Add one or more xpath queries to include from HTML.
160169
161- ### public splitWord(string $word): array
170+ #### public splitWord(string $word): array
162171
163172Split a single word on where the hyphenation would go.
164173Punctuation is not supported, only simple words. For parsing whole sentences
165174please use Syllable::splitWords() or Syllable::splitText().
166175
167- ### public splitWords(string $text): array
176+ #### public splitWords(string $text): array
168177
169178Split a text into an array of punctuation marks and words,
170179splitting each word on where the hyphenation would go.
171180
172- ### public splitText(string $text): array
181+ #### public splitText(string $text): array
173182
174183Split a text on where the hyphenation would go.
175184
176- ### public hyphenateWord(string $word): string
185+ #### public hyphenateWord(string $word): string
177186
178187Hyphenate a single word.
179188
180- ### public hyphenateText(string $text): string
189+ #### public hyphenateText(string $text): string
181190
182191Hyphenate all words in the plain text.
183192
184- ### public hyphenateHtml(string $html): string
193+ #### public hyphenateHtml(string $html): string
185194
186195Hyphenate all readable text in the HTML, excluding HTML tags and
187196attributes.
188197
189- ### public histogramText(string $text): array
198+ #### public histogramText(string $text): array
190199
191200Count the number of syllables in the text and return a map with
192201syllable count as key and number of words for that syllable count as
193202the value.
194203
195- ### public countWordsText(string $text): int
204+ #### public countWordsText(string $text): int
196205
197206Count the number of words in the text.
198207
199- ### public countSyllablesText(string $text): int
208+ #### public countSyllablesText(string $text): int
200209
201210Count the number of syllables in the text.
202211
203- ### public countPolysyllablesText(string $text): int
212+ #### public countPolysyllablesText(string $text): int
204213
205214Count the number of polysyllables in the text.
206215
207- Development
208- -----------
216+
217+ ## Development
209218
210219### Update language files
211220
@@ -312,8 +321,8 @@ composer install
312321to execute the tests.
313322
314323
315- Changes
316- -------
324+ ## Changes
325+
3173261.6
318327- Revert renaming of API method names
319328- Use cache version as string instead of number
0 commit comments