examples() as $ex) { $reason = $skip[$ex['number']] ?? null; $label = sprintf('#%d %s', $ex['number'], $ex['section']); yield $label => [$ex['markdown'], $ex['html'], $reason]; } } /** * @dataProvider specProvider */ public function testExample(string $md, string $expected, ?string $skipReason): void { if ($skipReason !== null) { $this->markTestSkipped($skipReason); } $actual = $this->renderMarkdown($md); $this->assertHtmlEquals($expected, $actual); } public function tearDown(): void { ModeRegistry::reset(); parent::tearDown(); } /** * Render markdown text through DokuWiki's full parser pipeline under * the `md` syntax setting, using {@see SpecCompatRenderer} — * an XHTML renderer subclass that emits the minimal link/media HTML * shape the GFM spec expects. Production rendering is unchanged; * this override exists so spec output can be compared byte-for-byte. */ private function renderMarkdown(string $text): string { global $conf; $conf['syntax'] = 'md'; ModeRegistry::reset(); $instructions = p_get_instructions($text); $renderer = new SpecCompatRenderer(); $renderer->reset(); $renderer->smileys = getSmileys(); $renderer->entities = getEntities(); $renderer->acronyms = getAcronyms(); $renderer->interwiki = getInterwiki(); foreach ($instructions as $instruction) { if (method_exists($renderer, $instruction[0])) { call_user_func_array([$renderer, $instruction[0]], $instruction[1] ?: []); } } return $renderer->doc; } /** * Assert two HTML strings are equivalent after whitespace normalization. * * DokuWiki's XHTML renderer emits extra whitespace around block tags * that the spec's reference HTML omits. The comparator strips whitespace * only around **block-level** tags (p, div, h1-h6, ul/ol/li, table/tr/td, * blockquote, pre, hr). Whitespace around **inline** tags (em, strong, * a, code, span, img, br, etc.) is preserved, because `x y` * and `xy` render differently. */ private function assertHtmlEquals(string $expected, string $actual): void { $this->assertEquals( $this->normalizeHtml($expected), $this->normalizeHtml($actual) ); } /** * Strip whitespace adjacent to block-level tags; leave inline tags alone. * * Additionally drops DokuWiki-specific heading decoration that carries no * semantic meaning for GFM-conformance checks: * * - `