Resolve error with code blocks in numbered lists (#3633)
This commit is contained in:
parent
b37522a45c
commit
f1492fa2bd
3 changed files with 15 additions and 5 deletions
|
|
@ -161,8 +161,8 @@ class MarkdownParser
|
|||
|
||||
def escape_liquid_tags_in_codeblock(content)
|
||||
# Escape codeblocks, code spans, and inline code
|
||||
content.gsub(/`{3}.*?`{3}|`{2}.+?`{2}|`{1}.+?`{1}/m) do |codeblock|
|
||||
if codeblock[0..2] == "```"
|
||||
content.gsub(/[[:space:]]*`{3}.*?`{3}|`{2}.+?`{2}|`{1}.+?`{1}/m) do |codeblock|
|
||||
if codeblock.match?(/[[:space:]]*`{3}/)
|
||||
"\n{% raw %}\n" + codeblock + "\n{% endraw %}\n"
|
||||
else
|
||||
"{% raw %}" + codeblock + "{% endraw %}"
|
||||
|
|
|
|||
|
|
@ -17,6 +17,18 @@ RSpec.describe MarkdownParser do
|
|||
expect(generate_and_parse_markdown(code_block)).to include("{% what %}")
|
||||
end
|
||||
|
||||
it "escapes codeblocks in numbered lists" do
|
||||
code_block = "1. Define your hooks in config file `lefthook.yml`\n
|
||||
```yaml
|
||||
pre-push:\n parallel: true\n commands:\n rubocop:
|
||||
run: bundle exec rspec --fail-fast\n
|
||||
```"
|
||||
escaped_codeblock = generate_and_parse_markdown(code_block)
|
||||
expect(escaped_codeblock).not_to include("```")
|
||||
expect(escaped_codeblock).not_to include("`")
|
||||
expect(escaped_codeblock).to include("bundle exec rspec --fail-fast")
|
||||
end
|
||||
|
||||
it "escapes liquid tags in code spans" do
|
||||
code_span = "``{% what %}``"
|
||||
expect(generate_and_parse_markdown(code_span)).to include("{% what %}")
|
||||
|
|
|
|||
|
|
@ -96,9 +96,7 @@ Format: <a href="cloudinary_link"></a></p>
|
|||
the present is our past.</p>
|
||||
</blockquote>
|
||||
|
||||
<p>I think you should use an <code><addr></code> element here instead.</p>
|
||||
|
||||
|
||||
<p>I think you should use an <code><addr></code> element here instead.<br /></p>
|
||||
|
||||
<div class="highlight"><pre class="highlight javascript"><code><span class="kd">function</span> <span class="nx">fancyAlert</span><span class="p">(</span><span class="nx">arg</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">if</span><span class="p">(</span><span class="nx">arg</span><span class="p">)</span> <span class="p">{</span>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue