mirror of
https://github.com/silverstripe/silverstripe-docsviewer
synced 2024-10-22 09:05:56 +00:00
BUGFIX: Deprecation errors and strict warnings breaks the docsviewer
This commit is contained in:
parent
ae092ebf19
commit
fa646cdbf6
@ -43,7 +43,7 @@ class DocumentationParser {
|
|||||||
|
|
||||||
$md = self::rewrite_api_links($md, $page);
|
$md = self::rewrite_api_links($md, $page);
|
||||||
$md = self::rewrite_heading_anchors($md, $page);
|
$md = self::rewrite_heading_anchors($md, $page);
|
||||||
$md = self::rewrite_code_blocks($md, $page);
|
$md = self::rewrite_code_blocks($md);
|
||||||
|
|
||||||
require_once(DOCSVIEWER_PATH .'/thirdparty/markdown/markdown.php');
|
require_once(DOCSVIEWER_PATH .'/thirdparty/markdown/markdown.php');
|
||||||
|
|
||||||
@ -53,11 +53,11 @@ class DocumentationParser {
|
|||||||
return $parser->transform($md);
|
return $parser->transform($md);
|
||||||
}
|
}
|
||||||
|
|
||||||
function rewrite_code_blocks($md) {
|
public static function rewrite_code_blocks($md) {
|
||||||
$started = false;
|
$started = false;
|
||||||
$inner = false;
|
$inner = false;
|
||||||
|
|
||||||
$lines = split("\n", $md);
|
$lines = explode("\n", $md);
|
||||||
foreach($lines as $i => $line) {
|
foreach($lines as $i => $line) {
|
||||||
if(!$started && preg_match('/^\t*:::\s*(.*)/', $line, $matches)) {
|
if(!$started && preg_match('/^\t*:::\s*(.*)/', $line, $matches)) {
|
||||||
// first line with custom formatting
|
// first line with custom formatting
|
||||||
@ -203,14 +203,14 @@ class DocumentationParser {
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static function rewrite_heading_anchors($md, $page) {
|
public static function rewrite_heading_anchors($md, $page) {
|
||||||
$re = '/^\#+(.*)/m';
|
$re = '/^\#+(.*)/m';
|
||||||
$md = preg_replace_callback($re, array('DocumentationParser', '_rewrite_heading_anchors_callback'), $md);
|
$md = preg_replace_callback($re, array('DocumentationParser', '_rewrite_heading_anchors_callback'), $md);
|
||||||
|
|
||||||
return $md;
|
return $md;
|
||||||
}
|
}
|
||||||
|
|
||||||
static function _rewrite_heading_anchors_callback($matches) {
|
public static function _rewrite_heading_anchors_callback($matches) {
|
||||||
$heading = $matches[0];
|
$heading = $matches[0];
|
||||||
$headingText = $matches[1];
|
$headingText = $matches[1];
|
||||||
|
|
||||||
@ -236,8 +236,8 @@ class DocumentationParser {
|
|||||||
$t = $title;
|
$t = $title;
|
||||||
$t = str_replace('&','-and-',$t);
|
$t = str_replace('&','-and-',$t);
|
||||||
$t = str_replace('&','-and-',$t);
|
$t = str_replace('&','-and-',$t);
|
||||||
$t = ereg_replace('[^A-Za-z0-9]+','-',$t);
|
$t = preg_replace('/[^A-Za-z0-9]+/','-',$t);
|
||||||
$t = ereg_replace('-+','-',$t);
|
$t = preg_replace('/-+/','-',$t);
|
||||||
$t = trim($t, '-');
|
$t = trim($t, '-');
|
||||||
$t = strtolower($t);
|
$t = strtolower($t);
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ class DocumentationService {
|
|||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function get_ignored_files() {
|
public static function get_ignored_files() {
|
||||||
return self::$ignored_files;
|
return self::$ignored_files;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,15 @@
|
|||||||
*/
|
*/
|
||||||
class DocumentationParserTest extends SapphireTest {
|
class DocumentationParserTest extends SapphireTest {
|
||||||
|
|
||||||
|
function testGenerateHtmlId() {
|
||||||
|
$this->assertEquals('title-one', DocumentationParser::generate_html_id('title one'));
|
||||||
|
$this->assertEquals('title-one', DocumentationParser::generate_html_id('Title one'));
|
||||||
|
$this->assertEquals('title-and-one', DocumentationParser::generate_html_id('Title & One'));
|
||||||
|
$this->assertEquals('title-and-one', DocumentationParser::generate_html_id('Title & One'));
|
||||||
|
$this->assertEquals('title-one', DocumentationParser::generate_html_id(' Title one '));
|
||||||
|
$this->assertEquals('title-one', DocumentationParser::generate_html_id('Title--one'));
|
||||||
|
}
|
||||||
|
|
||||||
function testRewriteCodeBlocks() {
|
function testRewriteCodeBlocks() {
|
||||||
$page = new DocumentationPage();
|
$page = new DocumentationPage();
|
||||||
$page->setRelativePath('test.md');
|
$page->setRelativePath('test.md');
|
||||||
|
@ -268,4 +268,17 @@ class DocumentationViewerTest extends FunctionalTest {
|
|||||||
$this->assertNull($warn->OutdatedRelease);
|
$this->assertNull($warn->OutdatedRelease);
|
||||||
$this->assertTrue($warn->FutureRelease);
|
$this->assertTrue($warn->FutureRelease);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that the pages comes back sorted by filename
|
||||||
|
*/
|
||||||
|
function testGetEntityPagesSortedByFilename() {
|
||||||
|
$v = new DocumentationViewer();
|
||||||
|
$response = $v->handleRequest(new SS_HTTPRequest('GET', 'DocumentationViewerTests/en/3.0/'), DataModel::inst());
|
||||||
|
$pages = $v->getEntityPages();
|
||||||
|
$links = $pages->column('Link');
|
||||||
|
$this->assertStringEndsWith('DocumentationViewerTests/en/3.0/ChangeLog', $links[0]);
|
||||||
|
$this->assertStringEndsWith('DocumentationViewerTests/en/3.0/Tutorials', $links[1]);
|
||||||
|
$this->assertStringEndsWith('DocumentationViewerTests/en/3.0/empty', $links[2]);
|
||||||
|
}
|
||||||
}
|
}
|
3
tests/docs-v3.0/en/ChangeLog.md
Normal file
3
tests/docs-v3.0/en/ChangeLog.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
This is a changelog
|
3
tests/docs-v3.0/en/Tutorials.md
Normal file
3
tests/docs-v3.0/en/Tutorials.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Tutorials
|
||||||
|
|
||||||
|
This a bunch of tutorials
|
Loading…
x
Reference in New Issue
Block a user