Installation:
composer require avtonom/creole-full-bundle "~1.1"
Ensure softark/creole is also installed (handled automatically via dependency).
Register the Bundle:
Add to config/bundles.php (Symfony 4+) or AppKernel.php (Symfony <4):
// config/bundles.php
return [
// ...
Avtonom\CreoleBundle\AvtonomCreoleBundle::class => ['all' => true],
];
First Use Case: Parse Creole/Wiki syntax in a controller or template:
use Avtonom\CreoleBundle\Parser\CreoleParser;
class WikiController extends AbstractController {
public function renderWiki(CreoleParser $parser) {
$markdown = "**Bold text** and //italic//";
$html = $parser->parse($markdown);
return $this->render('wiki/show.html.twig', ['content' => $html]);
}
}
Or in Twig:
{{ creole(content) }}
Parsing in Controllers/Commands:
Inject CreoleParser service to transform Creole/Wiki syntax to HTML:
public function processWikiContent(CreoleParser $parser, string $rawContent) {
$html = $parser->parse($rawContent);
// Store or return $html
}
Dynamic Content Rendering: Use Twig extensions for seamless integration:
{% set parsedContent = creole('== Heading ==\n* List item') %}
{{ parsedContent|raw }} {# Render raw HTML #}
Configuration Overrides:
Customize parser behavior via config/packages/avtonom_creole.yaml:
avtonom_creole:
allowed_tags: ['p', 'strong', 'em', 'ul', 'ol'] # Whitelist tags
auto_link: true
Event-Driven Processing:
Listen to avtonom_creole.parse events to pre/post-process content:
// src/EventListener/WikiListener.php
public function onParse(WikiEvent $event) {
$event->setContent(str_replace('{{var}}', $this->getVar(), $event->getContent()));
}
content column) and parse on-the-fly.CreoleParser to render dynamic API responses with formatted text.Symfony Version Mismatch:
softark/creole updates.softark/creole:^1.0 for newer Symfony versions.XSS Risks:
avtonom_creole:
allowed_tags: ['p', 'em', 'strong'] # Explicit whitelist
Caching Issues:
$parser->parse($content); // Re-parses every time
Twig Auto-escaping:
|raw filter to render HTML safely:
{{ creole(content)|raw }}
avtonom_creole:
debug: true
Custom Rules:
Extend softark/creole by creating a subclass:
use Softark\Creole\Parser;
class CustomParser extends Parser {
protected function initialize() {
parent::initialize();
$this->addRule('{{var}}', function($match) { return 'Dynamic Value'; });
}
}
Register as a service:
services:
app.custom_creole_parser:
class: App\Parser\CustomParser
tags: ['avtonom_creole.parser']
Pre/Post-Processing: Use events to modify content before/after parsing:
// src/EventSubscriber/WikiSubscriber.php
public static function getSubscribedEvents() {
return [
KernelEvents::VIEW => ['onKernelView', 20],
];
}
Performance: For high-traffic sites, cache parsed results:
$cacheKey = md5($content);
$html = $cache->get($cacheKey, function() use ($parser, $content) {
return $parser->parse($content);
});
How can I help you explore Laravel packages today?