-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a bridge to the league/commonmark Markdown parser
- Loading branch information
Showing
6 changed files
with
85 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
/** | ||
* FrontYAML | ||
* | ||
* @copyright Matthieu Napoli http://mnapoli.fr | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT (see the LICENSE file) | ||
*/ | ||
|
||
namespace Mni\FrontYAML\Bridge\CommonMark; | ||
|
||
use League\CommonMark\CommonMarkConverter; | ||
use Mni\FrontYAML\Markdown\MarkdownParser; | ||
|
||
/** | ||
* Bridge to the League CommonMark parser | ||
* | ||
* @author Matthieu Napoli <[email protected]> | ||
*/ | ||
class CommonMarkParser implements MarkdownParser | ||
{ | ||
public function __construct(CommonMarkConverter $commonMarkConverter = null) | ||
{ | ||
$this->parser = $commonMarkConverter ?: new CommonMarkConverter(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function parse($markdown) | ||
{ | ||
return $this->parser->convertToHtml($markdown); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace Mni\FrontYAML\Test\Bridge\CommonMark; | ||
|
||
use Mni\FrontYAML\Bridge\CommonMark\CommonMarkParser; | ||
|
||
class CommonMarkParserTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testParseWithDefaultParser() | ||
{ | ||
$parser = new CommonMarkParser(); | ||
|
||
$html = $parser->parse('# This is a title'); | ||
|
||
$this->assertEquals("<h1>This is a title</h1>\n", $html); | ||
} | ||
|
||
public function testParseWithGivenParser() | ||
{ | ||
$markdown = '# This is a title'; | ||
$html = "<h1>This is a title</h1>\n"; | ||
|
||
$commonMark = $this->getMock('League\CommonMark\CommonMarkConverter'); | ||
$commonMark->expects($this->once()) | ||
->method('convertToHtml') | ||
->with($markdown) | ||
->willReturn($html); | ||
|
||
$parser = new CommonMarkParser($commonMark); | ||
|
||
$this->assertEquals($html, $parser->parse($markdown)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?php | ||
|
||
namespace Test\Mni\FrontYAML\Parser; | ||
namespace Mni\FrontYAML\Test; | ||
|
||
use Mni\FrontYAML\Parser; | ||
|
||
|