function testRewriteCodeBlocks() { $page = new DocumentationPage(); $page->setRelativePath('test.md'); $page->setEntity(new DocumentationEntity('mymodule', '2.4', BASE_PATH . '/sapphiredocs/tests/docs/')); $page->setLang('en'); $page->setVersion('2.4'); $result = DocumentationParser::rewrite_code_blocks($page->getMarkdown()); $expected = <<<HTML <pre class="brush: php"> code block with multiple lines \tand tab indent \tand escaped < brackets </pre> Normal text after code block HTML; $this->assertContains($expected, $result, 'Custom code blocks with ::: prefix'); $expected = <<<HTML <pre> code block without formatting prefix </pre> HTML; $this->assertContains($expected, $result, 'Traditional markdown code blocks'); }
/** * Parse a given path to the documentation for a file. Performs a case insensitive * lookup on the file system. Automatically appends the file extension to one of the markdown * extensions as well so /install/ in a web browser will match /install.md or /INSTALL.md * * Filepath: /var/www/myproject/src/cms/en/folder/subfolder/page.md * URL: http://myhost/mywebroot/dev/docs/2.4/cms/en/folder/subfolder/page * Webroot: http://myhost/mywebroot/ * Baselink: dev/docs/2.4/cms/en/ * Pathparts: folder/subfolder/page * * @param DocumentationPage $page * @param String $baselink Link relative to webroot, up until the "root" of the module. * Necessary to rewrite relative links * * @return String */ public static function parse(DocumentationPage $page, $baselink = null) { $md = $page->getMarkdown(); // Pre-processing $md = self::rewrite_image_links($md, $page); $md = self::rewrite_relative_links($md, $page, $baselink); $md = self::rewrite_api_links($md, $page); // $md = self::rewrite_code_blocks($md, $page); require_once '../sapphiredocs/thirdparty/markdown.php'; $html = Markdown($md); return $html; }
/** * Strips out the metadata for a page * * @param DocumentationPage */ public static function retrieve_meta_data(DocumentationPage &$page) { if ($md = $page->getMarkdown()) { $matches = preg_match_all('/ (?<key>[A-Za-z0-9_-]+): \\s* (?<value>.*) /x', $md, $meta); if ($matches) { foreach ($meta['key'] as $index => $key) { if (isset($meta['value'][$index])) { $page->setMetaData($key, $meta['value'][$index]); } } } } }
public function testRewriteCodeBlocks() { $codePage = new DocumentationPage($this->entityAlt, 'CodeSnippets.md', DOCSVIEWER_PATH . '/tests/docs-parser/en/CodeSnippets.md'); $result = DocumentationParser::rewrite_code_blocks($codePage->getMarkdown()); $expected = <<<HTML #### <% control Foo %> ``` code block <% without formatting prefix %> ``` Paragraph with a segment of <% foo %> ``` code block that has a line in it ``` This is a yaml block ```yaml foo: bar baz: qux ``` This is a yaml block with tab in that new line ```yaml foo: bar baz: qux ``` HTML; $this->assertEquals($expected, $result, 'Code blocks support line breaks'); $result = DocumentationParser::rewrite_code_blocks($this->page->getMarkdown()); $expected = <<<HTML ```php code block with multiple lines \tand tab indent \tand escaped < brackets \t ``` Normal text after code block HTML; $this->assertContains($expected, $result, 'Custom code blocks with ::: prefix'); $expected = <<<HTML ``` code block without formatting prefix ``` HTML; $this->assertContains($expected, $result, 'Traditional markdown code blocks'); $expected = <<<HTML ``` Fenced code block ``` HTML; $this->assertContains($expected, $result, 'Backtick code blocks'); $expected = <<<HTML ```php Fenced box with new lines in between content ``` HTML; $this->assertContains($expected, $result, 'Backtick with newlines'); }