[15-min-fix] Add option for triple tildes for fenced codeblocks (#13810)
* Add option for triple tildes for fenced codeblocks Note that this doesn't account for all triple backticks in fenced codeblocks situations. * Add commented out but failing test case for the future? * Add tests from QA instructions
This commit is contained in:
parent
0b80d92d66
commit
864a9195a9
2 changed files with 14 additions and 1 deletions
|
|
@ -114,7 +114,7 @@ module MarkdownProcessor
|
|||
|
||||
def escape_liquid_tags_in_codeblock(content)
|
||||
# Escape codeblocks, code spans, and inline code
|
||||
content.gsub(/[[:space:]]*`{3}.*?`{3}|`{2}.+?`{2}|`{1}.+?`{1}/m) do |codeblock|
|
||||
content.gsub(/[[:space:]]*~{3}.*?~{3}|[[:space:]]*`{3}.*?`{3}|`{2}.+?`{2}|`{1}.+?`{1}/m) do |codeblock|
|
||||
codeblock.gsub!("{% endraw %}", "{----% endraw %----}")
|
||||
codeblock.gsub!("{% raw %}", "{----% raw %----}")
|
||||
if codeblock.match?(/[[:space:]]*`{3}/)
|
||||
|
|
|
|||
|
|
@ -27,6 +27,19 @@ RSpec.describe MarkdownProcessor::Parser, type: :service do
|
|||
expect(generate_and_parse_markdown(code_block)).not_to include("----")
|
||||
end
|
||||
|
||||
it "escapes some triple backticks within a codeblock when using tildes" do
|
||||
code_block = "~~~\nhello\n// ```\nwhatever\n// ```\n~~~"
|
||||
number_of_triple_backticks = generate_and_parse_markdown(code_block).scan("```").count
|
||||
expect(number_of_triple_backticks).to eq(2)
|
||||
end
|
||||
|
||||
# TODO: @zhao-andy this should fail if this issue is solved: https://github.com/forem/forem/issues/13823
|
||||
it "escapes triple backticks within a codeblock when using tildes" do
|
||||
code_block = "~~~\nhello\n```\nwhatever\n```\n~~~"
|
||||
number_of_triple_backticks = generate_and_parse_markdown(code_block).scan("```").count
|
||||
expect(number_of_triple_backticks).to eq(0)
|
||||
end
|
||||
|
||||
it "does not remove the non-'raw tag related' four dashes" do
|
||||
code_block = "```\n----\n```"
|
||||
expect(generate_and_parse_markdown(code_block)).to include("----")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue