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

Usually, HTML is meant to be presented to the user as-is. However, sometimes you may want to alias HTML elements and HTML attributes to other tags and attributes. Here is a concrete example: let's say you want to limit the number of links to 3 per text but users can post links many different ways via the [url] BBCode, as an <a href> element or even in plain text, letting the Autolink plugin linkify them. Your solution is to use the same tag for the 3 different plugins.

In the following example, we configure the HTMLElements plugin to alias <a href> to use the same tag as the BBCodes and Autolink plugins. Then we see that despite using 3 different syntaxes, only the first 3 URLs are linked.

$configurator = new s9e\TextFormatter\Configurator;

// The [url] BBCode uses a tag named "URL" with an attribute of the same name
$configurator->BBCodes->addFromRepository('URL');
$configurator->Autolink;

// <a> will use the "URL" tag
$configurator->HTMLElements->aliasElement('a', 'URL');

// The "href" attribute will use the "url" attribute
$configurator->HTMLElements->aliasAttribute('a', 'href', 'url');

// Limit the number of URL tags to 3
$configurator->tags['URL']->tagLimit = 3;

// Get an instance of the parser and the renderer
extract($configurator->finalize());

$text = 'http://example.org/1
[url=http://example.org/2]Second link[/url]
<a href="http://example.org/3">The third and last</a>
<a href="http://example.org/4">This one will not be linkified</a>';

$xml  = $parser->parse($text);
$html = $renderer->render($xml);

echo $html;
<a href="http://example.org/1">http://example.org/1</a>
<a href="http://example.org/2">Second link</a>
<a href="http://example.org/3">The third and last</a>
&lt;a href="http://example.org/4"&gt;This one will not be linkified&lt;/a&gt;
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