Error when using <?php tag inside the processing text
buttflattery opened this issue · comments
Prerequisites
- I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
- The issue still exists against the latest
master
branch of yii2-markdown. - This is not a usage question. I confirm having gone through and read the documentation and demos.
- This is not a general programming/coding question. (Those should be directed to the webtips Q & A forum).
- I have attempted to find the simplest possible steps to reproduce the issue.
- I have included a failing test as a pull request (Optional).
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"
- 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
- Google Chrome
- Mozilla Firefox
- Internet Explorer
- Safari
Operating System
- Windows
- Mac OS X
- Linux
- Mobile
Libraries
- jQuery version:
- yii2-markdown version:
Isolating the problem
- This bug happens on the demos page
- The bug happens consistently across all tested browsers
- This bug happens when using yii2-markdown without other plugins.
Use Html::encode
on the text before you process using Markdown::process
.
@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.