PHPackages                             whitecube/laravel-string-typography - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. whitecube/laravel-string-typography

ActiveLibrary[Templating &amp; Views](/categories/templating)

whitecube/laravel-string-typography
===================================

A set of simple Str &amp; Stringable macros helping to implement typographic rules

v1.1.0(5mo ago)5842MITPHPPHP ^8.0

Since Jul 24Pushed 5mo ago2 watchersCompare

[ Source](https://github.com/whitecube/laravel-string-typography)[ Packagist](https://packagist.org/packages/whitecube/laravel-string-typography)[ GitHub Sponsors](https://github.com/whitecube)[ RSS](/packages/whitecube-laravel-string-typography/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (3)Versions (4)Used By (0)

Typography Rules for Laravel
============================

[](#typography-rules-for-laravel)

Rendering strings provided by users can result in unexpected typographic results. For instance, in most latin languages (such as french) it is recommended to add a non-breaking space in front of, amongst others, exclamation or question marks (`!` and `?`). Most users will probably just type a regular space, which could result in an unwanted line break just before these punctuation marks.

This simple package provides a `typography` macro for Laravel's `Str` facade and `Stringable` instances (created using `Str::of()` or `str()`) that will take care of these typographic details.

It is also possible to enhance this package by adding your own typographic rules.

```
$content = 'Mama mia !';

echo str($content)->typography();
```

```
Mama mia&nbsp;!

```

Installation
------------

[](#installation)

```
composer require whitecube/laravel-string-typography
```

Getting started
---------------

[](#getting-started)

The package's ServiceProvider and therefore its `typography` macro will automatically be registered upon installation. You can start using it right away:

```
{{-- Using the "Str" facade --}}
{!! Str::typography($title) !!}

{{-- Using the "str()" helper --}}
{!! str($paragraph)->typography() !!}
```

Using `Stringable` instances, you can chain `typography` with other helper methods:

```
{!! str($text)->markdown()->typography() !!}
```

Note

Since the transformed strings contain HTML entities (such as `&nbsp;`), don't forget to render them using `{!! !!}` instead of `{{ }}` in your Blade templates.

Default typographic rules
-------------------------

[](#default-typographic-rules)

KeyUsageDescription`non-breaking-punctuation`Remove unwanted line breaks in front of punctuationReplaces ` !`, ` ?`, ` :`, ` ;` with `&nbsp;!`, `&nbsp;?`, `&nbsp;:`, `&nbsp;;` respectively.`hellip`Use the correct "horizontal ellipsis" HTML entityReplaces `&#8230;`, `&#x2026;`, `...`, `…` with `&hellip;`.Registering &amp; removing typographic rules
--------------------------------------------

[](#registering--removing-typographic-rules)

```
use Whitecube\Strings\Typography;

Typography::rule(
    key: 'a-to-b',
    regex: '/a/',
    callback: fn(array $matches) => 'b',
);
```

By default all the previously registered typographic rules will be applied when using the new `typography` method. It is possible to globally remove one of them using:

```
use Whitecube\Strings\Typography;

Typography::remove('a-to-b');
```

Filtering typographic rules
---------------------------

[](#filtering-typographic-rules)

Call a single or a few specific rules:

```
{!! str($text)->typography(only: 'hellip') !!}
{!! str($text)->typography(only: ['hellip', 'non-breaking-punctuation']) !!}
```

Call all rules except a single or a few specific unwanted rules:

```
{!! str($text)->typography(except: 'hellip') !!}
{!! str($text)->typography(except: ['hellip', 'non-breaking-punctuation']) !!}
```

---

🔥 Sponsorships
--------------

[](#-sponsorships)

If you are reliant on this package in your production applications, consider [sponsoring us](https://github.com/sponsors/whitecube)! It is the best way to help us keep doing what we love to do: making great open source software.

Contributing
------------

[](#contributing)

Feel free to suggest changes, ask for new features or fix bugs yourself. We're sure there are still a lot of improvements that could be made, and we would be very happy to merge useful pull requests. Thanks!

Made with ❤️ for open source
----------------------------

[](#made-with-️-for-open-source)

At [Whitecube](https://www.whitecube.be) we use a lot of open source software as part of our daily work. So when we have an opportunity to give something back, we're super excited!

We hope you will enjoy this small contribution from us and would love to [hear from you](mailto:hello@whitecube.be) if you find it useful in your projects. Follow us on [Twitter](https://twitter.com/whitecube_be) for more updates!

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance70

Regular maintenance activity

Popularity17

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 90.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~245 days

Total

3

Last Release

171d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8435657?v=4)[Whitecube](/maintainers/Whitecube)[@whitecube](https://github.com/whitecube)

---

Top Contributors

[![toonvandenbos](https://avatars.githubusercontent.com/u/5635557?v=4)](https://github.com/toonvandenbos "toonvandenbos (10 commits)")[![Debatty-Tom](https://avatars.githubusercontent.com/u/145542891?v=4)](https://github.com/Debatty-Tom "Debatty-Tom (1 commits)")

---

Tags

laravelbladetypographywhitecubepunctuationnbspnon-breakable space

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/whitecube-laravel-string-typography/health.svg)

```
[![Health](https://phpackages.com/badges/whitecube-laravel-string-typography/health.svg)](https://phpackages.com/packages/whitecube-laravel-string-typography)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
