Skip to content

Commit c27d361

Browse files
authored
Merge pull request #68 from alexander-nitsche/task-optimize-documentation
Task optimize documentation
2 parents 89ed115 + 6d62422 commit c27d361

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+94
-8747
lines changed

README.md

Lines changed: 55 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
Syllable
2-
========
1+
# Syllable
2+
33
Version 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

77
Copyright © 2011-2023 Martijn van der Lee.
88
MIT Open Source license applies.
99

10-
Introduction
11-
------------
10+
11+
## Introduction
12+
1213
PHP Syllable splitting and hyphenation.
1314
or rather...
1415
PHP Syl-la-ble split-ting and hy-phen-ation.
@@ -23,8 +24,8 @@ Language sources: http://tug.org/tex-hyphen/#languages
2324

2425
Supports PHP 5.6 and up, so you can use it on older servers.
2526

26-
Quick start
27-
-----------
27+
28+
## Installation
2829

2930
Install phpSyllable via Composer
3031

@@ -35,7 +36,10 @@ composer require vanderlee/syllable
3536
or simply add phpSyllable to your project and set up the project's
3637
autoloader 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

4044
Minimal example:
4145

@@ -51,6 +55,9 @@ use Vanderlee\Syllable\Syllable;
5155
use 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.
5461
Syllable::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

7683
See 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

8594
Create a new Syllable class, with defaults.
8695

87-
### public static setCacheDir(string $dir)
96+
#### public static setCacheDir(string $dir)
8897

8998
Set the directory where compiled language files may be stored.
9099
Default 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

94103
Set the character encoding to use.
95104
Specify `null` encoding to not apply any encoding at all.
96105

97-
### public static setLanguageDir(string $dir)
106+
#### public static setLanguageDir(string $dir)
98107

99108
Set the directory where language source files can be found.
100109
Default to the `languages` subdirectory of the current directory.
101110

102-
### public setLanguage(string $language)
111+
#### public setLanguage(string $language)
103112

104113
Set the language whose rules will be used for hyphenation.
105114

106-
### public setHyphen(mixed $hyphen)
115+
#### public setHyphen(mixed $hyphen)
107116

108117
Set the hyphen text or object to use as a hyphen marker.
109118

110-
### public getHyphen(): Hyphen
119+
#### public getHyphen(): Hyphen
111120

112121
Get 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

124133
Words 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

130139
Options to use for HTML parsing by libxml.
131140
See https://www.php.net/manual/de/libxml.constants.php.
132141

133-
### public excludeAll()
142+
#### public excludeAll()
134143

135144
Exclude all elements.
136145

137-
### public excludeElement(string|string[] $elements)
146+
#### public excludeElement(string|string[] $elements)
138147

139148
Add 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

143152
Add one or more elements with attributes to exclude from HTML.
144153

145-
### public excludeXpath(string|string[] $queries)
154+
#### public excludeXpath(string|string[] $queries)
146155

147156
Add one or more xpath queries to exclude from HTML.
148157

149-
### public includeElement(string|string[] $elements)
158+
#### public includeElement(string|string[] $elements)
150159

151160
Add 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

155164
Add one or more elements with attributes to include from HTML.
156165

157-
### public includeXpath(string|string[] $queries)
166+
#### public includeXpath(string|string[] $queries)
158167

159168
Add one or more xpath queries to include from HTML.
160169

161-
### public splitWord(string $word): array
170+
#### public splitWord(string $word): array
162171

163172
Split a single word on where the hyphenation would go.
164173
Punctuation is not supported, only simple words. For parsing whole sentences
165174
please use Syllable::splitWords() or Syllable::splitText().
166175

167-
### public splitWords(string $text): array
176+
#### public splitWords(string $text): array
168177

169178
Split a text into an array of punctuation marks and words,
170179
splitting each word on where the hyphenation would go.
171180

172-
### public splitText(string $text): array
181+
#### public splitText(string $text): array
173182

174183
Split a text on where the hyphenation would go.
175184

176-
### public hyphenateWord(string $word): string
185+
#### public hyphenateWord(string $word): string
177186

178187
Hyphenate a single word.
179188

180-
### public hyphenateText(string $text): string
189+
#### public hyphenateText(string $text): string
181190

182191
Hyphenate all words in the plain text.
183192

184-
### public hyphenateHtml(string $html): string
193+
#### public hyphenateHtml(string $html): string
185194

186195
Hyphenate all readable text in the HTML, excluding HTML tags and
187196
attributes.
188197

189-
### public histogramText(string $text): array
198+
#### public histogramText(string $text): array
190199

191200
Count the number of syllables in the text and return a map with
192201
syllable count as key and number of words for that syllable count as
193202
the value.
194203

195-
### public countWordsText(string $text): int
204+
#### public countWordsText(string $text): int
196205

197206
Count the number of words in the text.
198207

199-
### public countSyllablesText(string $text): int
208+
#### public countSyllablesText(string $text): int
200209

201210
Count the number of syllables in the text.
202211

203-
### public countPolysyllablesText(string $text): int
212+
#### public countPolysyllablesText(string $text): int
204213

205214
Count 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
312321
to execute the tests.
313322

314323

315-
Changes
316-
-------
324+
## Changes
325+
317326
1.6
318327
- Revert renaming of API method names
319328
- Use cache version as string instead of number

build/classes/DocumentationManager.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,18 +143,22 @@ protected function updateReadme()
143143

144144
$apiDocumentation = '';
145145
foreach ($apiMethods as $method) {
146-
$apiDocumentation .= '### '.$method['signature']."\n\n";
146+
$apiDocumentation .= '#### '.$method['signature']."\n\n";
147147
$apiDocumentation .= $method['comment'] !== '' ? $method['comment']."\n\n" : '';
148148
}
149+
$apiDocumentation .= "\n";
149150

150151
$readme = file_get_contents($this->readmeFile);
151-
$apiDocumentationStart = strpos($readme, '###', strpos($readme, "`Syllable` class reference\n--------------------------"));
152-
$apiDocumentationEnd = strpos($readme, "Development\n-----------", $apiDocumentationStart);
153-
$apiDocumentationLength = $apiDocumentationEnd - $apiDocumentationStart;
152+
$apiDocumentationStart = strpos($readme, '## `Syllable` API reference');
153+
if ($apiDocumentationStart !== false) {
154+
$apiDocumentationStart = strpos($readme, '####', $apiDocumentationStart);
155+
$apiDocumentationEnd = strpos($readme, '## Development', $apiDocumentationStart);
156+
}
157+
154158
$apiDocumentationOld = '';
155159
$readmeState = 0;
156-
157-
if ($apiDocumentationStart > -1 && $apiDocumentationEnd > -1) {
160+
if ($apiDocumentationStart !== false && $apiDocumentationEnd !== false) {
161+
$apiDocumentationLength = $apiDocumentationEnd - $apiDocumentationStart;
158162
$apiDocumentationOld = substr($readme, $apiDocumentationStart, $apiDocumentationLength);
159163
$readme = substr_replace($readme, $apiDocumentation, $apiDocumentationStart, $apiDocumentationLength);
160164
$readmeState += 1;
@@ -164,7 +168,7 @@ protected function updateReadme()
164168

165169
if ($readmeState < 1) {
166170
if (!($readmeState & 1)) {
167-
$errors[] = 'Missing headlines "`Syllable` class reference" and "Development" to locate API documentation.';
171+
$errors[] = 'Missing headlines "`Syllable` API reference" and "Development" to locate API documentation.';
168172
}
169173
if (isset($errors)) {
170174
throw new Exception(sprintf(

doc/404.html

Lines changed: 0 additions & 96 deletions
This file was deleted.

0 commit comments

Comments
 (0)