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
28266d9d
Commit
28266d9d
authored
Apr 01, 2016
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added WikiLinkFilter
parent
7d56d592
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
2 deletions
+56
-2
lib/banzai/filter/wiki_link_filter.rb
lib/banzai/filter/wiki_link_filter.rb
+52
-0
lib/banzai/pipeline/wiki_pipeline.rb
lib/banzai/pipeline/wiki_pipeline.rb
+4
-2
No files found.
lib/banzai/filter/wiki_link_filter.rb
0 → 100644
View file @
28266d9d
require
'uri'
module
Banzai
module
Filter
# HTML filter that "fixes" relative links to files in a repository.
#
# Context options:
# :project_wiki
class
WikiLinkFilter
<
HTML
::
Pipeline
::
Filter
def
call
return
doc
unless
project_wiki?
doc
.
search
(
'a:not(.gfm)'
).
each
do
|
el
|
process_link_attr
el
.
attribute
(
'href'
)
end
doc
end
protected
def
project_wiki?
!
context
[
:project_wiki
].
nil?
end
def
process_link_attr
(
html_attr
)
return
if
html_attr
.
blank?
uri
=
URI
(
html_attr
.
value
)
if
uri
.
relative?
&&
uri
.
path
.
present?
&&
uri
.
path
html_attr
.
value
=
rebuild_wiki_uri
(
uri
).
to_s
end
rescue
URI
::
Error
# noop
end
def
rebuild_wiki_uri
(
uri
)
uri
.
path
=
::
File
.
join
(
project_wiki_base_path
,
uri
.
path
)
uri
end
def
project_wiki
context
[
:project_wiki
]
end
def
project_wiki_base_path
project_wiki
&&
project_wiki
.
wiki_base_path
end
end
end
end
lib/banzai/pipeline/wiki_pipeline.rb
View file @
28266d9d
...
@@ -2,8 +2,10 @@ module Banzai
...
@@ -2,8 +2,10 @@ module Banzai
module
Pipeline
module
Pipeline
class
WikiPipeline
<
FullPipeline
class
WikiPipeline
<
FullPipeline
def
self
.
filters
def
self
.
filters
@filters
||=
super
.
insert_after
(
Filter
::
TableOfContentsFilter
,
@filters
||=
begin
Filter
::
GollumTagsFilter
)
super
.
insert_after
(
Filter
::
TableOfContentsFilter
,
Filter
::
GollumTagsFilter
)
.
insert_after
(
Filter
::
GollumTagsFilter
,
Filter
::
WikiLinkFilter
)
end
end
end
end
end
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