Closed acq688 closed 2 years ago
However, you see that "<", ">", and "&" are showing up as HTML entities. I've tried escaping them in various ways, without any luck. Please let me know if you see something that I'm doing wrong. Thank you!
If I use the following input file:
<details>
<summary markdown="0">
<h4>Test Example Code Here</h4>
</summary>
<div>
Check out my code block below:
~~~bash
# We are in a code block
export VARIABLE=xxx
echo "VARIABLE" > test.txt
Less than: >
Greater than: <
Ampersand: &
and run it through `kramdown --parse-block-html --parse-span-html` I get the following result:
~~~html
<details>
<summary>
<h4>Test Example Code Here</h4>
</summary>
<div>
<p>Check out my code block below:</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># We are in a code block</span>
<span class="nb">export </span><span class="nv">VARIABLE</span><span class="o">=</span>xxx
<span class="nb">echo</span> <span class="s2">"VARIABLE"</span> <span class="o">></span> test.txt
Less than: <span class="o">></span>
Greater than: <
Ampersand: &
</code></pre></div> </div>
</div>
</details>
which looks right.
Is this what you want? Note that I'm using the standard kramdown parser in this example.
Hi @gettalong -- thanks for the response!
Hmm, using the CLI, I get the same output that you do, which is the desired output.
However, if I copy this same block of code into my markdown file for Github pages I get:
<details>
<summary>
<h4>Test Example Code Here</h4>
</summary>
<div>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code><table class="rouge-table"><tbody><tr><td class="rouge-gutter gl"><pre class="lineno">1
2
3
</pre></td><td class="rouge-code"><pre><p>Check out my code block below:</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><table class="rouge-table"><tbody><tr><td class="rouge-gutter gl"><pre class="lineno">1 2 3 4 5 6 7
</pre></td></tr></tbody></table></code></pre></div> </div>
<p></pre></td><td class="rouge-code"><pre><span class="c"># We are in a code block</span>
<span class="nb">export </span><span class="nv">VARIABLE</span><span class="o">=</span>xxx
<span class="nb">echo</span> <span class="s2">“VARIABLE”</span> <span class="o">></span> test.txt</p>
<p>Less than: <span class="o">></span>
Greater than: <
Ampersand: &
</pre></td></tr></tbody></table></code></pre></div> </div></p>
</div>
</details>
Which renders as:
If I go ahead and add markdown="0"
to that div, I get:
<details>
<summary>
<h4>Test Example Code Here</h4>
</summary>
<div>
<p>Check out my code block below:</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><table class="rouge-table"><tbody><tr><td class="rouge-gutter gl"><pre class="lineno">1
2
3
4
5
6
7
</pre></td><td class="rouge-code"><pre><span class="c"># We are in a code block</span>
<span class="nb">export </span><span class="nv">VARIABLE</span><span class="o">=</span>xxx
<span class="nb">echo</span> <span class="s2">"VARIABLE"</span> &gt<span class="p">;</span> test.txt
Less than: &gt<span class="p">;</span>
Greater than: &lt<span class="p">;</span>
Ampersand: &amp<span class="p">;</span>
</pre></td></tr></tbody></table></code></pre></div> </div>
</div>
</details>
Which renders as:
Which seems to be correct, beyond the odd treatment of those characters (and the semicolon in the span). 🤔 I'm wondering if maybe this is conflicting with something else in the project...
Using the kramdown CLI you are by default using the kramdown parser and not the GFM one. So you might wanna narrow it down to whether it is the GFM parser or Jekyll and then report there.
Since kramdown itself is working fine, I will close the issue.
Thanks for putting me on the right path for this!
In case anyone else stumbles upon this issue, I was able to narrow it down to the base HTML page, where {{ section.content | markdownify }}
is being used.
Since the <div>
I'm using is set to markdown="0"
, kramdown is providing the following output:
<details>
<summary>
<h4>Test Example Code Here</h4>
</summary>
<div>
Check out my code block below:
~~~bash
# We are in a code block
export VARIABLE=xxx
echo "VARIABLE" > test.txt
Less than: >
Greater than: <
Ampersand: &
~~~
</div>
</details>
And this is getting piped through to markdownify. Markdownify doesn't seem to know what to do with those existing HTML entities, and they end up getting escaped incorrectly. I'm not sure if this is a bug in any particular project or just an unfortunate side effect of the way they're interacting. For now, while it's not the prettiest fix, I can bypass this issue by calling:
{{ section.content | replace: "&", "&" | replace: "<", "<" | replace: ">", ">" | markdownify }}
Hi -- I'm working with Github Pages and Jekyll and I've run into an issue with the characters "<", ">", and "&" showing as HTML entities inside of a code block when that code block is nested as follows:
In my markdown file I have the following block: