) — rarely used. * - Nested brackets in alt text (![foo ![bar](x)](y), ![foo [bar](x)](y)) * — leftmost-match cannot reorder; outer falls back to literal. * - Title HTML attribute — DokuWiki media instructions have no separate * title-attribute slot (alt is used as the caption). The title parses * cleanly but is discarded. * - Mixed syntax: ![alt](url) inside [[dw|link]] or {{dw|media}} inside * [gfm](link) — cross-syntax nesting is out of scope. */ class GfmMedia extends AbstractMode { /** @inheritdoc */ public function getSort() { return 310; } /** @inheritdoc */ public function connectTo($mode) { // Outer shape: `![alt](url)`. Alt class forbids brackets and // newlines; URL slot is permissive (`[^)\n]+`) — handle() does // URL / title splitting post-entry, mirroring how GfmLink and DW // Internallink work. $this->Lexer->addSpecialPattern('!\[[^\[\]\n]*\]\([^)\n]+\)', $mode, 'gfm_media'); } /** @inheritdoc */ public function handle($match, $state, $pos, Handler $handler) { $sep = strpos($match, ']('); $alt = substr($match, 2, $sep - 2); $inside = trim(substr($match, $sep + 2, -1)); $url = substr($inside, 0, strcspn($inside, " \t\n")); $p = MediaHelper::parseParameters($url); $call = (media_isexternal($p['src']) || link_isinterwiki($p['src'])) ? 'externalmedia' : 'internalmedia'; $handler->addCall( $call, [$p['src'], $alt !== '' ? $alt : null, $p['align'], $p['width'], $p['height'], $p['cache'], $p['linking']], $pos ); return true; } }