-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add rawHtml without using it (extensions may opt-in)
- Loading branch information
1 parent
7073ac3
commit add8d18
Showing
3 changed files
with
97 additions
and
3 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,39 @@ | ||
<?php | ||
|
||
class UnsafeExtension extends Parsedown | ||
{ | ||
protected function blockFencedCodeComplete($Block) | ||
{ | ||
$text = $Block['element']['text']['text']; | ||
unset($Block['element']['text']['text']); | ||
|
||
// WARNING: There is almost always a better way of doing things! | ||
// | ||
// This example is one of them, unsafe behaviour is NOT needed here. | ||
// Only use this if you trust the input and have no idea what | ||
// the output HTML will look like (e.g. using an external parser). | ||
$Block['element']['text']['rawHtml'] = "<p>$text</p>"; | ||
|
||
return $Block; | ||
} | ||
} | ||
|
||
class TrustDelegatedExtension extends Parsedown | ||
{ | ||
protected function blockFencedCodeComplete($Block) | ||
{ | ||
$text = $Block['element']['text']['text']; | ||
unset($Block['element']['text']['text']); | ||
|
||
// WARNING: There is almost always a better way of doing things! | ||
// | ||
// This behaviour is NOT needed in the demonstrated case. | ||
// Only use this if you are sure that the result being added into | ||
// rawHtml is safe. | ||
// (e.g. using an external parser with escaping capabilities). | ||
$Block['element']['text']['rawHtml'] = "<p>$text</p>"; | ||
$Block['element']['text']['allowRawHtmlInSafeMode'] = true; | ||
|
||
return $Block; | ||
} | ||
} |