Skip to content

Commit e3aca6a

Browse files
Streamline header formatting in README.md
- Streamline header formatting. - Fix detection of API documentation section in README.md.
1 parent 4f6c573 commit e3aca6a

3 files changed

Lines changed: 37 additions & 31 deletions

File tree

README.md

Lines changed: 16 additions & 14 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-
Installation
27-
------------
27+
28+
## Installation
2829

2930
Install phpSyllable via Composer
3031

@@ -35,8 +36,8 @@ 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-
Usage
39-
-----
39+
40+
## Usage
4041

4142
Instantiate a Syllable object and start hyphenation.
4243

@@ -81,8 +82,9 @@ echo $syllable->hyphenateText('Provide your own paragraphs...');
8182

8283
See the [demo.php](demo.php) file for a working example.
8384

84-
`Syllable` API reference
85-
--------------------------
85+
86+
## `Syllable` API reference
87+
8688
The following is an incomplete list, containing only the most common methods.
8789
For a complete documentation of all classes, read the generated [PHPDoc](doc).
8890

@@ -210,8 +212,8 @@ Count the number of syllables in the text.
210212

211213
Count the number of polysyllables in the text.
212214

213-
Development
214-
-----------
215+
216+
## Development
215217

216218
### Update language files
217219

@@ -318,8 +320,8 @@ composer install
318320
to execute the tests.
319321

320322

321-
Changes
322-
-------
323+
## Changes
324+
323325
1.6
324326
- Revert renaming of API method names
325327
- Use cache version as string instead of number

build/classes/DocumentationManager.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,19 @@ protected function updateReadme()
146146
$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` API 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;

tests/build/DocumentationManagerTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,23 @@ protected function tearDownFixture()
4242
public function delegateSucceeds()
4343
{
4444
$readme = trim('
45-
`Syllable` API reference
46-
--------------------------
45+
## `Syllable` API reference
46+
4747
The following is an incomplete list, containing only the most common methods.
4848
For a complete documentation of all classes, read the generated [PHPDoc](doc).
4949
5050
#### public setMethods(array $methods = [])
5151
5252
..
5353
54-
Development
55-
-----------
54+
55+
## Development
5656
');
5757

5858
$expectedOutputRegex = '#The API documentation in the README.md has CHANGED.#';
5959
$expectedReadme = trim('
60-
`Syllable` API reference
61-
--------------------------
60+
## `Syllable` API reference
61+
6262
The following is an incomplete list, containing only the most common methods.
6363
For a complete documentation of all classes, read the generated [PHPDoc](doc).
6464
@@ -75,8 +75,8 @@ public function delegateSucceeds()
7575
7676
The public static method.
7777
78-
Development
79-
-----------
78+
79+
## Development
8080
');
8181

8282
$this->createFileInTestDirectory('README.md', $readme);
@@ -99,17 +99,17 @@ public function delegateSucceeds()
9999
public function delegateFailsIfReadmeFormatChanges()
100100
{
101101
$readme = trim('
102-
Syllable class reference
103-
--------------------------
102+
## Syllable API reference
103+
104104
The following is an incomplete list, containing only the most common methods.
105105
For a complete documentation of all classes, read the generated [PHPDoc](doc).
106106
107107
#### public setMethods(array $methods = [])
108108
109109
..
110110
111-
Examples
112-
--------
111+
112+
## Development
113113
');
114114

115115
$expectedOutput = trim('

0 commit comments

Comments
 (0)