fater / typography
Simple way to make your text more typographer
Requires
- php: >=8.0
Requires (Dev)
- nunomaduro/phpinsights: ^2.7
- phpunit/phpunit: ^9
This package is auto-updated.
Last update: 2025-06-10 21:20:37 UTC
README
"Typography" is an open source PHP software that automatically can format your text. It can place spaces and correct mechanical errors in the text, replace characters and brackets. This software can be useful for people who are engaged in the production and formatting of texts for public purposes, such as web pages, promotional materials, presentations, resumes, news, public posts, etc.
Using the "Typography" allows you to significantly reduce the time for correcting and formatting the text, since the service automatically processes all the necessary actions. In addition, "Typography" guarantees high accuracy and quality of correction, which helps to avoid punctuation errors.
This can be especially useful for professional writers, journalists, advertisers and other people whose work is related to text content.
Table Of Contents
Requirements
- PHP 8.0 or higher
Installation
Install with composer:
composer require fater/typography
Usage Examples
To run "Typography" with default formatting rules use this code example:
<?php use Fater\Typography\Typography; $formattedText = Typography::init()->apply('Your text'); echo $formattedText;
Create your own formatting rule
If you want to make special formatting rules you can make class from base rule template:
<?php use Fater\Typography\Rules\Rule; use Your\Namespace\Rules; class YourOwnRule extends Rule { public function handle(string $text): string { // Your code modification rules $text .= ' World!'; // Return formatted text return $text; } }
Add your rule to default formatting rules
Add your rule to the list of handlers to use it:
<?php use Fater\Typography\Typography; use Fater\Typography\TypographyRules; use Your\Namespace\Rules\YourOwnRule; $rules = TypographyRules::init()->addRules([YourOwnRule::class]); // Text will be formatted with default list of rules including your rule $formattedText = Typography::init($rules) // Set rules instance with your rule ->apply('Hello');
if you want to use only your rule
At the beginning clear all rules list, add your rule to the list of handlers to use it:
<?php use Fater\Typography\Typography; use Fater\Typography\TypographyRules; $rules = TypographyRules::init() ->clearAll() ->addRules([YourOwnRule::class]); // Text will be formatted only with your rule $formattedText = Typography::init($rules) // Set rules instance with your rule ->apply('Hello'); echo $formattedText;
The above example will output:
Hello World!
Roadmap
v. 1.x
- Space:
- Add space after comma
- Add space after dot (ignore domains) TODO: emails/IP
- Remove space before punctuation (.,:;?!)
- Remove space in each paragraph
- Remove redundant line breaks
- Characters:
- Replace special characters (c), (r), (tm), +-, ..., <-, ->
- Replace dash
- First letter in uppercase
v. 2.x
Supports of formatting plain text and HTML code
Changelog
Read Changelog in releases list to know all product changes.
License
License MIT, see more details in LICENSE