private function markupText($markup_file) { $contents = Filesystem::readFile($markup_file); $file = basename($markup_file); $parts = explode("\n~~~~~~~~~~\n", $contents); $this->assertEqual(3, count($parts), $markup_file); list($input_remarkup, $expected_output, $expected_text) = $parts; $engine = $this->buildNewTestEngine(); switch ($file) { case 'raw-escape.txt': // NOTE: Here, we want to test PhutilRemarkupRuleEscapeRemarkup and // PhutilRemarkupBlockStorage, which are triggered by "\1". In the // test, "~" is used as a placeholder for "\1" since it's hard to type // "\1". $input_remarkup = str_replace("~", "", $input_remarkup); $expected_output = str_replace("~", "", $expected_output); $expected_text = str_replace("~", "", $expected_text); break; case 'toc.txt': $engine->setConfig('header.generate-toc', true); break; } $actual_output = (string) $engine->markupText($input_remarkup); switch ($file) { case 'toc.txt': $table_of_contents = PhutilRemarkupEngineRemarkupHeaderBlockRule::renderTableOfContents($engine); $actual_output = $table_of_contents . "\n\n" . $actual_output; break; } $this->assertEqual($expected_output, $actual_output, "Failed to markup HTML in file '{$file}'."); $engine->setMode(PhutilRemarkupEngine::MODE_TEXT); $actual_output = (string) $engine->markupText($input_remarkup); $this->assertEqual($expected_text, $actual_output, "Failed to markup text in file '{$file}'."); }
/** * @task markup */ public function didMarkupText($field, $output, PhutilMarkupEngine $engine) { $toc = PhutilRemarkupEngineRemarkupHeaderBlockRule::renderTableOfContents($engine); if ($toc) { $toc = '<div class="phabricator-remarkup-toc">' . '<div class="phabricator-remarkup-toc-header">' . 'Table of Contents' . '</div>' . $toc . '</div>'; } return '<div class="phabricator-remarkup">' . $toc . $output . '</div>'; }
public function renderContent() { $engine = PhabricatorMarkupEngine::newPhrictionMarkupEngine(); $markup = $engine->markupText($this->getContent()); $toc = PhutilRemarkupEngineRemarkupHeaderBlockRule::renderTableOfContents($engine); if ($toc) { $toc = '<div class="phabricator-remarkup-toc">' . '<div class="phabricator-remarkup-toc-header">' . 'Table of Contents' . '</div>' . $toc . '</div>'; } return '<div class="phabricator-remarkup">' . $toc . $markup . '</div>'; }