Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
efa630f00f6b
Commit
df9a992c
authored
Apr 16, 2015
by
Vinnie Okada
Browse files
Fix GFM extractions
Extract and re-insert links after sanitizing user markup.
parent
b8e559a4437e
Changes
1
Hide whitespace changes
Inline
Side-by-side
lib/gitlab/markdown.rb
View file @
efa630f0
...
...
@@ -60,21 +60,8 @@ def gfm_with_options(text, options = {}, project = @project, html_options = {})
@html_options
=
html_options
# Extract pre blocks so they are not altered
# from http://github.github.com/github-flavored-markdown/
text
.
gsub!
(
%r{<pre>.*?</pre>|<code>.*?</code>}m
)
{
|
match
|
extract_piece
(
match
)
}
# Extract links with probably parsable hrefs
text
.
gsub!
(
%r{<a.*?>.*?</a>}m
)
{
|
match
|
extract_piece
(
match
)
}
# Extract images with probably parsable src
text
.
gsub!
(
%r{<img.*?>}m
)
{
|
match
|
extract_piece
(
match
)
}
# TODO: add popups with additional information
# Insert pre block extractions
text
.
gsub!
(
/\{gfm-extraction-(\h{32})\}/
)
do
insert_piece
(
$1
)
end
# Used markdown pipelines in GitLab:
# GitlabEmojiFilter - performs emoji replacement.
# SanitizationFilter - remove unsafe HTML tags and attributes
...
...
@@ -118,8 +105,21 @@ def gfm_with_options(text, options = {}, project = @project, html_options = {})
text
=
result
[
:output
].
to_html
(
save_with:
saveoptions
)
# Extract pre blocks so they are not altered
# from http://github.github.com/github-flavored-markdown/
text
.
gsub!
(
%r{<pre>.*?</pre>|<code>.*?</code>}m
)
{
|
match
|
extract_piece
(
match
)
}
# Extract links with probably parsable hrefs
text
.
gsub!
(
%r{<a.*?>.*?</a>}m
)
{
|
match
|
extract_piece
(
match
)
}
# Extract images with probably parsable src
text
.
gsub!
(
%r{<img.*?>}m
)
{
|
match
|
extract_piece
(
match
)
}
text
=
parse
(
text
,
project
)
# Insert pre block extractions
text
.
gsub!
(
/\{gfm-extraction-(\h{32})\}/
)
do
insert_piece
(
$1
)
end
if
options
[
:parse_tasks
]
text
=
parse_tasks
(
text
)
end
...
...
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