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

Introduction

s9e\TextFormatter can optionally generate a JavaScript parser that can be used in browsers to parse text and preview the result in a live environment. The JavaScript parser requires Internet Explorer 8 or later, or any contemporary browser that supports XSLTProcessor.

$configurator = new s9e\TextFormatter\Configurator;

// Enable the JavaScript parser
$configurator->enableJavaScript();

// Now finalize() will return an entry for "js"
extract($configurator->finalize());

With JavaScript enabled, finalize() will return an element named js that contains the JavaScript source for the s9e.TextFormatter JavaScript object.

API

// Parse $text and return the XML as a string
s9e.TextFormatter.parse($text);

// Parse $text and preview it in HTMLElement $target. It will return the last node modified
s9e.TextFormatter.preview($text, $target);

// Toggle a plugin by name
s9e.TextFormatter.disablePlugin($pluginName);
s9e.TextFormatter.enablePlugin($pluginName);

// Toggle a tag by name
s9e.TextFormatter.disableTag($tagName);
s9e.TextFormatter.enableTag($tagName);

// Runtime configuration
s9e.TextFormatter.setNestingLimit($tagName, $limit);
s9e.TextFormatter.setTagLimit($tagName, $limit);

Minify the JavaScript parser with the Google Closure Compiler service

The JavaScript parser can be automatically be minified using the Google Closure Compiler service via HTTP. The minification level and other configuration are automatically set.

$configurator = new s9e\TextFormatter\Configurator;
$configurator->enableJavaScript();
$configurator->javascript->setMinifier('ClosureCompilerService');

Other minifiers are available.

Speed up minification with a cache

The result of minification can be cached locally and reused. It's only useful if the JavaScript parser is regenerated more often than the configuration changes, since any modification to the configuration produces a different source.

$configurator = new s9e\TextFormatter\Configurator;
$configurator->enableJavaScript();

$configurator->javascript
	->setMinifier('ClosureCompilerService')
	->cacheDir = '/path/to/cache';

Improve minification

It is possible to improve the minification ratio by disabling features that are not used. For instance, if you only use the parse and preview methods you can reduce the API to only those two methods.

$configurator = new s9e\TextFormatter\Configurator;
$configurator->enableJavaScript();

$configurator->javascript->exports = [
	'parse',
	'preview'
];
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.
anousss007/vigilance
supportpal/eloquent-model
ardenexal/fhir-models
laravel-at/laravel-image-sanitize
romalytar/yammi-audit-log-laravel
ardenexal/fhir-validation
arshaviras/weather-widget
laravel-chronicle/core
sunchayn/nimbus
daikazu/eloquent-salesforce-objects
unseen-codes/chat
romalytar/yammi-jobs-monitoring-laravel
kisame76/filament-db-table-state
nqxcode/laravel-lucene-search
dpfx/laravel-livewire-wizards
workos/workos-php-laravel
sofa/laravel-global-scope
nawasara/auth-primitives
adhocrat-io/arkhe-main
make-dev/orca-harpoon