Skip to content

Reference

phil/markup

Types

TypeKindRole
MarkupFormatenumMarkdown, Html, BBCode, MediaWiki, DokuWiki, Creole, Text, Ujo; values(); nameOf(), the name of a case or of a format an add-on brings
LevelenumBasic, Forum, All
MarkupCompilerinterfacecompile(string $source, MarkupFormat|string $format): string, HTML not safe to show; a string names a format of an add-on
LevelAwareCompilerinterfaceA MarkupCompiler with compileFor($source, $format, $level): told the level the HTML will be purified at
HtmlPurifierinterfacepurify(string $html, Level $level): string
Exception\MarkupException, Exception\InvalidSource, Exception\UnknownFormatexceptionsSee Exceptions
Markupfinal readonly classtoHtml() and text(): compile — at the level, for a LevelAwareCompiler —, then purify; Level::All unless told
MarkedUpTextembeddablesource (text), format (the name of the format, 16 characters), html (text)
Lexer\Cursorfinal classThe cursor of the analyser: see The analyser
Lexer\Sluggerfinal classThe anchors of one document, unique
Reader\MarkupReaderinterfaceread(string $source): Reading
Reader\Readingfinal readonly classdocument, a UJO Document, metadata and losses
Reader\Loss, Reader\LossReasonfinal readonly class, enumWhat a reader did not keep: element, path, reason
Contract\ExtractedElementStoreinterfacestore(string $content, string $mediaType, string $name): ?string: where extracted elements are stored as files
Reader\Markdown\MarkdownReaderMarkupReaderMarkdown, and the syntax of a dialect: see Markdown
Reader\Markdown\Contract\MarkdownDialect, Reader\Markdown\BaseDialectinterface, abstract classA dialect of Markdown, and one that reads as plain Markdown, to extend: see Extension points
Reader\Markdown\Contract\BlockRule, Reader\Markdown\Rule\InlineRuleinterfacesA block and an inline rule of a dialect
Reader\Markdown\MarkdownSyntaxenumThe built-in syntax a dialect may turn off: ColonBlocks
Reader\Markdown\Context, InlineParser, Inline, Delimiter, Attributes, Curly, FrontMatter, Rule\DelimiterRuleclassesWhat the rules of a dialect read with and make: see Extension points
Reader\Contract\ReaderProviderinterfacereader(Level $level, Normalizer $normalizer): MarkupReader, the reader of a format an add-on brings
Reader\BBCode\BBCodeReaderMarkupReaderBBCode and its extensions: see BBCode
Reader\MediaWiki\MediaWikiReader, Reader\DokuWiki\DokuWikiReader, Reader\Creole\CreoleReaderMarkupReaderThe wikis and their extensions: see The wikis
Reader\Wiki\WikiLinksfinal readonly classWhere the pages and the media a wiki text names are found: pages, media
Reader\Html\HtmlReaderMarkupReaderHTML into UJO: see HTML
Reader\UjoReaderMarkupReaderUJO JSON, through phil/ujo
Reader\Text\TextReaderMarkupReaderPlain text: a paragraph for each run of lines, line breaks kept, addresses made links
Adapter\DefaultCompilerLevelAwareCompilerEvery format, the add-ons' given by name; reader($format, $level) gives the reader of a format into UJO — HTML's and plain text's too, though both are compiled without it —; formats() the name of each
Adapter\SanitizerPurifierHtmlPurifierdefaultPolicies(), one sanitizer per level
Adapter\CodeClassesfinal readonly classThe classes kept on code (language-…) and span (hl-…), an attribute sanitizer of symfony/html-sanitizer
Adapter\PlainText, Adapter\AutolinkcompilersPlain text, links in text

The root namespace — formats, levels, ports and exceptions — is what a domain model may name; the analyser, the readers, the adapters, Markup and MarkedUpText belong with the infrastructure. The classes of Reader\Markdown and the rules under Reader\Markdown\Rule that the table does not name, the classes of Reader\BBCode other than BBCodeReader, those of Reader\Wiki other than WikiLinks, the syntaxes of the wikis and the walker of Reader\Html, are internal.

Formats

FormatCompiled
markdownread into UJO by MarkdownReader, then rendered by phil/ujo; raw HTML kept at all, escaped below
ujoread and checked by phil/ujo, then rendered; a source that is not valid throws InvalidSource
htmlas written; HtmlReader converts it into UJO on demand: see HTML
bbcoderead into UJO by BBCodeReader, then rendered; raw HTML as for Markdown: see BBCode
mediawiki, dokuwiki, creoleread into UJO by MediaWikiReader, DokuWikiReader, CreoleReader, then rendered; raw HTML as for Markdown: see The wikis
textescaped; a paragraph per block separated by a blank line, a line break per other new line, addresses made links; TextReader converts it into UJO paragraphs on demand
a format of an add-onread into UJO by the reader its ReaderProvider gives, then rendered

The HTML phil/ujo renders carries the classes of its blocks — ujo-paragraph, ujo-header — and the identifiers of headings. The purifier of every level removes the classes but those of code (Adapter\CodeClasses): language-… on code, which names the language of a block for a highlighter in the browser, and hl-… on span, which a highlighter on the server writes, where spans are kept; all keeps the identifiers, which a table of contents links to. Formats lists, feature by feature, how each format writes it.

Levels

LevelKeepsFor
basicstrong, b, em, i, u, s, del, sub, sup, code, bra name, a caption, a short comment
forumbasic, with p, a, img, ul, ol, li, blockquote, cite, pre, hra message of a forum
allevery element symfony/html-sanitizer counts as safe, headings and tables includedan article an editor writes

A container a level does not allow — a paragraph, a list, a heading, a table — is removed and its text kept; any other element — a script, a frame, a form, an object — is removed with its content. Every level removes attributes it does not know, styles and event handlers among them. Links may use http, https and mailto, or be relative; images http and https, or be relative. The input length is not capped.

An image is a request to its host. At forum and all, an image of another site — [img]https://…[/img], ![](https://…), <img src="https://…"> — makes the browser of every reader call that site, which learns their address and when they read: tracking without their consent when a member wrote the image, which Law 25 and the GDPR forbid without it. SanitizerPurifier::defaultPolicies() takes the hosts images may come from:

SanitizerPurifier::defaultPolicies(['cdn.example.com']);   // that host and its subdomains, and the site's own images
SanitizerPurifier::defaultPolicies([]);                    // the site's own images only
SanitizerPurifier::defaultPolicies();                      // any host

An image from another host loses its src; a relative image, served by the site itself, is always kept. A site whose members write texts at forum gives the hosts it serves images from, or [].

Purify again what was stored when it is shown: a policy that tightens then applies to texts written before.