Search by

jorisnoo / statamic-safe-entities

jorgenoo

A Statamic addon that provides a Blade directive and Bard buttons for safe HTML entity insertion (soft hyphens, non-breaking spaces, etc.).

Package info

github.com/jorisnoo/statamic-safe-entities

Type:statamic-addon

pkg:composer/jorisnoo/statamic-safe-entities

Statistics

Installs: 431

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 2

0.2.2 2026-09-14 05:21 UTC

This package is auto-updated.

Last update: 2026-10-04 16:21:27 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

A Statamic addon for safe HTML entity insertion in Bard, text, and textarea fields. Adds a Bard toolbar button for inserting soft hyphens, non-breaking spaces, en dashes, and other typography entities, plus Blade directives to render them safely.

Installation

composer require jorisnoo/statamic-safe-entities

Configuration

Publish the config file to customize which entities are available:

php artisan vendor:publish --tag="safe-entities-config"

Default configuration:

return [
    'entities' => [
        '­' => 'Soft Hyphen',
        ' ' => 'Non-Breaking Space',
        '–' => 'En Dash',
    ],
];

Each entry maps an entity code to a label shown in the Bard toolbar dropdown.

Usage

Bard toolbar

The addon adds an "&" button to the Bard toolbar. Clicking it shows a dropdown of configured entities. Selecting one inserts the entity code at the cursor position.

Blade directives

Two Blade directives are available for rendering entities safely:

@entities($text) — for text/textarea fields

Escapes the string for safe HTML output, then restores configured entity codes so they render as actual entities.

<p>@entities($entry->title)</p>

@entitiesHtml($html) — for Bard/rich-text fields

Restores double-encoded entities (&amp;shy; back to &shy;) in already-rendered HTML.

<div>@entitiesHtml($entry->content)</div>

PHP

You can also call the methods directly:

use Noo\SafeEntities\SafeEntities;

$text = SafeEntities::render($value);
$html = SafeEntities::renderHtml($value);

Both methods accept an optional second argument to override which entities to restore:

SafeEntities::render($value, ['&shy;', '&nbsp;']);

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

License

The MIT License (MIT). Please see License File for more information.

Maintainer releases

See RELEASING.md for versioning, changelog entries and the release command.