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
c873d35b
Commit
c873d35b
authored
Mar 10, 2021
by
Brett Walker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure all GitLab reference chars are checked
and add some documentation
parent
36b166df
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
5 deletions
+24
-5
doc/user/markdown.md
doc/user/markdown.md
+2
-1
lib/banzai/filter/markdown_pre_escape_filter.rb
lib/banzai/filter/markdown_pre_escape_filter.rb
+3
-2
spec/lib/banzai/pipeline/plain_markdown_pipeline_spec.rb
spec/lib/banzai/pipeline/plain_markdown_pipeline_spec.rb
+19
-2
No files found.
doc/user/markdown.md
View file @
c873d35b
...
...
@@ -462,7 +462,8 @@ GitLab Flavored Markdown recognizes the following:
For example, referencing an issue by using `#123` formats the output as a link
to issue number 123 with text `#123`. Likewise, a link to issue number 123 is
recognized and formatted with text `#123`.
recognized and formatted with text `#123`. If you don't want `#123` to link to an issue,
add a leading backslash `\#123`.
In addition to this, links to some objects are also recognized and formatted. Some examples of these are:
...
...
lib/banzai/filter/markdown_pre_escape_filter.rb
View file @
c873d35b
...
...
@@ -25,8 +25,9 @@ module Banzai
# does the conversion into span tags.
class
MarkdownPreEscapeFilter
<
HTML
::
Pipeline
::
TextFilter
# We just need to target those that are special GitLab references
ASCII_PUNCTUATION
=
%r{([
\\
][@#!$&~%^])}
.
freeze
LITERAL_KEYWORD
=
'cmliteral'
REFERENCE_CHARACTERS
=
'@#!$&~%^'
ASCII_PUNCTUATION
=
%r{([
\\
][
#{
REFERENCE_CHARACTERS
}
])}
.
freeze
LITERAL_KEYWORD
=
'cmliteral'
def
call
return
@text
unless
Feature
.
enabled?
(
:honor_escaped_markdown
,
context
[
:group
]
||
context
[
:project
]
&
.
group
)
...
...
spec/lib/banzai/pipeline/plain_markdown_pipeline_spec.rb
View file @
c873d35b
...
...
@@ -33,8 +33,11 @@ RSpec.describe Banzai::Pipeline::PlainMarkdownPipeline do
describe
'CommonMark tests'
,
:aggregate_failures
do
it
'converts all reference punctuation to literals'
do
markdown
=
%q(\@
\#
\!\$\&\~\%\^)
punctuation
=
%w(@ # ! $ ~ % ^)
reference_chars
=
Banzai
::
Filter
::
MarkdownPreEscapeFilter
::
REFERENCE_CHARACTERS
markdown
=
reference_chars
.
split
(
''
).
map
{
|
char
|
char
.
prepend
(
"
\\
"
)
}.
join
punctuation
=
Banzai
::
Filter
::
MarkdownPreEscapeFilter
::
REFERENCE_CHARACTERS
.
split
(
''
)
punctuation
=
punctuation
.
delete_if
{
|
char
|
char
==
'&'
}
punctuation
<<
'&'
result
=
described_class
.
call
(
markdown
,
project:
project
)
output
=
result
[
:output
].
to_html
...
...
@@ -43,6 +46,20 @@ RSpec.describe Banzai::Pipeline::PlainMarkdownPipeline do
expect
(
result
[
:escaped_literals
]).
to
be_truthy
end
it
'ensure we handle all the GitLab reference characters'
do
reference_chars
=
ObjectSpace
.
each_object
(
Class
).
map
do
|
klass
|
next
unless
klass
.
included_modules
.
include?
(
Referable
)
next
unless
klass
.
respond_to?
(
:reference_prefix
)
next
unless
klass
.
reference_prefix
.
length
==
1
klass
.
reference_prefix
end
.
compact
reference_chars
.
all?
do
|
char
|
Banzai
::
Filter
::
MarkdownPreEscapeFilter
::
REFERENCE_CHARACTERS
.
include?
(
char
)
end
end
it
'does not convert non-reference punctuation to spans'
do
markdown
=
%q(\"\'\*\+\,\-\.\/\:\;\<\=\>\?\[\]\_\`\{\|\})
+
%q[\(\)
\\\\
]
...
...
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