php-markdown
php-markdown copied to clipboard
How to avoid ampersand entity encodings?
First off; this is a rocking PHP Markdown reader! I'm using it to render some help docs for a module documentation website.
I am using (fenced) code blocks to show usage examples. To pass properties to some functional parts, as example, I need to use the ampersand (&) sign. This is being converted to & ; amp; (without spaces) entities and that is not what I want in my code examples.
How can I avoid it to convert it to & and just let be written as & sign inside code blocks?
Can you give me a sample input that does that? Fenced code block don't normally double-encode ampersands.
Here you can see te rendered Markdown; https://rtfm.modxsimplecart.com/snippets/scgetcart The right content is generated by a Markdown file. The contents of the Markdown file is just with & sign without entities etc.
That doesn't really tell me what is the input given to Markdown. If I had to guess, I'd say the input is something like this:
The default snippet call for this snippet is just like this;
~~~
[[!scGetCart? &tpl=`myCustomCart`]]
~~~
And let's say we want to include all product colors (own custom TV for products);
But then if I paste this in the PHP Markdown dingus the result is as expected.
Is there another text filter function used on that site that could cause this? Or is the Markdown parser configured in a non-default way?
I am working with MarkdownExtra and that's exactly what I did. Except that I have added a class to code block to trigger the syntax highlight on my website (the black boxes). Like;
For example, with some fictive custom chunks to influence the output;
~~~~ {.language-markup}
[[!scGetCart:tag? &tpl=`myCustomCart`]]
~~~~
And let's say we want to include all product colors (own custom TV for products);
Also configured "code_attr_on_pre". Set to true. The PHP part;
/** @var \Michelf\MarkdownExtra $parser */ $parser = new MarkdownExtra; $parser->code_attr_on_pre = true; $content = file_get_contents($file); $content = $parser->defaultTransform($content);
So, I'm trying this small PHP program:
$parser = new MarkdownExtra;
$parser->code_attr_on_pre = true;
$content = "For example, with some fictive custom chunks to influence the output;
~~~~ {.language-markup}
[[!scGetCart:tag? &tpl=`myCustomCart`]]
~~~~
And let's say we want to include all product colors (own custom TV for products);";
$content = $parser->transform($content);
echo $content;
and I get this output:
<p>For example, with some fictive custom chunks to influence the output;</p>
<pre class="language-markup"><code>[[!scGetCart:tag? &tpl=`myCustomCart`]]
</code></pre>
<p>And let's say we want to include all product colors (own custom TV for products);</p>
All seems perfectly fine. I'm not sure how you get this double encoding. Which version of PHP Markdown are you using?
(Note: you're using defaultTransform above, which is a static function using the default parameters. It thus ignores your code_attr_on_pre setting. It does not seem to have any effect on the &, but you should use transform in this case.)