Skip to content

Extension points

phil/markup-bundle

What an application configures, replaces or decorates. The compilers, purifiers and readers are phil/markup's.

Configuration

OptionWhat it extends
formats, default_formatThe formats texts may be written in, in the order the form offers them, and the one taken when none is named
added_formatsThe formats add-ons bring: their label, and the service of their ReaderProvider; an add-on bundle prepends its own
levels, default_levelThe highest level each format is purified at, whatever a template asks, and the level taken when none is named
smart_punctuationWhether, and in which locale, the HTML goes through a typographer before it is purified
media_hostsThe hosts images may come from, given to SanitizerPurifier whichever bundle registers it

See Configuration.

Services

ServiceHow an application relies on it
Phil\Markup\MarkupCompilerAn alias: pointed at the application's own compiler — #[AsAlias(MarkupCompiler::class)] — and Markup, the filters and the bundles that compile follow; the smart punctuation decorates whatever it points at
Phil\Markup\HtmlPurifierAn alias: pointed at the application's own purifier the same way; a purifier the application builds itself keeps its own image hosts
Phil\Ujo\Html\HtmlRendererThe renderer DefaultCompiler renders UJO with: the application's block renderers, through the factory phil/ujo-bundle documents, render its own blocks in every format
Phil\Markup\MarkupInjected wherever texts are compiled and purified; public
Phil\MarkupBundle\Infrastructure\Format\MarkupFormatsInjected to read the enabled formats and levels; public
Phil\MarkupBundle\Infrastructure\Conversion\UjoConverterInjected to convert a text into UJO; reads with DefaultCompiler whatever MarkupCompiler points at; public

An application's own compiler changes the HTML, not the readers: what the converter reads stays the library's, and the readers of the formats declared in added_formats.

Dialects and formats of add-ons

A dialect of Markdown — its inline and block rules, the syntax it reads differently — is a MarkdownDialect of phil/markup, given to a MarkdownReader; a whole format is a ReaderProvider, which gives that reader, or one of its own. An add-on bundle registers its provider as a service, declares it in added_formats from prependExtension(), and ships the translations of its label in the phil_markup domain:

public function prependExtension(ContainerConfigurator $container, ContainerBuilder $builder): void
{
    $builder->prependExtensionConfig('phil_markup', ['added_formats' => ['shout' => ['label' => 'Shout', 'reader' => ShoutReaders::class]]]);
}

public function loadExtension(array $config, ContainerConfigurator $container, ContainerBuilder $builder): void
{
    $builder->register(ShoutReaders::class, ShoutReaders::class);
}

The application then enables the format, or leaves formats empty to take every one.

Forms and Twig

PointHow
The formats a field offersMarkupFormatType, among the enabled formats — see Forms
Compiling in templatesphil_markup, phil_purify and phil_ujo, with a format and a level under the format's ceiling — see Twig