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

In the following example, we create a custom normalization that replaces pairs of comments in the form <!-- IF FOO -->, <!-- ENDIF --> with a normal <xsl:if test="$FOO"> element. Since template normalization is automatically run on every template, this effectively extends the template syntax to support this new construct.

$configurator = new s9e\TextFormatter\Configurator;

// We prepend our callback so that it's executed before comments are removed
$configurator->templateNormalizer->prepend(
	function (DOMNode $template)
	{
		$dom   = $template->ownerDocument;
		$xpath = new DOMXPath($dom);
		$query = '//comment()[. = " ENDIF "]';

		// Query all ENDIF comments
		foreach ($xpath->query($query) as $comment)
		{
			// Iterate backwards from the ENDIF comment until we find an IF comment
			$node = $comment->previousSibling;

			while ($node)
			{
				if ($node->nodeType === XML_COMMENT_NODE
				 && preg_match('/^ IF (\\w+) $/', $node->textContent, $m))
				{
					break;
				}

				$node = $node->previousSibling;
			}

			if (empty($m))
			{
				continue;
			}

			// Create the xsl:if element that will replace the pair of comments
			$xslIf = $dom->createElementNS('http://www.w3.org/1999/XSL/Transform', 'if');
			$xslIf->setAttribute('test', '$' . $m[1]);

			// Iterate forward from the IF comment to the ENDIF and move nodes to the xsl:if
			while (!$node->nextSibling->isSameNode($comment))
			{
				$xslIf->appendChild($node->parentNode->removeChild($node->nextSibling));
			}

			// All that's left is to remove the ENDIF comment and replace the IF comment with xsl:if
			$node->parentNode->removeChild($node->nextSibling);
			$node->parentNode->replaceChild($xslIf, $node);
		}
	}
);

echo $configurator->templateNormalizer->normalizeTemplate('
	<!-- IF S_USER_LOGGED_IN -->
	<div>Welcome!</div>
	<!-- ENDIF -->
');
<xsl:if test="$S_USER_LOGGED_IN"><div>Welcome!</div></xsl:if>
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