Commit 949bcb1f authored by Brett Walker's avatar Brett Walker

Fenced blockquotes to not change source line pos

Replaces blockquote fences with \n,
keeping the line numbering intact.
parent 3ccb4d95
---
title: Allow task lists that follow a blockquote to work correctly
merge_request: 26937
author:
type: fixed
......@@ -42,7 +42,9 @@ module Banzai
def call
@text.gsub(REGEX) do
if $~[:quote]
$~[:quote].gsub(/^/, "> ").gsub(/^> $/, ">")
# keep the same number of source lines/positions by replacing the
# fence lines with newlines
"\n" + $~[:quote].gsub(/^/, "> ").gsub(/^> $/, ">") + "\n"
else
$~[0]
end
......
......@@ -18,10 +18,13 @@ Double `>>>` inside code block:
Blockquote outside code block:
> Quote
Code block inside blockquote:
> Quote
>
> ```
......@@ -30,8 +33,10 @@ Code block inside blockquote:
>
> Quote
Single `>>>` inside code block inside blockquote:
> Quote
>
> ```
......@@ -42,8 +47,10 @@ Single `>>>` inside code block inside blockquote:
>
> Quote
Double `>>>` inside code block inside blockquote:
> Quote
>
> ```
......@@ -56,6 +63,7 @@ Double `>>>` inside code block inside blockquote:
>
> Quote
Single `>>>` inside HTML:
<pre>
......@@ -76,10 +84,13 @@ Double `>>>` inside HTML:
Blockquote outside HTML:
> Quote
HTML inside blockquote:
> Quote
>
> <pre>
......@@ -88,8 +99,10 @@ HTML inside blockquote:
>
> Quote
Single `>>>` inside HTML inside blockquote:
> Quote
>
> <pre>
......@@ -100,8 +113,10 @@ Single `>>>` inside HTML inside blockquote:
>
> Quote
Double `>>>` inside HTML inside blockquote:
> Quote
>
> <pre>
......@@ -113,3 +128,4 @@ Double `>>>` inside HTML inside blockquote:
> </pre>
>
> Quote
......@@ -13,6 +13,6 @@ describe Banzai::Filter::BlockquoteFenceFilter do
end
it 'allows trailing whitespace on blockquote fence lines' do
expect(filter(">>> \ntest\n>>> ")).to eq("> test")
expect(filter(">>> \ntest\n>>> ")).to eq("\n> test\n")
end
end
......@@ -58,8 +58,10 @@ describe Issues::BuildService do
"> That has a quote\n"\
">>>\n"
note_result = " > This is a string\n"\
" > \n"\
" > > with a blockquote\n"\
" > > > That has a quote\n"
" > > > That has a quote\n"\
" > \n"
discussion = create(:diff_note_on_merge_request, note: note_text).to_discussion
expect(service.item_for_discussion(discussion)).to include(note_result)
end
......
......@@ -113,4 +113,25 @@ describe TaskListToggleService do
expect(toggler.execute).to be_falsey
end
it 'properly handles a GitLab blockquote' do
markdown =
<<-EOT.strip_heredoc
>>>
gitlab blockquote
>>>
* [ ] Task 1
* [x] Task 2
EOT
markdown_html = Banzai::Pipeline::FullPipeline.call(markdown, project: nil)[:output].to_html
toggler = described_class.new(markdown, markdown_html,
toggle_as_checked: true,
line_source: '* [ ] Task 1', line_number: 5)
expect(toggler.execute).to be_truthy
expect(toggler.updated_markdown.lines[4]).to eq "* [x] Task 1\n"
expect(toggler.updated_markdown_html).to include('disabled checked> Task 1')
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment