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 ...@@ -42,7 +42,9 @@ module Banzai
def call def call
@text.gsub(REGEX) do @text.gsub(REGEX) do
if $~[:quote] 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 else
$~[0] $~[0]
end end
......
...@@ -18,10 +18,13 @@ Double `>>>` inside code block: ...@@ -18,10 +18,13 @@ Double `>>>` inside code block:
Blockquote outside code block: Blockquote outside code block:
> Quote > Quote
Code block inside blockquote: Code block inside blockquote:
> Quote > Quote
> >
> ``` > ```
...@@ -30,8 +33,10 @@ Code block inside blockquote: ...@@ -30,8 +33,10 @@ Code block inside blockquote:
> >
> Quote > Quote
Single `>>>` inside code block inside blockquote: Single `>>>` inside code block inside blockquote:
> Quote > Quote
> >
> ``` > ```
...@@ -42,8 +47,10 @@ Single `>>>` inside code block inside blockquote: ...@@ -42,8 +47,10 @@ Single `>>>` inside code block inside blockquote:
> >
> Quote > Quote
Double `>>>` inside code block inside blockquote: Double `>>>` inside code block inside blockquote:
> Quote > Quote
> >
> ``` > ```
...@@ -56,6 +63,7 @@ Double `>>>` inside code block inside blockquote: ...@@ -56,6 +63,7 @@ Double `>>>` inside code block inside blockquote:
> >
> Quote > Quote
Single `>>>` inside HTML: Single `>>>` inside HTML:
<pre> <pre>
...@@ -76,10 +84,13 @@ Double `>>>` inside HTML: ...@@ -76,10 +84,13 @@ Double `>>>` inside HTML:
Blockquote outside HTML: Blockquote outside HTML:
> Quote > Quote
HTML inside blockquote: HTML inside blockquote:
> Quote > Quote
> >
> <pre> > <pre>
...@@ -88,8 +99,10 @@ HTML inside blockquote: ...@@ -88,8 +99,10 @@ HTML inside blockquote:
> >
> Quote > Quote
Single `>>>` inside HTML inside blockquote: Single `>>>` inside HTML inside blockquote:
> Quote > Quote
> >
> <pre> > <pre>
...@@ -100,8 +113,10 @@ Single `>>>` inside HTML inside blockquote: ...@@ -100,8 +113,10 @@ Single `>>>` inside HTML inside blockquote:
> >
> Quote > Quote
Double `>>>` inside HTML inside blockquote: Double `>>>` inside HTML inside blockquote:
> Quote > Quote
> >
> <pre> > <pre>
...@@ -113,3 +128,4 @@ Double `>>>` inside HTML inside blockquote: ...@@ -113,3 +128,4 @@ Double `>>>` inside HTML inside blockquote:
> </pre> > </pre>
> >
> Quote > Quote
...@@ -13,6 +13,6 @@ describe Banzai::Filter::BlockquoteFenceFilter do ...@@ -13,6 +13,6 @@ describe Banzai::Filter::BlockquoteFenceFilter do
end end
it 'allows trailing whitespace on blockquote fence lines' do 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
end end
...@@ -58,8 +58,10 @@ describe Issues::BuildService do ...@@ -58,8 +58,10 @@ describe Issues::BuildService do
"> That has a quote\n"\ "> That has a quote\n"\
">>>\n" ">>>\n"
note_result = " > This is a string\n"\ note_result = " > This is a string\n"\
" > \n"\
" > > with a blockquote\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 discussion = create(:diff_note_on_merge_request, note: note_text).to_discussion
expect(service.item_for_discussion(discussion)).to include(note_result) expect(service.item_for_discussion(discussion)).to include(note_result)
end end
......
...@@ -113,4 +113,25 @@ describe TaskListToggleService do ...@@ -113,4 +113,25 @@ describe TaskListToggleService do
expect(toggler.execute).to be_falsey expect(toggler.execute).to be_falsey
end 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 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