Add blockquote fence syntax to Markdown
This commit is contained in:
parent
92772f85c1
commit
6a477b9bfc
6 changed files with 345 additions and 2 deletions
|
@ -7,11 +7,12 @@
|
|||
* [Newlines](#newlines)
|
||||
* [Multiple underscores in words](#multiple-underscores-in-words)
|
||||
* [URL auto-linking](#url-auto-linking)
|
||||
* [Multiline Blockquote](#multiline-blockquote)
|
||||
* [Code and Syntax Highlighting](#code-and-syntax-highlighting)
|
||||
* [Inline Diff](#inline-diff)
|
||||
* [Emoji](#emoji)
|
||||
* [Special GitLab references](#special-gitlab-references)
|
||||
* [Task lists](#task-lists)
|
||||
* [Task Lists](#task-lists)
|
||||
|
||||
**[Standard Markdown](#standard-markdown)**
|
||||
|
||||
|
@ -89,6 +90,37 @@ GFM will autolink almost any URL you copy and paste into your text.
|
|||
* irc://irc.freenode.net/gitlab
|
||||
* http://localhost:3000
|
||||
|
||||
## Multiline Blockquote
|
||||
|
||||
On top of standard Markdown [blockquotes](#blockquotes), which require prepending `>` to quoted lines,
|
||||
GFM supports multiline blockquotes fenced by <code>>>></code>.
|
||||
|
||||
```no-highlight
|
||||
>>>
|
||||
If you paste a message from somewhere else
|
||||
|
||||
that
|
||||
|
||||
spans
|
||||
|
||||
multiple lines,
|
||||
|
||||
you can quote that without having to manually prepend `>` to every line!
|
||||
>>>
|
||||
```
|
||||
|
||||
>>>
|
||||
If you paste a message from somewhere else
|
||||
|
||||
that
|
||||
|
||||
spans
|
||||
|
||||
multiple lines,
|
||||
|
||||
you can quote that without having to manually prepend `>` to every line!
|
||||
>>>
|
||||
|
||||
## Code and Syntax Highlighting
|
||||
|
||||
_GitLab uses the [Rouge Ruby library][rouge] for syntax highlighting. For a
|
||||
|
|
50
lib/banzai/filter/blockquote_fence_filter.rb
Normal file
50
lib/banzai/filter/blockquote_fence_filter.rb
Normal file
|
@ -0,0 +1,50 @@
|
|||
module Banzai
|
||||
module Filter
|
||||
class BlockquoteFenceFilter < HTML::Pipeline::TextFilter
|
||||
REGEX = %r{
|
||||
(?<code>
|
||||
# Code blocks:
|
||||
# ```
|
||||
# Anything, including ignored `>>>` blocks
|
||||
# ```
|
||||
^```.+?\n```$
|
||||
)
|
||||
|
|
||||
(?<html>
|
||||
# HTML:
|
||||
# <tag>
|
||||
# Anything, including ignored `>>>` blocks
|
||||
# </tag>
|
||||
^<[^>]+?>.+?\n<\/[^>]+?>$
|
||||
)
|
||||
|
|
||||
(
|
||||
^>>>\n(?<quote>
|
||||
(?:
|
||||
(?!^```|^<[^>]+?>).
|
||||
|
|
||||
\g<code>
|
||||
|
|
||||
\g<html>
|
||||
)
|
||||
+?)\n>>>$
|
||||
)
|
||||
}mx.freeze
|
||||
|
||||
def initialize(text, context = nil, result = nil)
|
||||
super text, context, result
|
||||
@text = @text.delete "\r"
|
||||
end
|
||||
|
||||
def call
|
||||
@text.gsub(REGEX) do
|
||||
if $~[:quote]
|
||||
$~[:quote].gsub(/^/, "> ").gsub(/^> $/, ">")
|
||||
else
|
||||
$~[0]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -3,7 +3,8 @@ module Banzai
|
|||
class PreProcessPipeline < BasePipeline
|
||||
def self.filters
|
||||
FilterArray[
|
||||
Filter::YamlFrontMatterFilter
|
||||
Filter::YamlFrontMatterFilter,
|
||||
Filter::BlockquoteFenceFilter,
|
||||
]
|
||||
end
|
||||
|
||||
|
|
115
spec/fixtures/blockquote_fence_after.md
vendored
Normal file
115
spec/fixtures/blockquote_fence_after.md
vendored
Normal file
|
@ -0,0 +1,115 @@
|
|||
Single `>>>` inside code block:
|
||||
|
||||
```
|
||||
# Code
|
||||
>>>
|
||||
# Code
|
||||
```
|
||||
|
||||
Double `>>>` inside code block:
|
||||
|
||||
```
|
||||
# Code
|
||||
>>>
|
||||
# Code
|
||||
>>>
|
||||
# Code
|
||||
```
|
||||
|
||||
Blockquote outside code block:
|
||||
|
||||
> Quote
|
||||
|
||||
Code block inside blockquote:
|
||||
|
||||
> Quote
|
||||
>
|
||||
> ```
|
||||
> # Code
|
||||
> ```
|
||||
>
|
||||
> Quote
|
||||
|
||||
Single `>>>` inside code block inside blockquote:
|
||||
|
||||
> Quote
|
||||
>
|
||||
> ```
|
||||
> # Code
|
||||
> >>>
|
||||
> # Code
|
||||
> ```
|
||||
>
|
||||
> Quote
|
||||
|
||||
Double `>>>` inside code block inside blockquote:
|
||||
|
||||
> Quote
|
||||
>
|
||||
> ```
|
||||
> # Code
|
||||
> >>>
|
||||
> # Code
|
||||
> >>>
|
||||
> # Code
|
||||
> ```
|
||||
>
|
||||
> Quote
|
||||
|
||||
Single `>>>` inside HTML:
|
||||
|
||||
<pre>
|
||||
# Code
|
||||
>>>
|
||||
# Code
|
||||
</pre>
|
||||
|
||||
Double `>>>` inside HTML:
|
||||
|
||||
<pre>
|
||||
# Code
|
||||
>>>
|
||||
# Code
|
||||
>>>
|
||||
# Code
|
||||
</pre>
|
||||
|
||||
Blockquote outside HTML:
|
||||
|
||||
> Quote
|
||||
|
||||
HTML inside blockquote:
|
||||
|
||||
> Quote
|
||||
>
|
||||
> <pre>
|
||||
> # Code
|
||||
> </pre>
|
||||
>
|
||||
> Quote
|
||||
|
||||
Single `>>>` inside HTML inside blockquote:
|
||||
|
||||
> Quote
|
||||
>
|
||||
> <pre>
|
||||
> # Code
|
||||
> >>>
|
||||
> # Code
|
||||
> </pre>
|
||||
>
|
||||
> Quote
|
||||
|
||||
Double `>>>` inside HTML inside blockquote:
|
||||
|
||||
> Quote
|
||||
>
|
||||
> <pre>
|
||||
> # Code
|
||||
> >>>
|
||||
> # Code
|
||||
> >>>
|
||||
> # Code
|
||||
> </pre>
|
||||
>
|
||||
> Quote
|
131
spec/fixtures/blockquote_fence_before.md
vendored
Normal file
131
spec/fixtures/blockquote_fence_before.md
vendored
Normal file
|
@ -0,0 +1,131 @@
|
|||
Single `>>>` inside code block:
|
||||
|
||||
```
|
||||
# Code
|
||||
>>>
|
||||
# Code
|
||||
```
|
||||
|
||||
Double `>>>` inside code block:
|
||||
|
||||
```
|
||||
# Code
|
||||
>>>
|
||||
# Code
|
||||
>>>
|
||||
# Code
|
||||
```
|
||||
|
||||
Blockquote outside code block:
|
||||
|
||||
>>>
|
||||
Quote
|
||||
>>>
|
||||
|
||||
Code block inside blockquote:
|
||||
|
||||
>>>
|
||||
Quote
|
||||
|
||||
```
|
||||
# Code
|
||||
```
|
||||
|
||||
Quote
|
||||
>>>
|
||||
|
||||
Single `>>>` inside code block inside blockquote:
|
||||
|
||||
>>>
|
||||
Quote
|
||||
|
||||
```
|
||||
# Code
|
||||
>>>
|
||||
# Code
|
||||
```
|
||||
|
||||
Quote
|
||||
>>>
|
||||
|
||||
Double `>>>` inside code block inside blockquote:
|
||||
|
||||
>>>
|
||||
Quote
|
||||
|
||||
```
|
||||
# Code
|
||||
>>>
|
||||
# Code
|
||||
>>>
|
||||
# Code
|
||||
```
|
||||
|
||||
Quote
|
||||
>>>
|
||||
|
||||
Single `>>>` inside HTML:
|
||||
|
||||
<pre>
|
||||
# Code
|
||||
>>>
|
||||
# Code
|
||||
</pre>
|
||||
|
||||
Double `>>>` inside HTML:
|
||||
|
||||
<pre>
|
||||
# Code
|
||||
>>>
|
||||
# Code
|
||||
>>>
|
||||
# Code
|
||||
</pre>
|
||||
|
||||
Blockquote outside HTML:
|
||||
|
||||
>>>
|
||||
Quote
|
||||
>>>
|
||||
|
||||
HTML inside blockquote:
|
||||
|
||||
>>>
|
||||
Quote
|
||||
|
||||
<pre>
|
||||
# Code
|
||||
</pre>
|
||||
|
||||
Quote
|
||||
>>>
|
||||
|
||||
Single `>>>` inside HTML inside blockquote:
|
||||
|
||||
>>>
|
||||
Quote
|
||||
|
||||
<pre>
|
||||
# Code
|
||||
>>>
|
||||
# Code
|
||||
</pre>
|
||||
|
||||
Quote
|
||||
>>>
|
||||
|
||||
Double `>>>` inside HTML inside blockquote:
|
||||
|
||||
>>>
|
||||
Quote
|
||||
|
||||
<pre>
|
||||
# Code
|
||||
>>>
|
||||
# Code
|
||||
>>>
|
||||
# Code
|
||||
</pre>
|
||||
|
||||
Quote
|
||||
>>>
|
14
spec/lib/banzai/filter/blockquote_fence_filter_spec.rb
Normal file
14
spec/lib/banzai/filter/blockquote_fence_filter_spec.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe Banzai::Filter::BlockquoteFenceFilter, lib: true do
|
||||
include FilterSpecHelper
|
||||
|
||||
it 'convers blockquote fences to blockquote lines' do
|
||||
content = File.read(Rails.root.join('spec/fixtures/blockquote_fence_before.md'))
|
||||
expected = File.read(Rails.root.join('spec/fixtures/blockquote_fence_after.md'))
|
||||
|
||||
output = filter(content)
|
||||
|
||||
expect(output).to eq(expected)
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue