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

Once installed, the fastest way to start using s9e\TextFormatter is to use a predefined bundle. In this example, we use the Forum bundle, which supports the same kind of BBCodes/formatting that is used in internet forums. If you prefer Markdown, try the Fatdown bundle. You can also use them as a starting point to make your own bundle.

Forum bundle (BBCodes)

use s9e\TextFormatter\Bundles\Forum as TextFormatter;

$text = 'To-do list:
[list]
  [*] Say hello to the world :)
  [*] Go to http://example.com
  [*] Try to trip the parser with [b]mis[i]nes[/b]ted[u] tags[/i][/u]
  [*] Watch this video: [media]http://www.youtube.com/watch?v=QH2-TGUlwu4[/media]
[/list]';

// Parse the original text
$xml = TextFormatter::parse($text);

// Here you should save $xml to your database
// $db->query('INSERT INTO ...');

// Render and output the HTML result
echo TextFormatter::render($xml);

// You can "unparse" the XML to get the original text back
assert(TextFormatter::unparse($xml) === $text);
To-do list:
<ul>
  <li> Say hello to the world <img alt=":)" class="emoji" draggable="false" src="https://cdn.jsdelivr.net/gh/twitter/twemoji@latest/assets/svg/1f642.svg"></li>
  <li> Go to <a href="http://example.com">http://example.com</a></li>
  <li> Try to trip the parser with <b>mis<i>nes</i></b><i>ted<u> tags</u></i></li>
  <li> Watch this video: <span data-s9e-mediaembed="youtube" style="display:inline-block;width:100%;max-width:640px"><span style="display:block;overflow:hidden;position:relative;padding-bottom:56.25%"><iframe allow="clipboard-write" allowfullscreen="" loading="lazy" referrerpolicy="origin" scrolling="no" style="background:url(https://i.ytimg.com/vi/QH2-TGUlwu4/hqdefault.jpg) 50% 50% / cover;border:0;height:100%;left:0;position:absolute;width:100%" src="https://www.youtube.com/embed/QH2-TGUlwu4"></iframe></span></span></li>
</ul>

Fatdown bundle (Markdown)

use s9e\TextFormatter\Bundles\Fatdown as TextFormatter;

$text = 'To-do list:

  * Say hello to the world :)
  * Go to http://example.com
  * Try to trip the parser with **mis*nes**ted<u> tags*</u>
  * Watch this video: http://www.youtube.com/watch?v=QH2-TGUlwu4';

// Parse the original text
$xml = TextFormatter::parse($text);

// Here you should save $xml to your database
// $db->query('INSERT INTO ...');

// Render and output the HTML result
echo TextFormatter::render($xml);

// You can "unparse" the XML to get the original text back
assert(TextFormatter::unparse($xml) === $text);
<p>To-do list:</p>

  <ul><li>Say hello to the world :)</li>
  <li>Go to <a href="http://example.com">http://example.com</a></li>
  <li>Try to trip the parser with <strong>mis<em>nes</em></strong><em>ted<u> tags</u></em></li>
  <li>Watch this video: <span data-s9e-mediaembed="youtube" style="display:inline-block;width:100%;max-width:640px"><span style="display:block;overflow:hidden;position:relative;padding-bottom:56.25%"><iframe allow="clipboard-write" allowfullscreen="" loading="lazy" referrerpolicy="origin" scrolling="no" style="background:url(https://i.ytimg.com/vi/QH2-TGUlwu4/hqdefault.jpg) 50% 50% / cover;border:0;height:100%;left:0;position:absolute;width:100%" src="https://www.youtube.com/embed/QH2-TGUlwu4"></iframe></span></span></li></ul>
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.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui