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

Manage aliases

Aliases can be managed via the $aliases property, an associative array that maps aliases (as keys) to fully-qualified emoji or emoji sequences (as values.)

$configurator = new s9e\TextFormatter\Configurator;
$configurator->Emoji->aliases[':D'] = '😀';

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

$text = 'Hello world :D';
$xml  = $parser->parse($text);
$html = $renderer->render($xml);

echo $html;
Hello world <img alt=":D" class="emoji" draggable="false" src="https://cdn.jsdelivr.net/gh/twitter/twemoji@latest/assets/svg/1f600.svg">

Configure aliases at parsing time

Starting with 1.3, emoji aliases can be read and modified at parsing time via $parser->registeredVars['Emoji.aliases'] in PHP and s9e.TextFormatter.registeredVars['Emoji.aliases'] in JavaScript. Do note that while removing an alias will prevent it from being used, only aliases that start and end with a : and only contain lowercase letters, digits, _, - and + can be added at parsing time.

$configurator = new s9e\TextFormatter\Configurator;
$configurator->Emoji;

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

$text = 'Hi :smiling_face:';
$xml  = $parser->parse($text);
$html = $renderer->render($xml);
echo "$html\n";

// Add an alias before parsing the text again
$parser->registeredVars['Emoji.aliases'][':smiling_face:'] = '😀';

$xml  = $parser->parse($text);
$html = $renderer->render($xml);
echo $html;
Hi :smiling_face:
Hi <img alt=":smiling_face:" class="emoji" draggable="false" src="https://cdn.jsdelivr.net/gh/twitter/twemoji@latest/assets/svg/1f600.svg">

Using Twemoji assets with text parsed on an older release

Before 1.3, support for Twemoji was incomplete due to a discrepancy between Twemoji's file naming scheme and the default set used by the plugin. Starting with 1.3, a tseq attribute has been added to the output and can be used to display Twemoji assets from their CDN. Reparsing the old text fixes this issue. Alternatively, it is possible to use an xsl:choose conditional to use a different image source depending on the presence of the tseq attribute.

$configurator = new s9e\TextFormatter\Configurator;
$configurator->Emoji->getTag()->template =
	'<xsl:choose>
		<xsl:when test="[@tseq](https://github.com/tseq)">
			<img alt="{.}" class="emoji" draggable="false"
				src="//twemoji.maxcdn.com/v/latest/svg/{[@tseq](https://github.com/tseq)}.svg"/>
		</xsl:when>
		<xsl:otherwise>
			<img alt="{.}" class="emoji" draggable="false"
				src="https://cdn.jsdelivr.net/gh/s9e/emoji-assets-twemoji@12.0.1/dist/svgz/{[@seq](https://github.com/seq)}.svgz"/>
		</xsl:otherwise>
	</xsl:choose>';

extract($configurator->finalize());

$xml = "<r><EMOJI seq=\"00a9\">\u{a9}\u{fe0f}</EMOJI>\n"
     . "<EMOJI tseq=\"a9\" seq=\"00a9\">\u{a9}\u{fe0f}</EMOJI></r>";

echo $renderer->render($xml);
<img alt="©️" class="emoji" draggable="false" src="https://cdn.jsdelivr.net/gh/s9e/emoji-assets-twemoji@12.0.1/dist/svgz/00a9.svgz">
<img alt="©️" class="emoji" draggable="false" src="//twemoji.maxcdn.com/v/latest/svg/a9.svg">
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