mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
Add unsafeHtml option for extensions to use on trusted input
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
require 'UnsafeExtension.php';
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
@@ -55,6 +56,17 @@ class ParsedownTest extends TestCase
|
||||
$this->assertEquals($expectedMarkup, $actualMarkup);
|
||||
}
|
||||
|
||||
function testUnsafeHtml()
|
||||
{
|
||||
$markdown = "```php\nfoobar\n```";
|
||||
$expectedMarkup = '<pre><code class="language-php"><p>foobar</p></code></pre>';
|
||||
|
||||
$unsafeExtension = new UnsafeExtension;
|
||||
$actualMarkup = $unsafeExtension->text($markdown);
|
||||
|
||||
$this->assertEquals($expectedMarkup, $actualMarkup);
|
||||
}
|
||||
|
||||
function data()
|
||||
{
|
||||
$data = array();
|
||||
|
||||
14
test/UnsafeExtension.php
Normal file
14
test/UnsafeExtension.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
class UnsafeExtension extends Parsedown
|
||||
{
|
||||
protected function blockFencedCodeComplete($Block)
|
||||
{
|
||||
$text = $Block['element']['text']['text'];
|
||||
unset($Block['element']['text']['text']);
|
||||
|
||||
$Block['element']['text']['unsafeHtml'] = "<p>$text</p>";
|
||||
|
||||
return $Block;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user