gollum-lib 3.0.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of gollum-lib might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/README.md +7 -7
- data/gollum-lib.gemspec +17 -15
- data/lib/gollum-lib.rb +10 -11
- data/lib/gollum-lib/blob_entry.rb +4 -4
- data/lib/gollum-lib/committer.rb +7 -7
- data/lib/gollum-lib/file.rb +3 -3
- data/lib/gollum-lib/filter/code.rb +5 -1
- data/lib/gollum-lib/filter/macro.rb +56 -0
- data/lib/gollum-lib/filter/tags.rb +70 -43
- data/lib/gollum-lib/filter/toc.rb +98 -47
- data/lib/gollum-lib/filter/wsd.rb +1 -1
- data/lib/gollum-lib/git_access.rb +6 -12
- data/lib/gollum-lib/macro.rb +43 -0
- data/lib/gollum-lib/macro/all_pages.rb +11 -0
- data/lib/gollum-lib/markup.rb +5 -1
- data/lib/gollum-lib/page.rb +25 -25
- data/lib/gollum-lib/wiki.rb +61 -42
- metadata +30 -28
- data/lib/gollum-lib/grit_ext.rb +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c4e3d8ea8a629bdd6bc0a8b13dc901366811de7
|
4
|
+
data.tar.gz: b894bed5617bedddbfaed91003cf82f50b9785c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ca45f261d3d0a22ea9686b682b380c3cb14cb878cd86dec20fb780ed600cedce4ac9352ab58439a5c19af21a07f90246bcc9330d4f8315b2c630b1bb5efc8c5
|
7
|
+
data.tar.gz: 56b810b3f1384448377ea7c109e1f708269f072827ac19d139638141be8fd01d8a9f3a54aae52e3a6eae295a8aacae52ebaf0115887dba9358e47c3e03d2d771
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
gollum lib -- A wiki built on top of Git
|
2
2
|
========================================
|
3
3
|
|
4
|
-
[](http://badge.fury.io/rb/gollum-lib)
|
5
|
+
[](https://travis-ci.org/gollum/gollum-lib)
|
6
|
+
[](https://gemnasium.com/gollum/gollum-lib)
|
7
7
|
|
8
8
|
## DESCRIPTION
|
9
9
|
|
@@ -43,7 +43,7 @@ In order to use the various formats that Gollum supports, you will need to
|
|
43
43
|
separately install the necessary dependencies for each format. You only need
|
44
44
|
to install the dependencies for the formats that you plan to use.
|
45
45
|
|
46
|
-
* [
|
46
|
+
* [AsciiDoc](http://www.methods.co.nz/asciidoc/) -- `gem install asciidoctor`
|
47
47
|
* [Creole](http://wikicreole.org/) -- `gem install creole`
|
48
48
|
* [Markdown](http://daringfireball.net/projects/markdown/) -- `gem install redcarpet`
|
49
49
|
* [GitHub Flavored Markdown](https://help.github.com/articles/github-flavored-markdown) -- `gem install github-markdown`
|
@@ -105,7 +105,7 @@ page.format
|
|
105
105
|
# => :markdown
|
106
106
|
|
107
107
|
vsn = page.version
|
108
|
-
# => <
|
108
|
+
# => <Gollum::Git::Commit>
|
109
109
|
|
110
110
|
vsn.id
|
111
111
|
# => '3ca43e12377ea1e32ea5c9ce5992ec8bf266e3e5'
|
@@ -129,7 +129,7 @@ Get a list of versions for a given page:
|
|
129
129
|
|
130
130
|
```ruby
|
131
131
|
vsns = wiki.page('page-name').versions
|
132
|
-
# => [<
|
132
|
+
# => [<Gollum::Git::Commit, <Gollum::Git::Commit, <Gollum::Git::Commit>]
|
133
133
|
|
134
134
|
vsns.first.id
|
135
135
|
# => '3ca43e12377ea1e32ea5c9ce5992ec8bf266e3e5'
|
@@ -154,7 +154,7 @@ file.raw_data
|
|
154
154
|
# => "alert('hello');"
|
155
155
|
|
156
156
|
file.version
|
157
|
-
# => <
|
157
|
+
# => <Gollum::Git::Commit>
|
158
158
|
```
|
159
159
|
|
160
160
|
Get a specific version of a given static file:
|
data/gollum-lib.gemspec
CHANGED
@@ -5,8 +5,8 @@ Gem::Specification.new do |s|
|
|
5
5
|
s.required_ruby_version = '>= 1.9'
|
6
6
|
|
7
7
|
s.name = 'gollum-lib'
|
8
|
-
s.version = '
|
9
|
-
s.date = '2014-
|
8
|
+
s.version = '4.0.0'
|
9
|
+
s.date = '2014-11-26'
|
10
10
|
s.rubyforge_project = 'gollum-lib'
|
11
11
|
s.license = 'MIT'
|
12
12
|
|
@@ -22,33 +22,33 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.rdoc_options = ['--charset=UTF-8']
|
23
23
|
s.extra_rdoc_files = %w[README.md LICENSE]
|
24
24
|
|
25
|
-
s.add_dependency '
|
26
|
-
s.add_dependency 'rouge', '~> 1.
|
27
|
-
s.add_dependency 'nokogiri', '~> 1.6.
|
25
|
+
s.add_dependency 'gollum-grit_adapter', '~> 0.1.0'
|
26
|
+
s.add_dependency 'rouge', '~> 1.7.4'
|
27
|
+
s.add_dependency 'nokogiri', '~> 1.6.4'
|
28
28
|
s.add_dependency 'stringex', '~> 2.5.1'
|
29
29
|
s.add_dependency 'sanitize', '~> 2.1.0'
|
30
|
-
s.add_dependency 'github-markup', '~> 1.1
|
30
|
+
s.add_dependency 'github-markup', '~> 1.3.1'
|
31
31
|
|
32
|
-
s.add_development_dependency 'org-ruby', '~> 0.9.
|
33
|
-
s.add_development_dependency 'github-markdown', '~> 0.6.
|
32
|
+
s.add_development_dependency 'org-ruby', '~> 0.9.9'
|
33
|
+
s.add_development_dependency 'github-markdown', '~> 0.6.7'
|
34
34
|
s.add_development_dependency 'RedCloth', '~> 4.2.9'
|
35
|
-
s.add_development_dependency 'mocha', '~> 1.
|
35
|
+
s.add_development_dependency 'mocha', '~> 1.1.0'
|
36
36
|
s.add_development_dependency 'shoulda', '~> 3.5.0'
|
37
37
|
s.add_development_dependency 'wikicloth', '~> 0.8.1'
|
38
|
-
s.add_development_dependency 'rake', '~> 10.
|
39
|
-
s.add_development_dependency 'pry', '~> 0.
|
38
|
+
s.add_development_dependency 'rake', '~> 10.4.0'
|
39
|
+
s.add_development_dependency 'pry', '~> 0.10.1'
|
40
40
|
# required by pry
|
41
41
|
s.add_development_dependency 'rb-readline', '~> 0.5.1'
|
42
42
|
# updating minitest-reporters requires a new minitest which fails with gollum's tests.
|
43
43
|
s.add_development_dependency 'minitest-reporters', '~> 0.14.16'
|
44
44
|
s.add_development_dependency 'nokogiri-diff', '~> 0.2.0'
|
45
45
|
# required by guard
|
46
|
-
s.add_development_dependency 'guard', '~> 2.
|
47
|
-
s.add_development_dependency 'guard-minitest', '~> 2.2
|
46
|
+
s.add_development_dependency 'guard', '~> 2.8.2'
|
47
|
+
s.add_development_dependency 'guard-minitest', '~> 2.3.2'
|
48
48
|
s.add_development_dependency 'rb-inotify', '~> 0.9.3'
|
49
49
|
s.add_development_dependency 'rb-fsevent', '~> 0.9.4'
|
50
50
|
s.add_development_dependency 'rb-fchange', '~> 0.0.6'
|
51
|
-
s.add_development_dependency 'twitter_cldr', '~>
|
51
|
+
s.add_development_dependency 'twitter_cldr', '~> 3.1.0'
|
52
52
|
# = MANIFEST =
|
53
53
|
s.files = %w[
|
54
54
|
Gemfile
|
@@ -65,6 +65,7 @@ Gem::Specification.new do |s|
|
|
65
65
|
lib/gollum-lib/file_view.rb
|
66
66
|
lib/gollum-lib/filter.rb
|
67
67
|
lib/gollum-lib/filter/code.rb
|
68
|
+
lib/gollum-lib/filter/macro.rb
|
68
69
|
lib/gollum-lib/filter/metadata.rb
|
69
70
|
lib/gollum-lib/filter/plain_text.rb
|
70
71
|
lib/gollum-lib/filter/remote_code.rb
|
@@ -75,9 +76,10 @@ Gem::Specification.new do |s|
|
|
75
76
|
lib/gollum-lib/filter/wsd.rb
|
76
77
|
lib/gollum-lib/git_access.rb
|
77
78
|
lib/gollum-lib/gitcode.rb
|
78
|
-
lib/gollum-lib/grit_ext.rb
|
79
79
|
lib/gollum-lib/helpers.rb
|
80
80
|
lib/gollum-lib/hook.rb
|
81
|
+
lib/gollum-lib/macro.rb
|
82
|
+
lib/gollum-lib/macro/all_pages.rb
|
81
83
|
lib/gollum-lib/markup.rb
|
82
84
|
lib/gollum-lib/markups.rb
|
83
85
|
lib/gollum-lib/page.rb
|
data/lib/gollum-lib.rb
CHANGED
@@ -4,9 +4,15 @@ require 'digest/md5'
|
|
4
4
|
require 'digest/sha1'
|
5
5
|
require 'ostruct'
|
6
6
|
|
7
|
+
DEFAULT_ADAPTER = 'grit_adapter'
|
8
|
+
|
9
|
+
if defined?(Gollum::GIT_ADAPTER)
|
10
|
+
require "#{Gollum::GIT_ADAPTER.downcase}_adapter"
|
11
|
+
else
|
12
|
+
require DEFAULT_ADAPTER
|
13
|
+
end
|
14
|
+
|
7
15
|
# external
|
8
|
-
require 'grit'
|
9
|
-
require File.expand_path('../gollum-lib/grit_ext', __FILE__)
|
10
16
|
require 'github/markup'
|
11
17
|
require 'sanitize'
|
12
18
|
|
@@ -18,6 +24,7 @@ require File.expand_path('../gollum-lib/pagination', __FILE__)
|
|
18
24
|
require File.expand_path('../gollum-lib/blob_entry', __FILE__)
|
19
25
|
require File.expand_path('../gollum-lib/wiki', __FILE__)
|
20
26
|
require File.expand_path('../gollum-lib/page', __FILE__)
|
27
|
+
require File.expand_path('../gollum-lib/macro', __FILE__)
|
21
28
|
require File.expand_path('../gollum-lib/file', __FILE__)
|
22
29
|
require File.expand_path('../gollum-lib/file_view', __FILE__)
|
23
30
|
require File.expand_path('../gollum-lib/markup', __FILE__)
|
@@ -31,21 +38,13 @@ $KCODE = 'U' if RUBY_VERSION[0, 3] == '1.8'
|
|
31
38
|
|
32
39
|
module Gollum
|
33
40
|
module Lib
|
34
|
-
VERSION = '
|
41
|
+
VERSION = '4.0.0'
|
35
42
|
end
|
36
43
|
|
37
44
|
def self.assets_path
|
38
45
|
::File.expand_path('gollum/frontend/public', ::File.dirname(__FILE__))
|
39
46
|
end
|
40
47
|
|
41
|
-
def self.set_git_timeout(time)
|
42
|
-
Grit::Git.git_timeout = time
|
43
|
-
end
|
44
|
-
|
45
|
-
def self.set_git_max_filesize(size)
|
46
|
-
Grit::Git.git_max_size = size
|
47
|
-
end
|
48
|
-
|
49
48
|
class Error < StandardError; end
|
50
49
|
|
51
50
|
class DuplicatePageError < Error
|
@@ -31,13 +31,13 @@ module Gollum
|
|
31
31
|
@name ||= ::File.basename(@path)
|
32
32
|
end
|
33
33
|
|
34
|
-
# Gets a
|
34
|
+
# Gets a Gollum::Git::Blob instance for this blob.
|
35
35
|
#
|
36
|
-
# repo -
|
36
|
+
# repo - Gollum::Git::Repo instance for the Gollum::Git::Blob.
|
37
37
|
#
|
38
|
-
# Returns an unbaked
|
38
|
+
# Returns an unbaked Gollum::Git::Blob instance.
|
39
39
|
def blob(repo)
|
40
|
-
@blob ||=
|
40
|
+
@blob ||= Gollum::Git::Blob.create(repo,
|
41
41
|
:id => @sha, :name => name, :size => @size, :mode => @mode)
|
42
42
|
end
|
43
43
|
|
data/lib/gollum-lib/committer.rb
CHANGED
@@ -18,7 +18,7 @@ module Gollum
|
|
18
18
|
# :message - The String commit message.
|
19
19
|
# :name - The String author full name.
|
20
20
|
# :email - The String email address.
|
21
|
-
# :parent - Optional
|
21
|
+
# :parent - Optional Gollum::Git::Commit parent to this update.
|
22
22
|
# :tree - Optional String SHA of the tree to create the
|
23
23
|
# index from.
|
24
24
|
# :committer - Optional Gollum::Committer instance. If provided,
|
@@ -35,7 +35,7 @@ module Gollum
|
|
35
35
|
|
36
36
|
# Public: References the Git index for this commit.
|
37
37
|
#
|
38
|
-
# Returns a
|
38
|
+
# Returns a Gollum::Git::Index.
|
39
39
|
def index
|
40
40
|
@index ||= begin
|
41
41
|
idx = @wiki.repo.index
|
@@ -50,18 +50,18 @@ module Gollum
|
|
50
50
|
|
51
51
|
# Public: The committer for this commit.
|
52
52
|
#
|
53
|
-
# Returns a
|
53
|
+
# Returns a Gollum::Git::Actor.
|
54
54
|
def actor
|
55
55
|
@actor ||= begin
|
56
56
|
@options[:name] = @wiki.default_committer_name if @options[:name].to_s.empty?
|
57
57
|
@options[:email] = @wiki.default_committer_email if @options[:email].to_s.empty?
|
58
|
-
|
58
|
+
Gollum::Git::Actor.new(@options[:name], @options[:email])
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
62
|
# Public: The parent commits to this pending commit.
|
63
63
|
#
|
64
|
-
# Returns an array of
|
64
|
+
# Returns an array of Gollum::Git::Commit instances.
|
65
65
|
def parents
|
66
66
|
@parents ||= begin
|
67
67
|
arr = [@options[:parent] || @wiki.repo.commit(@wiki.ref)]
|
@@ -155,9 +155,9 @@ module Gollum
|
|
155
155
|
|
156
156
|
Dir.chdir(::File.join(@wiki.repo.path, '..')) do
|
157
157
|
if file_path_scheduled_for_deletion?(index.tree, path)
|
158
|
-
@wiki.repo.git.rm(
|
158
|
+
@wiki.repo.git.rm(path, :force => true)
|
159
159
|
else
|
160
|
-
@wiki.repo.git.checkout(
|
160
|
+
@wiki.repo.git.checkout(path, 'HEAD')
|
161
161
|
end
|
162
162
|
end
|
163
163
|
end
|
data/lib/gollum-lib/file.rb
CHANGED
@@ -73,7 +73,7 @@ module Gollum
|
|
73
73
|
return @on_disk_path
|
74
74
|
end
|
75
75
|
|
76
|
-
# Public: The
|
76
|
+
# Public: The Gollum::Git::Commit version of the file.
|
77
77
|
attr_accessor :version
|
78
78
|
|
79
79
|
# Public: The String path of the file.
|
@@ -86,7 +86,7 @@ module Gollum
|
|
86
86
|
|
87
87
|
# Populate the File with information from the Blob.
|
88
88
|
#
|
89
|
-
# blob - The
|
89
|
+
# blob - The Gollum::Git::Blob that contains the info.
|
90
90
|
# path - The String directory path of the file.
|
91
91
|
#
|
92
92
|
# Returns the populated Gollum::File.
|
@@ -139,7 +139,7 @@ module Gollum
|
|
139
139
|
def find(name, version, try_on_disk=false)
|
140
140
|
checked = name.downcase
|
141
141
|
map = @wiki.tree_map_for(version)
|
142
|
-
commit = version.is_a?(
|
142
|
+
commit = version.is_a?(Gollum::Git::Commit) ? version : @wiki.commit_for(version)
|
143
143
|
|
144
144
|
if entry = map.detect { |entry| entry.path.downcase == checked }
|
145
145
|
@path = name
|
@@ -85,6 +85,9 @@ class Gollum::Filter::Code < Gollum::Filter
|
|
85
85
|
end
|
86
86
|
else # Rouge
|
87
87
|
begin
|
88
|
+
# if `lang` was not defined then assume plaintext
|
89
|
+
# if `lang` is defined but cannot be found then wrap it and escape it
|
90
|
+
lang ||= 'plaintext'
|
88
91
|
if Rouge::Lexer.find(lang).nil?
|
89
92
|
lexer = Rouge::Lexers::PlainText.new
|
90
93
|
formatter = Rouge::Formatters::HTML.new(:wrap => false)
|
@@ -110,7 +113,8 @@ class Gollum::Filter::Code < Gollum::Filter
|
|
110
113
|
"<pre><code>#{CGI.escapeHTML(spec[:code])}</code></pre>"
|
111
114
|
end
|
112
115
|
end
|
113
|
-
|
116
|
+
# Removes paragraph tags surrounding <pre> blocks, see issue https://github.com/gollum/gollum-lib/issues/97
|
117
|
+
data.gsub!(/(<p>#{id}<\/p>|#{id})/) do
|
114
118
|
body
|
115
119
|
end
|
116
120
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# ~*~ encoding: utf-8 ~*~
|
2
|
+
|
3
|
+
# Replace specified tokens with dynamically generated content.
|
4
|
+
class Gollum::Filter::Macro < Gollum::Filter
|
5
|
+
def extract(data)
|
6
|
+
quoted_arg = %r{".*?"}
|
7
|
+
unquoted_arg = %r{[^,)]+}
|
8
|
+
named_arg = %r{[a-z0-9_]+=".*?"}
|
9
|
+
|
10
|
+
arg = %r{(?:#{quoted_arg}|#{unquoted_arg}|#{named_arg})}
|
11
|
+
arg_list = %r{(\s*|#{arg}(?:\s*,\s*#{arg})*)}
|
12
|
+
|
13
|
+
data.gsub(/\<\<\s*([A-Z][A-Za-z0-9]*)\s*\(#{arg_list}\)\s*\>\>/) do
|
14
|
+
id = Digest::SHA1.hexdigest($1 + $2)
|
15
|
+
macro = $1
|
16
|
+
argstr = $2
|
17
|
+
args = []
|
18
|
+
opts = {}
|
19
|
+
|
20
|
+
argstr.scan /,?\s*(#{arg})\s*/ do |arg|
|
21
|
+
# Stabstabstab
|
22
|
+
arg = arg.first
|
23
|
+
|
24
|
+
if arg =~ /^([a-z0-9_]+)="(.*?)"/
|
25
|
+
opts[$1] = $2
|
26
|
+
elsif arg =~ /^"(.*)"$/
|
27
|
+
args << $1
|
28
|
+
else
|
29
|
+
args << arg
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
args << opts unless opts.empty?
|
34
|
+
|
35
|
+
@map[id] = { :macro => macro, :args => args }
|
36
|
+
id
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def process(data)
|
41
|
+
@map.each do |id, spec|
|
42
|
+
macro = spec[:macro]
|
43
|
+
args = spec[:args]
|
44
|
+
|
45
|
+
data.gsub!(id) do
|
46
|
+
begin
|
47
|
+
Gollum::Macro.instance(macro, @markup.wiki, @markup.page).render(*args)
|
48
|
+
rescue StandardError => e
|
49
|
+
"!!!Macro Error: #{e.message}!!!"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
data
|
55
|
+
end
|
56
|
+
end
|
@@ -15,51 +15,53 @@ class Gollum::Filter::Tags < Gollum::Filter
|
|
15
15
|
parts = $2.split('][')
|
16
16
|
parts[0][0..4] = ""
|
17
17
|
link = "#{parts[1]}|#{parts[0].sub(/\.org/, '')}"
|
18
|
-
id =
|
19
|
-
@map[id] = link
|
18
|
+
id = register_tag(link)
|
20
19
|
"#{pre}#{id}#{post}"
|
21
20
|
else
|
22
21
|
$&
|
23
22
|
end
|
24
23
|
else
|
25
|
-
id
|
26
|
-
@map[id] = $2
|
24
|
+
id = register_tag($2)
|
27
25
|
"#{$1}#{id}#{$3}"
|
28
26
|
end
|
29
27
|
end
|
30
28
|
data
|
31
29
|
end
|
32
30
|
|
33
|
-
|
31
|
+
def register_tag(tag)
|
32
|
+
id = "TAG#{Digest::SHA1.hexdigest(tag)}TAG"
|
33
|
+
@map[id] = tag
|
34
|
+
id
|
35
|
+
end
|
36
|
+
|
37
|
+
# Process all text nodes from the doc and replace the placeholders with the
|
34
38
|
# final markup.
|
35
|
-
def process(
|
36
|
-
|
37
|
-
|
38
|
-
if
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
39
|
+
def process(rendered_data)
|
40
|
+
doc = Nokogiri::HTML::DocumentFragment.parse(rendered_data)
|
41
|
+
doc.traverse do |node|
|
42
|
+
if node.text? then
|
43
|
+
content = node.content
|
44
|
+
content.gsub!(/TAG[a-f0-9]+TAG/) do |id|
|
45
|
+
if tag = @map[id] then
|
46
|
+
if is_preformatted?(node) then
|
47
|
+
"[[#{tag}]]"
|
48
|
+
else
|
49
|
+
process_tag(tag).gsub('%2f', '/')
|
50
|
+
end
|
51
|
+
end
|
45
52
|
end
|
53
|
+
node.replace(content) if content != node.content
|
46
54
|
end
|
47
55
|
end
|
48
56
|
|
49
|
-
|
57
|
+
doc.to_html
|
50
58
|
end
|
51
59
|
|
52
60
|
private
|
53
|
-
|
54
|
-
# preformatted tags.
|
55
|
-
#
|
56
|
-
# data - The String data (with placeholders).
|
57
|
-
# id - The String SHA1 hash.
|
61
|
+
|
58
62
|
PREFORMATTED_TAGS = %w(code tt)
|
59
63
|
|
60
|
-
def is_preformatted?(
|
61
|
-
doc = Nokogiri::HTML::DocumentFragment.parse(data)
|
62
|
-
node = doc.search("[text()*='#{id}']").first
|
64
|
+
def is_preformatted?(node)
|
63
65
|
node && (PREFORMATTED_TAGS.include?(node.name) ||
|
64
66
|
node.ancestors.any? { |a| PREFORMATTED_TAGS.include?(a.name) })
|
65
67
|
end
|
@@ -79,6 +81,8 @@ class Gollum::Filter::Tags < Gollum::Filter
|
|
79
81
|
html
|
80
82
|
elsif html = process_image_tag(tag)
|
81
83
|
html
|
84
|
+
elsif html = process_external_link_tag(tag)
|
85
|
+
html
|
82
86
|
elsif html = process_file_link_tag(tag)
|
83
87
|
html
|
84
88
|
else
|
@@ -199,6 +203,35 @@ class Gollum::Filter::Tags < Gollum::Filter
|
|
199
203
|
end
|
200
204
|
end
|
201
205
|
|
206
|
+
# Return the String HTML if the tag is a valid external link tag or
|
207
|
+
# nil if it is not.
|
208
|
+
def process_external_link_tag(tag)
|
209
|
+
parts = tag.split('|')
|
210
|
+
return if parts.size.zero?
|
211
|
+
if parts.size == 1
|
212
|
+
url = parts[0].strip
|
213
|
+
else
|
214
|
+
name, url = *parts.compact.map(&:strip)
|
215
|
+
end
|
216
|
+
accepted_protocols = @markup.wiki.sanitization.protocols['a']['href'].dup
|
217
|
+
if accepted_protocols.include?(:relative)
|
218
|
+
accepted_protocols.select!{|protocol| protocol != :relative}
|
219
|
+
regexp = %r{^((#{accepted_protocols.join("|")}):)?(//)}
|
220
|
+
else
|
221
|
+
regexp = %r{^((#{accepted_protocols.join("|")}):)}
|
222
|
+
end
|
223
|
+
if url =~ regexp
|
224
|
+
if name.nil?
|
225
|
+
%{<a href="#{url}">#{url}</a>}
|
226
|
+
else
|
227
|
+
%{<a href="#{url}">#{name}</a>}
|
228
|
+
end
|
229
|
+
else
|
230
|
+
nil
|
231
|
+
end
|
232
|
+
|
233
|
+
end
|
234
|
+
|
202
235
|
# Attempt to process the tag as a file link tag.
|
203
236
|
#
|
204
237
|
# tag - The String tag contents (the stuff inside the double
|
@@ -214,8 +247,6 @@ class Gollum::Filter::Tags < Gollum::Filter
|
|
214
247
|
path = parts[1] && parts[1].strip
|
215
248
|
path = if path && file = @markup.find_file(path)
|
216
249
|
::File.join @markup.wiki.base_path, file.path
|
217
|
-
elsif path =~ %r{^https?://}
|
218
|
-
path
|
219
250
|
else
|
220
251
|
nil
|
221
252
|
end
|
@@ -243,25 +274,21 @@ class Gollum::Filter::Tags < Gollum::Filter
|
|
243
274
|
name, page_name = *parts.compact.map(&:strip)
|
244
275
|
cname = @markup.wiki.page_class.cname(page_name || name)
|
245
276
|
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
link_name
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
presence = "present"
|
255
|
-
end
|
256
|
-
link = ::File.join(@markup.wiki.base_path, page ? page.escaped_url_path : CGI.escape(link_name))
|
277
|
+
presence = "absent"
|
278
|
+
link_name = cname
|
279
|
+
page, extra = find_page_from_name(cname)
|
280
|
+
if page
|
281
|
+
link_name = @markup.wiki.page_class.cname(page.name)
|
282
|
+
presence = "present"
|
283
|
+
end
|
284
|
+
link = ::File.join(@markup.wiki.base_path, page ? page.escaped_url_path : CGI.escape(link_name))
|
257
285
|
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
286
|
+
# //page is invalid
|
287
|
+
# strip all duplicate forward slashes using helpers.rb trim_leading_slash
|
288
|
+
# //page => /page
|
289
|
+
link = trim_leading_slash link
|
262
290
|
|
263
|
-
|
264
|
-
end
|
291
|
+
%{<a class="internal #{presence}" href="#{link}#{extra}">#{name}</a>}
|
265
292
|
end
|
266
293
|
|
267
294
|
# Find a page from a given cname. If the page has an anchor (#) and has
|