kartik-v / yii2-markdown

Advanced Markdown editing and conversion utilities for Yii Framework 2.0
http://demos.krajee.com/markdown
Other
89 stars 41 forks source link

Error when using <?php tag inside the processing text #72

Closed buttflattery closed 6 years ago

buttflattery commented 6 years ago

Prerequisites

Steps to reproduce the issue

1.Install the extension 2.crate a readme.md file and add the following containing the <?php tag


<?php echo "some text"
  1. Convert the text using
echo Markdown::process($this->render('README.md'));

Expected behavior and actual behavior

When I follow those steps, I see...

PHP Parse Error – yii\base\ErrorException syntax error, unexpected '`'

I was expecting... The formatted output

If you remove the <?php tag from the text to be processed then it works ok

BUT

If you use it in the following way it even works along the <?php tag

<?php $html = <<< HTML
        <?php echo "some text";
HTML;
?>
<?=\kartik\markdown\Markdown::process($html) ?>

Environment

Yii 2.0.15.1

Browsers

Operating System

Libraries

Isolating the problem

kartik-v commented 6 years ago

Use Html::encode on the text before you process using Markdown::process.

buttflattery commented 6 years ago

@kartik-v Well to my surprise the Html::encode() does not solve the issue, instead you have to provide the closing ?> tags along with the starting tags to make it work correctly when using $this->render('README.md') to load the text.