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

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

Multi-purpose text formatting and markup library. Plugins offer support for BBCodes, Markdown, emoticons, HTML, embedding third-party media (YouTube, etc...), enhanced typography and more.

Frequently asked questions about Text Formatter
How do I install s9e\TextFormatter in a Laravel project?
Use Composer to install the package with `composer require s9e/text-formatter`. No Laravel-specific dependencies exist, so it integrates seamlessly. Register a service provider to configure bundles (e.g., Markdown or BBCode) via the `Configurator` class, then inject the formatter into controllers or services.
Which Laravel versions does s9e\TextFormatter support?
The package is PHP-focused and works with any Laravel version (8.x, 9.x, 10.x) as long as PHP 8.0+ is used. No Laravel-specific dependencies mean compatibility is broad, but test thoroughly for edge cases like Blade templating or API responses.
Can I use this for a Laravel forum with BBCode support?
Yes, s9e\TextFormatter excels at BBCode parsing. Enable the BBCode plugin via a bundle (e.g., `$configurator->BBCode`), then customize allowed tags or filters to sanitize user input. Pair with Laravel’s validation for security, like blocking external image tags.
How do I cache parsed output for performance in Laravel?
Cache parsed HTML or Markdown using Laravel’s cache system (e.g., `Cache::remember`). Store raw markup in the database and parsed output in cache with keys like `post_{$id}_html`. For dynamic content, use per-user caching or tags to invalidate when input changes.
Does the JavaScript port work with Laravel Mix/Vite?
Yes, the JS port integrates with Laravel Mix or Vite for client-side previews. Include the JS bundle in your assets, then initialize it on form inputs. Use Alpine.js/Livewire to sync changes with the backend. The demo on the [GitHub repo](https://s9e.github.io/TextFormatter/) shows basic setup.
How do I secure user-generated content with this library?
Use the library’s built-in filters (e.g., URL whitelists) and combine with Laravel’s validation. For example, restrict BBCode tags to safe ones (`[b]`, `[i]`) and blacklist external links. Test with malformed input to ensure no XSS risks remain.
Can I use this for API responses (e.g., converting Markdown to HTML)?
Absolutely. Configure a Markdown bundle (`$configurator->Markdown`) and inject the formatter into API controllers. Parse Markdown in routes like `/api/docs` and return sanitized HTML. Cache results for high-traffic endpoints.
Are there alternatives to s9e\TextFormatter for Laravel?
Alternatives include `Parsedown` (Markdown-only) or `BBCodeParser` (BBCode-focused). However, s9e\TextFormatter stands out for its plugin flexibility (BBCode + Markdown + HTML), JS port, and predefined bundles. It’s ideal if you need a unified solution for multiple formats.
How do I test s9e\TextFormatter in Laravel’s PHPUnit?
Write unit tests for parsing edge cases (e.g., malformed BBCode, nested Markdown). Use Laravel’s `Mockery` to test service integration. The package includes PHPUnit tests; adapt them to your Laravel context. Focus on security (e.g., XSS attempts) and performance (large inputs).
What’s the best way to handle errors (e.g., invalid BBCode) in production?
Wrap formatter calls in try-catch blocks and log errors. Return user-friendly messages (e.g., ‘Invalid format’) or use Laravel’s `ProblemDetails` for APIs. For critical errors, send alerts via Laravel’s `Reportable` exceptions or queue processing for async handling.
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