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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
b9abf938
Commit
b9abf938
authored
Mar 30, 2016
by
connorshea
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Wrap images in discussions and wikis with a link to the image source using ImageLinkFilter.
Resolves #14411. See merge request !3464
parent
67136007
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
61 additions
and
2 deletions
+61
-2
CHANGELOG
CHANGELOG
+1
-0
app/assets/stylesheets/framework/typography.scss
app/assets/stylesheets/framework/typography.scss
+6
-0
features/steps/project/wiki.rb
features/steps/project/wiki.rb
+1
-1
lib/banzai/filter/image_link_filter.rb
lib/banzai/filter/image_link_filter.rb
+27
-0
lib/banzai/pipeline/gfm_pipeline.rb
lib/banzai/pipeline/gfm_pipeline.rb
+1
-0
spec/features/atom/users_spec.rb
spec/features/atom/users_spec.rb
+1
-1
spec/lib/banzai/filter/image_link_filter_spec.rb
spec/lib/banzai/filter/image_link_filter_spec.rb
+24
-0
No files found.
CHANGELOG
View file @
b9abf938
Please view this file on the master branch, on stable branches it's out of date.
Please view this file on the master branch, on stable branches it's out of date.
v 8.7.0 (unreleased)
v 8.7.0 (unreleased)
- All images in discussions and wikis now link to their source files !3464 (Connor Shea).
- Improved Markdown rendering performance !3389 (Yorick Peterse)
- Improved Markdown rendering performance !3389 (Yorick Peterse)
- Don't attempt to look up an avatar in repo if repo directory does not exist (Stan hu)
- Don't attempt to look up an avatar in repo if repo directory does not exist (Stan hu)
- Preserve time notes/comments have been updated at when moving issue
- Preserve time notes/comments have been updated at when moving issue
...
...
app/assets/stylesheets/framework/typography.scss
View file @
b9abf938
...
@@ -138,6 +138,12 @@
...
@@ -138,6 +138,12 @@
}
}
}
}
a
.no-attachment-icon
{
&
:before
{
display
:
none
;
}
}
/* Link to current header. */
/* Link to current header. */
h1
,
h2
,
h3
,
h4
,
h5
,
h6
{
h1
,
h2
,
h3
,
h4
,
h5
,
h6
{
position
:
relative
;
position
:
relative
;
...
...
features/steps/project/wiki.rb
View file @
b9abf938
...
@@ -85,7 +85,7 @@ class Spinach::Features::ProjectWiki < Spinach::FeatureSteps
...
@@ -85,7 +85,7 @@ class Spinach::Features::ProjectWiki < Spinach::FeatureSteps
end
end
step
'I have an existing Wiki page with images linked on page'
do
step
'I have an existing Wiki page with images linked on page'
do
wiki
.
create_page
(
"pictures"
,
"Look at this [image](image.jpg)
\n\n
![
image
](image.jpg)"
,
:markdown
,
"first commit"
)
wiki
.
create_page
(
"pictures"
,
"Look at this [image](image.jpg)
\n\n
![
alt text
](image.jpg)"
,
:markdown
,
"first commit"
)
@wiki_page
=
wiki
.
find_page
(
"pictures"
)
@wiki_page
=
wiki
.
find_page
(
"pictures"
)
end
end
...
...
lib/banzai/filter/image_link_filter.rb
0 → 100644
View file @
b9abf938
module
Banzai
module
Filter
# HTML filter that wraps links around inline images.
class
ImageLinkFilter
<
HTML
::
Pipeline
::
Filter
# Find every image that isn't already wrapped in an `a` tag, create
# a new node (a link to the image source), copy the image as a child
# of the anchor, and then replace the img with the link-wrapped version.
def
call
doc
.
xpath
(
'descendant-or-self::img[not(ancestor::a)]'
).
each
do
|
img
|
link
=
doc
.
document
.
create_element
(
'a'
,
class:
'no-attachment-icon'
,
href:
img
[
'src'
],
target:
'_blank'
)
link
.
children
=
img
.
clone
img
.
replace
(
link
)
end
doc
end
end
end
end
lib/banzai/pipeline/gfm_pipeline.rb
View file @
b9abf938
...
@@ -7,6 +7,7 @@ module Banzai
...
@@ -7,6 +7,7 @@ module Banzai
Filter
::
SanitizationFilter
,
Filter
::
SanitizationFilter
,
Filter
::
UploadLinkFilter
,
Filter
::
UploadLinkFilter
,
Filter
::
ImageLinkFilter
,
Filter
::
EmojiFilter
,
Filter
::
EmojiFilter
,
Filter
::
TableOfContentsFilter
,
Filter
::
TableOfContentsFilter
,
Filter
::
AutolinkFilter
,
Filter
::
AutolinkFilter
,
...
...
spec/features/atom/users_spec.rb
View file @
b9abf938
...
@@ -61,7 +61,7 @@ describe "User Feed", feature: true do
...
@@ -61,7 +61,7 @@ describe "User Feed", feature: true do
end
end
it
'should have XHTML summaries in merge request descriptions'
do
it
'should have XHTML summaries in merge request descriptions'
do
expect
(
body
).
to
match
/Here is the fix: <
img[^>]*\/
>/
expect
(
body
).
to
match
/Here is the fix: <
a[^>]*><img[^>]*\/><\/a
>/
end
end
end
end
end
end
...
...
spec/lib/banzai/filter/image_link_filter_spec.rb
0 → 100644
View file @
b9abf938
require
'spec_helper'
describe
Banzai
::
Filter
::
ImageLinkFilter
,
lib:
true
do
include
FilterSpecHelper
def
image
(
path
)
%(<img src="#{path}" />)
end
it
'wraps the image with a link to the image src'
do
doc
=
filter
(
image
(
'/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg'
))
expect
(
doc
.
at_css
(
'img'
)[
'src'
]).
to
eq
doc
.
at_css
(
'a'
)[
'href'
]
end
it
'does not wrap a duplicate link'
do
exp
=
act
=
%q(<a href="/whatever">#{image('/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg')}</a>)
expect
(
filter
(
act
).
to_html
).
to
eq
exp
end
it
'works with external images'
do
doc
=
filter
(
image
(
'https://i.imgur.com/DfssX9C.jpg'
))
expect
(
doc
.
at_css
(
'img'
)[
'src'
]).
to
eq
doc
.
at_css
(
'a'
)[
'href'
]
end
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