Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Text Formatter Laravel Package

s9e/text-formatter

PHP text formatting library with plugin support for BBCode, Markdown, HTML, and more. Includes predefined bundles, extensive documentation, and a JavaScript port for client-side preview and demos. Install via Composer and integrate customizable parsing/rendering.

View on GitHub
Deep Wiki
Context7

Add rel="ugc" to links

The AddAttributeValueToElements normalizer can be used to add a value to a list of space-separated values. For instance, it can add a link type to a link's rel, or a class name to an element's class.

In the following example, we target all a elements with the XPath query //a in order to add ugc to the list of link types stored in the element's rel attribute.

use s9e\TextFormatter\Configurator\TemplateNormalizations\AddAttributeValueToElements;

// Create a new configurator and enable the Autolink plugin
$configurator = new s9e\TextFormatter\Configurator;
$configurator->Autolink;

// Add our custom normalizer
$configurator->templateNormalizer->add(
	new AddAttributeValueToElements('//a', 'rel', 'ugc')
);

extract($configurator->finalize());

$text = 'https://example.org';
$xml  = $parser->parse($text);
$html = $renderer->render($xml);

echo $html;
<a href="https://example.org" rel="ugc">https://example.org</a>

Set loading="lazy" on images

In the following example, we use the SetAttributeOnElements normalizer to add a loading attribute to images that do not have one.

use s9e\TextFormatter\Configurator\TemplateNormalizations\SetAttributeOnElements;

// Create a new configurator and enable the Autoimage plugin
$configurator = new s9e\TextFormatter\Configurator;
$configurator->Autoimage;

// Add our custom normalizer
$configurator->templateNormalizer->add(
	new SetAttributeOnElements('//img[not([@loading](https://github.com/loading))]', 'loading', 'lazy')
);

extract($configurator->finalize());

$text = 'https://example.org/img.png';
$xml  = $parser->parse($text);
$html = $renderer->render($xml);

echo $html;
<img src="https://example.org/img.png" loading="lazy">

Set nonce="{$NONCE}" on scripts

In the following example, we use the SetAttributeOnElements normalizer to add a nonce attribute to all script elements.

use s9e\TextFormatter\Configurator\TemplateNormalizations\SetAttributeOnElements;

// Create a new configurator
$configurator = new s9e\TextFormatter\Configurator;

// Add our custom normalizer before plugins are configured and templates are set
$configurator->templateNormalizer->add(
	new SetAttributeOnElements('//script', 'nonce', '{$NONCE}')
);

// Add a BBCode that creates a script element
$configurator->BBCodes->addCustom('[x]', '<script>alert(1)</script>');

extract($configurator->finalize());

$text = '[x]';
$xml  = $parser->parse($text);

// Set the value for $NONCE before rendering
$renderer->setParameter('NONCE', 'xxxx');
$html = $renderer->render($xml);

echo $html;
<script nonce="xxxx">alert(1)</script>
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours