Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
350be558
Commit
350be558
authored
Dec 09, 2021
by
Brett Walker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add default_enabled: :yaml
to calls of Feature.enabled?(:use_cmark_renderer)
parent
9fa609c7
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
37 additions
and
37 deletions
+37
-37
lib/banzai/filter/footnote_filter.rb
lib/banzai/filter/footnote_filter.rb
+7
-7
lib/banzai/filter/markdown_engines/common_mark.rb
lib/banzai/filter/markdown_engines/common_mark.rb
+4
-4
lib/banzai/filter/markdown_post_escape_filter.rb
lib/banzai/filter/markdown_post_escape_filter.rb
+1
-1
lib/banzai/filter/plantuml_filter.rb
lib/banzai/filter/plantuml_filter.rb
+1
-1
lib/banzai/filter/sanitization_filter.rb
lib/banzai/filter/sanitization_filter.rb
+2
-2
lib/banzai/filter/syntax_highlight_filter.rb
lib/banzai/filter/syntax_highlight_filter.rb
+2
-2
lib/gitlab/asciidoc/syntax_highlighter/html_pipeline_adapter.rb
...tlab/asciidoc/syntax_highlighter/html_pipeline_adapter.rb
+1
-1
spec/lib/banzai/filter/markdown_filter_spec.rb
spec/lib/banzai/filter/markdown_filter_spec.rb
+4
-4
spec/lib/banzai/filter/plantuml_filter_spec.rb
spec/lib/banzai/filter/plantuml_filter_spec.rb
+3
-3
spec/lib/banzai/filter/syntax_highlight_filter_spec.rb
spec/lib/banzai/filter/syntax_highlight_filter_spec.rb
+9
-9
spec/lib/banzai/pipeline/plain_markdown_pipeline_spec.rb
spec/lib/banzai/pipeline/plain_markdown_pipeline_spec.rb
+1
-1
spec/lib/gitlab/asciidoc_spec.rb
spec/lib/gitlab/asciidoc_spec.rb
+1
-1
spec/support/helpers/stub_gitlab_calls.rb
spec/support/helpers/stub_gitlab_calls.rb
+1
-1
No files found.
lib/banzai/filter/footnote_filter.rb
View file @
350be558
...
@@ -37,7 +37,7 @@ module Banzai
...
@@ -37,7 +37,7 @@ module Banzai
XPATH_SECTION_OLD
=
Gitlab
::
Utils
::
Nokogiri
.
css_to_xpath
(
CSS_SECTION_OLD
).
freeze
XPATH_SECTION_OLD
=
Gitlab
::
Utils
::
Nokogiri
.
css_to_xpath
(
CSS_SECTION_OLD
).
freeze
def
call
def
call
if
Feature
.
enabled?
(
:use_cmark_renderer
)
if
Feature
.
enabled?
(
:use_cmark_renderer
,
default_enabled: :yaml
)
# Sanitization stripped off the section class - add it back in
# Sanitization stripped off the section class - add it back in
return
doc
unless
section_node
=
doc
.
at_xpath
(
XPATH_SECTION
)
return
doc
unless
section_node
=
doc
.
at_xpath
(
XPATH_SECTION
)
...
@@ -52,26 +52,26 @@ module Banzai
...
@@ -52,26 +52,26 @@ module Banzai
rand_suffix
=
"-
#{
random_number
}
"
rand_suffix
=
"-
#{
random_number
}
"
modified_footnotes
=
{}
modified_footnotes
=
{}
xpath_footnote
=
if
Feature
.
enabled?
(
:use_cmark_renderer
)
xpath_footnote
=
if
Feature
.
enabled?
(
:use_cmark_renderer
,
default_enabled: :yaml
)
XPATH_FOOTNOTE
XPATH_FOOTNOTE
else
else
Gitlab
::
Utils
::
Nokogiri
.
css_to_xpath
(
'sup > a[id]'
)
Gitlab
::
Utils
::
Nokogiri
.
css_to_xpath
(
'sup > a[id]'
)
end
end
doc
.
xpath
(
xpath_footnote
).
each
do
|
link_node
|
doc
.
xpath
(
xpath_footnote
).
each
do
|
link_node
|
if
Feature
.
enabled?
(
:use_cmark_renderer
)
if
Feature
.
enabled?
(
:use_cmark_renderer
,
default_enabled: :yaml
)
ref_num
=
link_node
[
:id
].
delete_prefix
(
FOOTNOTE_LINK_ID_PREFIX
)
ref_num
=
link_node
[
:id
].
delete_prefix
(
FOOTNOTE_LINK_ID_PREFIX
)
ref_num
.
gsub!
(
/[[:punct:]]/
,
'\\\\\&'
)
ref_num
.
gsub!
(
/[[:punct:]]/
,
'\\\\\&'
)
else
else
ref_num
=
link_node
[
:id
].
delete_prefix
(
FOOTNOTE_LINK_ID_PREFIX_OLD
)
ref_num
=
link_node
[
:id
].
delete_prefix
(
FOOTNOTE_LINK_ID_PREFIX_OLD
)
end
end
css
=
Feature
.
enabled?
(
:use_cmark_renderer
)
?
"section[data-footnotes] li[id=
#{
fn_id
(
ref_num
)
}
]"
:
"li[id=
#{
fn_id
(
ref_num
)
}
]"
css
=
Feature
.
enabled?
(
:use_cmark_renderer
,
default_enabled: :yaml
)
?
"section[data-footnotes] li[id=
#{
fn_id
(
ref_num
)
}
]"
:
"li[id=
#{
fn_id
(
ref_num
)
}
]"
node_xpath
=
Gitlab
::
Utils
::
Nokogiri
.
css_to_xpath
(
css
)
node_xpath
=
Gitlab
::
Utils
::
Nokogiri
.
css_to_xpath
(
css
)
footnote_node
=
doc
.
at_xpath
(
node_xpath
)
footnote_node
=
doc
.
at_xpath
(
node_xpath
)
if
footnote_node
||
modified_footnotes
[
ref_num
]
if
footnote_node
||
modified_footnotes
[
ref_num
]
next
if
Feature
.
disabled?
(
:use_cmark_renderer
)
&&
!
INTEGER_PATTERN
.
match?
(
ref_num
)
next
if
Feature
.
disabled?
(
:use_cmark_renderer
,
default_enabled: :yaml
)
&&
!
INTEGER_PATTERN
.
match?
(
ref_num
)
link_node
[
:href
]
+=
rand_suffix
link_node
[
:href
]
+=
rand_suffix
link_node
[
:id
]
+=
rand_suffix
link_node
[
:id
]
+=
rand_suffix
...
@@ -103,12 +103,12 @@ module Banzai
...
@@ -103,12 +103,12 @@ module Banzai
end
end
def
fn_id
(
num
)
def
fn_id
(
num
)
prefix
=
Feature
.
enabled?
(
:use_cmark_renderer
)
?
FOOTNOTE_ID_PREFIX
:
FOOTNOTE_ID_PREFIX_OLD
prefix
=
Feature
.
enabled?
(
:use_cmark_renderer
,
default_enabled: :yaml
)
?
FOOTNOTE_ID_PREFIX
:
FOOTNOTE_ID_PREFIX_OLD
"
#{
prefix
}#{
num
}
"
"
#{
prefix
}#{
num
}
"
end
end
def
fnref_id
(
num
)
def
fnref_id
(
num
)
prefix
=
Feature
.
enabled?
(
:use_cmark_renderer
)
?
FOOTNOTE_LINK_ID_PREFIX
:
FOOTNOTE_LINK_ID_PREFIX_OLD
prefix
=
Feature
.
enabled?
(
:use_cmark_renderer
,
default_enabled: :yaml
)
?
FOOTNOTE_LINK_ID_PREFIX
:
FOOTNOTE_LINK_ID_PREFIX_OLD
"
#{
prefix
}#{
num
}
"
"
#{
prefix
}#{
num
}
"
end
end
end
end
...
...
lib/banzai/filter/markdown_engines/common_mark.rb
View file @
350be558
...
@@ -42,11 +42,11 @@ module Banzai
...
@@ -42,11 +42,11 @@ module Banzai
def
initialize
(
context
)
def
initialize
(
context
)
@context
=
context
@context
=
context
@renderer
=
Banzai
::
Renderer
::
CommonMark
::
HTML
.
new
(
options:
render_options
)
if
Feature
.
disabled?
(
:use_cmark_renderer
)
@renderer
=
Banzai
::
Renderer
::
CommonMark
::
HTML
.
new
(
options:
render_options
)
if
Feature
.
disabled?
(
:use_cmark_renderer
,
default_enabled: :yaml
)
end
end
def
render
(
text
)
def
render
(
text
)
if
Feature
.
enabled?
(
:use_cmark_renderer
)
if
Feature
.
enabled?
(
:use_cmark_renderer
,
default_enabled: :yaml
)
CommonMarker
.
render_html
(
text
,
render_options
,
extensions
)
CommonMarker
.
render_html
(
text
,
render_options
,
extensions
)
else
else
doc
=
CommonMarker
.
render_doc
(
text
,
PARSE_OPTIONS
,
extensions
)
doc
=
CommonMarker
.
render_doc
(
text
,
PARSE_OPTIONS
,
extensions
)
...
@@ -58,7 +58,7 @@ module Banzai
...
@@ -58,7 +58,7 @@ module Banzai
private
private
def
extensions
def
extensions
if
Feature
.
enabled?
(
:use_cmark_renderer
)
if
Feature
.
enabled?
(
:use_cmark_renderer
,
default_enabled: :yaml
)
EXTENSIONS
EXTENSIONS
else
else
EXTENSIONS
+
[
EXTENSIONS
+
[
...
@@ -72,7 +72,7 @@ module Banzai
...
@@ -72,7 +72,7 @@ module Banzai
end
end
def
render_options_no_sourcepos
def
render_options_no_sourcepos
Feature
.
enabled?
(
:use_cmark_renderer
)
?
RENDER_OPTIONS_C
:
RENDER_OPTIONS_RUBY
Feature
.
enabled?
(
:use_cmark_renderer
,
default_enabled: :yaml
)
?
RENDER_OPTIONS_C
:
RENDER_OPTIONS_RUBY
end
end
def
render_options_sourcepos
def
render_options_sourcepos
...
...
lib/banzai/filter/markdown_post_escape_filter.rb
View file @
350be558
...
@@ -42,7 +42,7 @@ module Banzai
...
@@ -42,7 +42,7 @@ module Banzai
private
private
def
lang_tag
def
lang_tag
if
Feature
.
enabled?
(
:use_cmark_renderer
)
if
Feature
.
enabled?
(
:use_cmark_renderer
,
default_enabled: :yaml
)
Gitlab
::
Utils
::
Nokogiri
.
css_to_xpath
(
'pre'
)
Gitlab
::
Utils
::
Nokogiri
.
css_to_xpath
(
'pre'
)
else
else
Gitlab
::
Utils
::
Nokogiri
.
css_to_xpath
(
'code'
)
Gitlab
::
Utils
::
Nokogiri
.
css_to_xpath
(
'code'
)
...
...
lib/banzai/filter/plantuml_filter.rb
View file @
350be558
...
@@ -26,7 +26,7 @@ module Banzai
...
@@ -26,7 +26,7 @@ module Banzai
def
lang_tag
def
lang_tag
@lang_tag
||=
@lang_tag
||=
if
Feature
.
enabled?
(
:use_cmark_renderer
)
if
Feature
.
enabled?
(
:use_cmark_renderer
,
default_enabled: :yaml
)
Gitlab
::
Utils
::
Nokogiri
.
css_to_xpath
(
'pre[lang="plantuml"] > code'
).
freeze
Gitlab
::
Utils
::
Nokogiri
.
css_to_xpath
(
'pre[lang="plantuml"] > code'
).
freeze
else
else
Gitlab
::
Utils
::
Nokogiri
.
css_to_xpath
(
'pre > code[lang="plantuml"]'
).
freeze
Gitlab
::
Utils
::
Nokogiri
.
css_to_xpath
(
'pre > code[lang="plantuml"]'
).
freeze
...
...
lib/banzai/filter/sanitization_filter.rb
View file @
350be558
...
@@ -28,7 +28,7 @@ module Banzai
...
@@ -28,7 +28,7 @@ module Banzai
allowlist
[
:attributes
][
'li'
]
=
%w[id]
allowlist
[
:attributes
][
'li'
]
=
%w[id]
allowlist
[
:transformers
].
push
(
self
.
class
.
remove_non_footnote_ids
)
allowlist
[
:transformers
].
push
(
self
.
class
.
remove_non_footnote_ids
)
if
Feature
.
enabled?
(
:use_cmark_renderer
)
if
Feature
.
enabled?
(
:use_cmark_renderer
,
default_enabled: :yaml
)
# Allow section elements with data-footnotes attribute
# Allow section elements with data-footnotes attribute
allowlist
[
:elements
].
push
(
'section'
)
allowlist
[
:elements
].
push
(
'section'
)
allowlist
[
:attributes
][
'section'
]
=
%w(data-footnotes)
allowlist
[
:attributes
][
'section'
]
=
%w(data-footnotes)
...
@@ -61,7 +61,7 @@ module Banzai
...
@@ -61,7 +61,7 @@ module Banzai
return
unless
node
.
name
==
'a'
||
node
.
name
==
'li'
return
unless
node
.
name
==
'a'
||
node
.
name
==
'li'
return
unless
node
.
has_attribute?
(
'id'
)
return
unless
node
.
has_attribute?
(
'id'
)
if
Feature
.
enabled?
(
:use_cmark_renderer
)
if
Feature
.
enabled?
(
:use_cmark_renderer
,
default_enabled: :yaml
)
return
if
node
.
name
==
'a'
&&
node
[
'id'
]
=~
Banzai
::
Filter
::
FootnoteFilter
::
FOOTNOTE_LINK_REFERENCE_PATTERN
return
if
node
.
name
==
'a'
&&
node
[
'id'
]
=~
Banzai
::
Filter
::
FootnoteFilter
::
FOOTNOTE_LINK_REFERENCE_PATTERN
return
if
node
.
name
==
'li'
&&
node
[
'id'
]
=~
Banzai
::
Filter
::
FootnoteFilter
::
FOOTNOTE_LI_REFERENCE_PATTERN
return
if
node
.
name
==
'li'
&&
node
[
'id'
]
=~
Banzai
::
Filter
::
FootnoteFilter
::
FOOTNOTE_LI_REFERENCE_PATTERN
else
else
...
...
lib/banzai/filter/syntax_highlight_filter.rb
View file @
350be558
...
@@ -70,7 +70,7 @@ module Banzai
...
@@ -70,7 +70,7 @@ module Banzai
private
private
def
parse_lang_params
(
node
)
def
parse_lang_params
(
node
)
node
=
node
.
parent
if
Feature
.
enabled?
(
:use_cmark_renderer
)
node
=
node
.
parent
if
Feature
.
enabled?
(
:use_cmark_renderer
,
default_enabled: :yaml
)
# Commonmarker's FULL_INFO_STRING render option works with the space delimiter.
# Commonmarker's FULL_INFO_STRING render option works with the space delimiter.
# But the current behavior of GitLab's markdown renderer is different - it grabs everything as the single
# But the current behavior of GitLab's markdown renderer is different - it grabs everything as the single
...
@@ -92,7 +92,7 @@ module Banzai
...
@@ -92,7 +92,7 @@ module Banzai
language
,
language_params
=
language
.
split
(
LANG_PARAMS_DELIMITER
,
2
)
language
,
language_params
=
language
.
split
(
LANG_PARAMS_DELIMITER
,
2
)
if
Feature
.
enabled?
(
:use_cmark_renderer
)
if
Feature
.
enabled?
(
:use_cmark_renderer
,
default_enabled: :yaml
)
language_params
=
[
node
.
attr
(
'data-meta'
),
language_params
].
compact
.
join
(
' '
)
language_params
=
[
node
.
attr
(
'data-meta'
),
language_params
].
compact
.
join
(
' '
)
end
end
...
...
lib/gitlab/asciidoc/syntax_highlighter/html_pipeline_adapter.rb
View file @
350be558
...
@@ -7,7 +7,7 @@ module Gitlab
...
@@ -7,7 +7,7 @@ module Gitlab
register_for
'gitlab-html-pipeline'
register_for
'gitlab-html-pipeline'
def
format
(
node
,
lang
,
opts
)
def
format
(
node
,
lang
,
opts
)
if
Feature
.
enabled?
(
:use_cmark_renderer
)
if
Feature
.
enabled?
(
:use_cmark_renderer
,
default_enabled: :yaml
)
%(<pre #{lang ? %[lang="#{lang}"] : ''}><code>#{node.content}</code></pre>)
%(<pre #{lang ? %[lang="#{lang}"] : ''}><code>#{node.content}</code></pre>)
else
else
%(<pre><code #{lang ? %[ lang="#{lang}"] : ''}>#{node.content}</code></pre>)
%(<pre><code #{lang ? %[ lang="#{lang}"] : ''}>#{node.content}</code></pre>)
...
...
spec/lib/banzai/filter/markdown_filter_spec.rb
View file @
350be558
...
@@ -33,7 +33,7 @@ RSpec.describe Banzai::Filter::MarkdownFilter do
...
@@ -33,7 +33,7 @@ RSpec.describe Banzai::Filter::MarkdownFilter do
it
'adds language to lang attribute when specified'
do
it
'adds language to lang attribute when specified'
do
result
=
filter
(
"```html
\n
some code
\n
```"
,
no_sourcepos:
true
)
result
=
filter
(
"```html
\n
some code
\n
```"
,
no_sourcepos:
true
)
if
Feature
.
enabled?
(
:use_cmark_renderer
)
if
Feature
.
enabled?
(
:use_cmark_renderer
,
default_enabled: :yaml
)
expect
(
result
).
to
start_with
(
'<pre lang="html"><code>'
)
expect
(
result
).
to
start_with
(
'<pre lang="html"><code>'
)
else
else
expect
(
result
).
to
start_with
(
'<pre><code lang="html">'
)
expect
(
result
).
to
start_with
(
'<pre><code lang="html">'
)
...
@@ -49,7 +49,7 @@ RSpec.describe Banzai::Filter::MarkdownFilter do
...
@@ -49,7 +49,7 @@ RSpec.describe Banzai::Filter::MarkdownFilter do
it
'works with utf8 chars in language'
do
it
'works with utf8 chars in language'
do
result
=
filter
(
"```日
\n
some code
\n
```"
,
no_sourcepos:
true
)
result
=
filter
(
"```日
\n
some code
\n
```"
,
no_sourcepos:
true
)
if
Feature
.
enabled?
(
:use_cmark_renderer
)
if
Feature
.
enabled?
(
:use_cmark_renderer
,
default_enabled: :yaml
)
expect
(
result
).
to
start_with
(
'<pre lang="日"><code>'
)
expect
(
result
).
to
start_with
(
'<pre lang="日"><code>'
)
else
else
expect
(
result
).
to
start_with
(
'<pre><code lang="日">'
)
expect
(
result
).
to
start_with
(
'<pre><code lang="日">'
)
...
@@ -59,7 +59,7 @@ RSpec.describe Banzai::Filter::MarkdownFilter do
...
@@ -59,7 +59,7 @@ RSpec.describe Banzai::Filter::MarkdownFilter do
it
'works with additional language parameters'
do
it
'works with additional language parameters'
do
result
=
filter
(
"```ruby:red gem foo
\n
some code
\n
```"
,
no_sourcepos:
true
)
result
=
filter
(
"```ruby:red gem foo
\n
some code
\n
```"
,
no_sourcepos:
true
)
if
Feature
.
enabled?
(
:use_cmark_renderer
)
if
Feature
.
enabled?
(
:use_cmark_renderer
,
default_enabled: :yaml
)
expect
(
result
).
to
start_with
(
'<pre lang="ruby:red" data-meta="gem foo"><code>'
)
expect
(
result
).
to
start_with
(
'<pre lang="ruby:red" data-meta="gem foo"><code>'
)
else
else
expect
(
result
).
to
start_with
(
'<pre><code lang="ruby:red gem foo">'
)
expect
(
result
).
to
start_with
(
'<pre><code lang="ruby:red gem foo">'
)
...
@@ -102,7 +102,7 @@ RSpec.describe Banzai::Filter::MarkdownFilter do
...
@@ -102,7 +102,7 @@ RSpec.describe Banzai::Filter::MarkdownFilter do
expect
(
result
).
to
include
(
'<td>foot <sup'
)
expect
(
result
).
to
include
(
'<td>foot <sup'
)
if
Feature
.
enabled?
(
:use_cmark_renderer
)
if
Feature
.
enabled?
(
:use_cmark_renderer
,
default_enabled: :yaml
)
expect
(
result
).
to
include
(
'<section class="footnotes" data-footnotes>'
)
expect
(
result
).
to
include
(
'<section class="footnotes" data-footnotes>'
)
else
else
expect
(
result
).
to
include
(
'<section class="footnotes">'
)
expect
(
result
).
to
include
(
'<section class="footnotes">'
)
...
...
spec/lib/banzai/filter/plantuml_filter_spec.rb
View file @
350be558
...
@@ -9,7 +9,7 @@ RSpec.describe Banzai::Filter::PlantumlFilter do
...
@@ -9,7 +9,7 @@ RSpec.describe Banzai::Filter::PlantumlFilter do
it
'replaces plantuml pre tag with img tag'
do
it
'replaces plantuml pre tag with img tag'
do
stub_application_setting
(
plantuml_enabled:
true
,
plantuml_url:
"http://localhost:8080"
)
stub_application_setting
(
plantuml_enabled:
true
,
plantuml_url:
"http://localhost:8080"
)
input
=
if
Feature
.
enabled?
(
:use_cmark_renderer
)
input
=
if
Feature
.
enabled?
(
:use_cmark_renderer
,
default_enabled: :yaml
)
'<pre lang="plantuml"><code>Bob -> Sara : Hello</code></pre>'
'<pre lang="plantuml"><code>Bob -> Sara : Hello</code></pre>'
else
else
'<pre><code lang="plantuml">Bob -> Sara : Hello</code></pre>'
'<pre><code lang="plantuml">Bob -> Sara : Hello</code></pre>'
...
@@ -24,7 +24,7 @@ RSpec.describe Banzai::Filter::PlantumlFilter do
...
@@ -24,7 +24,7 @@ RSpec.describe Banzai::Filter::PlantumlFilter do
it
'does not replace plantuml pre tag with img tag if disabled'
do
it
'does not replace plantuml pre tag with img tag if disabled'
do
stub_application_setting
(
plantuml_enabled:
false
)
stub_application_setting
(
plantuml_enabled:
false
)
if
Feature
.
enabled?
(
:use_cmark_renderer
)
if
Feature
.
enabled?
(
:use_cmark_renderer
,
default_enabled: :yaml
)
input
=
'<pre lang="plantuml"><code>Bob -> Sara : Hello</code></pre>'
input
=
'<pre lang="plantuml"><code>Bob -> Sara : Hello</code></pre>'
output
=
'<pre lang="plantuml"><code>Bob -> Sara : Hello</code></pre>'
output
=
'<pre lang="plantuml"><code>Bob -> Sara : Hello</code></pre>'
else
else
...
@@ -40,7 +40,7 @@ RSpec.describe Banzai::Filter::PlantumlFilter do
...
@@ -40,7 +40,7 @@ RSpec.describe Banzai::Filter::PlantumlFilter do
it
'does not replace plantuml pre tag with img tag if url is invalid'
do
it
'does not replace plantuml pre tag with img tag if url is invalid'
do
stub_application_setting
(
plantuml_enabled:
true
,
plantuml_url:
"invalid"
)
stub_application_setting
(
plantuml_enabled:
true
,
plantuml_url:
"invalid"
)
input
=
if
Feature
.
enabled?
(
:use_cmark_renderer
)
input
=
if
Feature
.
enabled?
(
:use_cmark_renderer
,
default_enabled: :yaml
)
'<pre lang="plantuml"><code>Bob -> Sara : Hello</code></pre>'
'<pre lang="plantuml"><code>Bob -> Sara : Hello</code></pre>'
else
else
'<pre><code lang="plantuml">Bob -> Sara : Hello</code></pre>'
'<pre><code lang="plantuml">Bob -> Sara : Hello</code></pre>'
...
...
spec/lib/banzai/filter/syntax_highlight_filter_spec.rb
View file @
350be558
...
@@ -40,7 +40,7 @@ RSpec.describe Banzai::Filter::SyntaxHighlightFilter do
...
@@ -40,7 +40,7 @@ RSpec.describe Banzai::Filter::SyntaxHighlightFilter do
context
"when a valid language is specified"
do
context
"when a valid language is specified"
do
it
"highlights as that language"
do
it
"highlights as that language"
do
result
=
if
Feature
.
enabled?
(
:use_cmark_renderer
)
result
=
if
Feature
.
enabled?
(
:use_cmark_renderer
,
default_enabled: :yaml
)
filter
(
'<pre lang="ruby"><code>def fun end</code></pre>'
)
filter
(
'<pre lang="ruby"><code>def fun end</code></pre>'
)
else
else
filter
(
'<pre><code lang="ruby">def fun end</code></pre>'
)
filter
(
'<pre><code lang="ruby">def fun end</code></pre>'
)
...
@@ -54,7 +54,7 @@ RSpec.describe Banzai::Filter::SyntaxHighlightFilter do
...
@@ -54,7 +54,7 @@ RSpec.describe Banzai::Filter::SyntaxHighlightFilter do
context
"when an invalid language is specified"
do
context
"when an invalid language is specified"
do
it
"highlights as plaintext"
do
it
"highlights as plaintext"
do
result
=
if
Feature
.
enabled?
(
:use_cmark_renderer
)
result
=
if
Feature
.
enabled?
(
:use_cmark_renderer
,
default_enabled: :yaml
)
filter
(
'<pre lang="gnuplot"><code>This is a test</code></pre>'
)
filter
(
'<pre lang="gnuplot"><code>This is a test</code></pre>'
)
else
else
filter
(
'<pre><code lang="gnuplot">This is a test</code></pre>'
)
filter
(
'<pre><code lang="gnuplot">This is a test</code></pre>'
)
...
@@ -73,7 +73,7 @@ RSpec.describe Banzai::Filter::SyntaxHighlightFilter do
...
@@ -73,7 +73,7 @@ RSpec.describe Banzai::Filter::SyntaxHighlightFilter do
%w(math mermaid plantuml suggestion)
.
each
do
|
lang
|
%w(math mermaid plantuml suggestion)
.
each
do
|
lang
|
context
"when
#{
lang
}
is specified"
do
context
"when
#{
lang
}
is specified"
do
it
"highlights as plaintext but with the correct language attribute and class"
do
it
"highlights as plaintext but with the correct language attribute and class"
do
result
=
if
Feature
.
enabled?
(
:use_cmark_renderer
)
result
=
if
Feature
.
enabled?
(
:use_cmark_renderer
,
default_enabled: :yaml
)
filter
(
%{<pre lang="#{lang}"><code>This is a test</code></pre>}
)
filter
(
%{<pre lang="#{lang}"><code>This is a test</code></pre>}
)
else
else
filter
(
%{<pre><code lang="#{lang}">This is a test</code></pre>}
)
filter
(
%{<pre><code lang="#{lang}">This is a test</code></pre>}
)
...
@@ -89,7 +89,7 @@ RSpec.describe Banzai::Filter::SyntaxHighlightFilter do
...
@@ -89,7 +89,7 @@ RSpec.describe Banzai::Filter::SyntaxHighlightFilter do
let
(
:lang_params
)
{
'foo-bar-kux'
}
let
(
:lang_params
)
{
'foo-bar-kux'
}
let
(
:xss_lang
)
do
let
(
:xss_lang
)
do
if
Feature
.
enabled?
(
:use_cmark_renderer
)
if
Feature
.
enabled?
(
:use_cmark_renderer
,
default_enabled: :yaml
)
"
#{
lang
}
data-meta=
\"
foo-bar-kux
\"
<script>alert(1)</script>"
"
#{
lang
}
data-meta=
\"
foo-bar-kux
\"
<script>alert(1)</script>"
else
else
"
#{
lang
}#{
described_class
::
LANG_PARAMS_DELIMITER
}
<script>alert(1)</script>"
"
#{
lang
}#{
described_class
::
LANG_PARAMS_DELIMITER
}
<script>alert(1)</script>"
...
@@ -97,7 +97,7 @@ RSpec.describe Banzai::Filter::SyntaxHighlightFilter do
...
@@ -97,7 +97,7 @@ RSpec.describe Banzai::Filter::SyntaxHighlightFilter do
end
end
it
"includes data-lang-params tag with extra information"
do
it
"includes data-lang-params tag with extra information"
do
result
=
if
Feature
.
enabled?
(
:use_cmark_renderer
)
result
=
if
Feature
.
enabled?
(
:use_cmark_renderer
,
default_enabled: :yaml
)
filter
(
%{<pre lang="#{lang}" data-meta="#{lang_params}"><code>This is a test</code></pre>}
)
filter
(
%{<pre lang="#{lang}" data-meta="#{lang_params}"><code>This is a test</code></pre>}
)
else
else
filter
(
%{<pre><code lang="#{lang}#{delimiter}#{lang_params}">This is a test</code></pre>}
)
filter
(
%{<pre><code lang="#{lang}#{delimiter}#{lang_params}">This is a test</code></pre>}
)
...
@@ -108,7 +108,7 @@ RSpec.describe Banzai::Filter::SyntaxHighlightFilter do
...
@@ -108,7 +108,7 @@ RSpec.describe Banzai::Filter::SyntaxHighlightFilter do
include_examples
"XSS prevention"
,
lang
include_examples
"XSS prevention"
,
lang
if
Feature
.
enabled?
(
:use_cmark_renderer
)
if
Feature
.
enabled?
(
:use_cmark_renderer
,
default_enabled: :yaml
)
include_examples
"XSS prevention"
,
include_examples
"XSS prevention"
,
"
#{
lang
}
data-meta=
\"
foo-bar-kux
\"
<script>alert(1)</script>"
"
#{
lang
}
data-meta=
\"
foo-bar-kux
\"
<script>alert(1)</script>"
else
else
...
@@ -131,7 +131,7 @@ RSpec.describe Banzai::Filter::SyntaxHighlightFilter do
...
@@ -131,7 +131,7 @@ RSpec.describe Banzai::Filter::SyntaxHighlightFilter do
context
'when delimiter is space'
do
context
'when delimiter is space'
do
it
'delimits on the first appearance'
do
it
'delimits on the first appearance'
do
if
Feature
.
enabled?
(
:use_cmark_renderer
)
if
Feature
.
enabled?
(
:use_cmark_renderer
,
default_enabled: :yaml
)
result
=
filter
(
%{<pre lang="#{lang}" data-meta="#{lang_params} more-things"><code>This is a test</code></pre>}
)
result
=
filter
(
%{<pre lang="#{lang}" data-meta="#{lang_params} more-things"><code>This is a test</code></pre>}
)
expect
(
result
.
to_html
).
to
eq
(
expected_result
)
expect
(
result
.
to_html
).
to
eq
(
expected_result
)
...
@@ -147,7 +147,7 @@ RSpec.describe Banzai::Filter::SyntaxHighlightFilter do
...
@@ -147,7 +147,7 @@ RSpec.describe Banzai::Filter::SyntaxHighlightFilter do
it
'delimits on the first appearance'
do
it
'delimits on the first appearance'
do
result
=
filter
(
%{<pre lang="#{lang}#{delimiter}#{lang_params} more-things"><code>This is a test</code></pre>}
)
result
=
filter
(
%{<pre lang="#{lang}#{delimiter}#{lang_params} more-things"><code>This is a test</code></pre>}
)
if
Feature
.
enabled?
(
:use_cmark_renderer
)
if
Feature
.
enabled?
(
:use_cmark_renderer
,
default_enabled: :yaml
)
expect
(
result
.
to_html
).
to
eq
(
expected_result
)
expect
(
result
.
to_html
).
to
eq
(
expected_result
)
else
else
expect
(
result
.
to_html
).
to
eq
(
%{<pre class=\"code highlight js-syntax-highlight language-plaintext\" lang=\"plaintext\" v-pre=\"true\"><code><span id=\"LC1\" class=\"line\" lang=\"plaintext\">This is a test</span></code></pre>}
)
expect
(
result
.
to_html
).
to
eq
(
%{<pre class=\"code highlight js-syntax-highlight language-plaintext\" lang=\"plaintext\" v-pre=\"true\"><code><span id=\"LC1\" class=\"line\" lang=\"plaintext\">This is a test</span></code></pre>}
)
...
@@ -173,7 +173,7 @@ RSpec.describe Banzai::Filter::SyntaxHighlightFilter do
...
@@ -173,7 +173,7 @@ RSpec.describe Banzai::Filter::SyntaxHighlightFilter do
end
end
it
"highlights as plaintext"
do
it
"highlights as plaintext"
do
result
=
if
Feature
.
enabled?
(
:use_cmark_renderer
)
result
=
if
Feature
.
enabled?
(
:use_cmark_renderer
,
default_enabled: :yaml
)
filter
(
'<pre lang="ruby"><code>This is a test</code></pre>'
)
filter
(
'<pre lang="ruby"><code>This is a test</code></pre>'
)
else
else
filter
(
'<pre><code lang="ruby">This is a test</code></pre>'
)
filter
(
'<pre><code lang="ruby">This is a test</code></pre>'
)
...
...
spec/lib/banzai/pipeline/plain_markdown_pipeline_spec.rb
View file @
350be558
...
@@ -71,7 +71,7 @@ RSpec.describe Banzai::Pipeline::PlainMarkdownPipeline do
...
@@ -71,7 +71,7 @@ RSpec.describe Banzai::Pipeline::PlainMarkdownPipeline do
let
(
:markdown
)
{
%Q(``` foo
\\
@bar
\n
foo
\n
```)
}
let
(
:markdown
)
{
%Q(``` foo
\\
@bar
\n
foo
\n
```)
}
it
'renders correct html'
do
it
'renders correct html'
do
if
Feature
.
enabled?
(
:use_cmark_renderer
)
if
Feature
.
enabled?
(
:use_cmark_renderer
,
default_enabled: :yaml
)
correct_html_included
(
markdown
,
%Q(<pre data-sourcepos="1:1-3:3" lang="foo@bar"><code>foo
\n
</code></pre>)
)
correct_html_included
(
markdown
,
%Q(<pre data-sourcepos="1:1-3:3" lang="foo@bar"><code>foo
\n
</code></pre>)
)
else
else
correct_html_included
(
markdown
,
%Q(<code lang="foo@bar">foo
\n
</code>)
)
correct_html_included
(
markdown
,
%Q(<code lang="foo@bar">foo
\n
</code>)
)
...
...
spec/lib/gitlab/asciidoc_spec.rb
View file @
350be558
...
@@ -96,7 +96,7 @@ module Gitlab
...
@@ -96,7 +96,7 @@ module Gitlab
it
"does not convert dangerous fenced code with inline script into HTML"
do
it
"does not convert dangerous fenced code with inline script into HTML"
do
input
=
'```mypre"><script>alert(3)</script>'
input
=
'```mypre"><script>alert(3)</script>'
output
=
output
=
if
Feature
.
enabled?
(
:use_cmark_renderer
)
if
Feature
.
enabled?
(
:use_cmark_renderer
,
default_enabled: :yaml
)
"<div>
\n
<div>
\n
<pre class=
\"
code highlight js-syntax-highlight language-plaintext
\"
lang=
\"
plaintext
\"
v-pre=
\"
true
\"
><code></code></pre>
\n
</div>
\n
</div>"
"<div>
\n
<div>
\n
<pre class=
\"
code highlight js-syntax-highlight language-plaintext
\"
lang=
\"
plaintext
\"
v-pre=
\"
true
\"
><code></code></pre>
\n
</div>
\n
</div>"
else
else
"<div>
\n
<div>
\n
<pre class=
\"
code highlight js-syntax-highlight language-plaintext
\"
lang=
\"
plaintext
\"
v-pre=
\"
true
\"
><code><span id=
\"
LC1
\"
class=
\"
line
\"
lang=
\"
plaintext
\"
>
\"
></span></code></pre>
\n
</div>
\n
</div>"
"<div>
\n
<div>
\n
<pre class=
\"
code highlight js-syntax-highlight language-plaintext
\"
lang=
\"
plaintext
\"
v-pre=
\"
true
\"
><code><span id=
\"
LC1
\"
class=
\"
line
\"
lang=
\"
plaintext
\"
>
\"
></span></code></pre>
\n
</div>
\n
</div>"
...
...
spec/support/helpers/stub_gitlab_calls.rb
View file @
350be558
...
@@ -93,7 +93,7 @@ module StubGitlabCalls
...
@@ -93,7 +93,7 @@ module StubGitlabCalls
def
stub_commonmark_sourcepos_disabled
def
stub_commonmark_sourcepos_disabled
render_options
=
render_options
=
if
Feature
.
enabled?
(
:use_cmark_renderer
)
if
Feature
.
enabled?
(
:use_cmark_renderer
,
default_enabled: :yaml
)
Banzai
::
Filter
::
MarkdownEngines
::
CommonMark
::
RENDER_OPTIONS_C
Banzai
::
Filter
::
MarkdownEngines
::
CommonMark
::
RENDER_OPTIONS_C
else
else
Banzai
::
Filter
::
MarkdownEngines
::
CommonMark
::
RENDER_OPTIONS_RUBY
Banzai
::
Filter
::
MarkdownEngines
::
CommonMark
::
RENDER_OPTIONS_RUBY
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment