Add local file support.
Example of absolute path to local file. ```html:/home``` Example of relative path to local file. ```html:home``` 1.8.7 string fix. 's'[0..0] instead of 's'[0] Fix regex. Add absolute and relative tests.
This commit is contained in:
@@ -89,12 +89,6 @@ module Precious
|
|||||||
redirect File.join(settings.wiki_options[:base_path].to_s, 'Home')
|
redirect File.join(settings.wiki_options[:base_path].to_s, 'Home')
|
||||||
end
|
end
|
||||||
|
|
||||||
# Removes all slashes from the start of string.
|
|
||||||
def clean_url url
|
|
||||||
return url if url.nil?
|
|
||||||
url.gsub('%2F','/').gsub(/^\/+/,'')
|
|
||||||
end
|
|
||||||
|
|
||||||
# path is set to name if path is nil.
|
# path is set to name if path is nil.
|
||||||
# if path is 'a/b' and a and b are dirs, then
|
# if path is 'a/b' and a and b are dirs, then
|
||||||
# path must have a trailing slash 'a/b/' or
|
# path must have a trailing slash 'a/b/' or
|
||||||
|
|||||||
@@ -17,5 +17,11 @@ module Precious
|
|||||||
def sanitize_empty_params(param)
|
def sanitize_empty_params(param)
|
||||||
[nil,''].include?(param) ? nil : CGI.unescape(param)
|
[nil,''].include?(param) ? nil : CGI.unescape(param)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Remove all slashes from the start of string.
|
||||||
|
def clean_url url
|
||||||
|
return url if url.nil?
|
||||||
|
url.gsub('%2F','/').gsub(/^\/+/,'')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ module Gollum
|
|||||||
class Gitcode
|
class Gitcode
|
||||||
def initialize path
|
def initialize path
|
||||||
raise(ArgumentError, 'path is nil or empty') if path.nil? or path.empty?
|
raise(ArgumentError, 'path is nil or empty') if path.nil? or path.empty?
|
||||||
|
|
||||||
@uri = URI::HTTP.build({
|
@uri = URI::HTTP.build({
|
||||||
:path => self.unchomp(path),
|
:path => self.unchomp(path),
|
||||||
:host => 'raw.github.com',
|
:host => 'raw.github.com',
|
||||||
|
|||||||
+22
-4
@@ -2,7 +2,9 @@ require 'digest/sha1'
|
|||||||
require 'cgi'
|
require 'cgi'
|
||||||
require 'pygments'
|
require 'pygments'
|
||||||
require 'base64'
|
require 'base64'
|
||||||
require File.expand_path( '../gitcode', __FILE__ )
|
|
||||||
|
require File.expand_path '../frontend/helpers', __FILE__
|
||||||
|
require File.expand_path '../gitcode', __FILE__
|
||||||
|
|
||||||
# initialize Pygments
|
# initialize Pygments
|
||||||
Pygments.start
|
Pygments.start
|
||||||
@@ -10,6 +12,8 @@ Pygments.start
|
|||||||
module Gollum
|
module Gollum
|
||||||
|
|
||||||
class Markup
|
class Markup
|
||||||
|
include Precious::Helpers
|
||||||
|
|
||||||
attr_accessor :toc
|
attr_accessor :toc
|
||||||
attr_reader :metadata
|
attr_reader :metadata
|
||||||
|
|
||||||
@@ -459,9 +463,23 @@ module Gollum
|
|||||||
#########################################################################
|
#########################################################################
|
||||||
|
|
||||||
def extract_gitcode data
|
def extract_gitcode data
|
||||||
data.gsub /^[ \t]*``` ?(\w+):(.+)```$/ do
|
data.gsub /^[ \t]*``` ?([^:\n\r]+):([^`\n\r]+)```/ do
|
||||||
gc = Gollum::Gitcode.new $2
|
contents = ''
|
||||||
"```#{$1}\n#{gc.contents}\n```"
|
# Use empty string if $2 is nil.
|
||||||
|
uri = $2 || ''
|
||||||
|
# Detect local file.
|
||||||
|
if uri[0..6] != 'github/'
|
||||||
|
if uri[0..0] != '/' # relative file
|
||||||
|
contents = @wiki.page(uri).formatted_data
|
||||||
|
else # use full path
|
||||||
|
contents = @wiki.paged( extract_name( clean_url( uri ) ),
|
||||||
|
'/' + clean_url( extract_path( uri ) ) ).formatted_data
|
||||||
|
end
|
||||||
|
else
|
||||||
|
contents = Gollum::Gitcode.new(uri).contents
|
||||||
|
end
|
||||||
|
|
||||||
|
"```#{$1}\n#{contents}\n```\n"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -495,6 +495,35 @@ np.array([[2,2],[1,3]],np.float)
|
|||||||
assert_match /\(\[\[/, rendered, "#{markup_class} parses out wiki links\n#{rendered}"
|
assert_match /\(\[\[/, rendered, "#{markup_class} parses out wiki links\n#{rendered}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "embed code is escaped" do
|
||||||
|
@wiki.write_page("script", :markdown, "a <script></script> b", commit_details)
|
||||||
|
@wiki.write_page("page", :markdown, "```html:script```", commit_details)
|
||||||
|
|
||||||
|
output_script = @wiki.page("script").formatted_data
|
||||||
|
output_page = @wiki.page("page").formatted_data
|
||||||
|
|
||||||
|
assert_equal %Q{<p>a b</p>}, output_script
|
||||||
|
assert_equal %Q{<div class=\"highlight\">\n<pre><span class=\"nt\"><p></span>a b<span class=\"nt\"></p></span>\n</pre>\n</div>\n}, output_page
|
||||||
|
end
|
||||||
|
|
||||||
|
test "embed code page absolute link" do
|
||||||
|
@wiki.write_page("base", :markdown, "a\n!base\b", commit_details)
|
||||||
|
@wiki.write_page("a", :markdown, "a\n```html:/base```\b", commit_details)
|
||||||
|
|
||||||
|
page = @wiki.page("a")
|
||||||
|
output = page.formatted_data
|
||||||
|
assert_equal %Q{<p>a\n</p><div class=\"highlight\">\n<pre><span class=\"nt\"><p></span>a\n!base<span class=\"nt\"></p></span>\n</pre>\n</div>\n\n}, output
|
||||||
|
end
|
||||||
|
|
||||||
|
test "embed code page relative link" do
|
||||||
|
@wiki.write_page("base", :markdown, "a\n!rel\b", commit_details)
|
||||||
|
@wiki.write_page("a", :markdown, "a\n```html:base```\b", commit_details)
|
||||||
|
|
||||||
|
page = @wiki.page("a")
|
||||||
|
output = page.formatted_data
|
||||||
|
assert_equal %Q{<p>a\n</p><div class=\"highlight\">\n<pre><span class=\"nt\"><p></span>a\n!rel<span class=\"nt\"></p></span>\n</pre>\n</div>\n\n}, output
|
||||||
|
end
|
||||||
|
|
||||||
#########################################################################
|
#########################################################################
|
||||||
#
|
#
|
||||||
# Web Sequence Diagrams
|
# Web Sequence Diagrams
|
||||||
|
|||||||
Reference in New Issue
Block a user