Support external file links.

This commit is contained in:
Tom Preston-Werner
2010-07-20 21:06:54 -05:00
parent 5b24f623a2
commit 9d68c4ef8a
2 changed files with 43 additions and 11 deletions
+32 -7
View File
@@ -65,6 +65,24 @@ For security and compatibility reasons Gollum wikis may not contain custom CSS
or JavaScript. These tags will be stripped from the converted HTML. or JavaScript. These tags will be stripped from the converted HTML.
## BRACKET TAGS
A variety of Gollum tags use a double bracket syntax. For example:
[[Link]]
Some tags will accept attributes which are separated by pipe symbols. For
example:
[[Link|Page Title]]
In all cases, the first thing in the link is what is displayed on the page.
So, if the tag is an internal wiki link, the first thing in the tag will be
the link text displayed on the page. If the tag is an embedded image, the
first thing in the tag will be a path to an image file. Use this trick to
easily remember which order things should appear in tags.
## PAGE LINKS ## PAGE LINKS
To link to another Gollum wiki page, use the Gollum Page Link Tag. To link to another Gollum wiki page, use the Gollum Page Link Tag.
@@ -95,13 +113,14 @@ Here are a few more examples:
[[モルドール]] -> モルドール.ext [[モルドール]] -> モルドール.ext
## ABSOLUTE VS. RELATIVE PATHS ## ABSOLUTE VS. RELATIVE VS. EXTERNAL PATH
For Gollum tags that operate on static files (images, PDFs, etc), the paths For Gollum tags that operate on static files (images, PDFs, etc), the paths
may be referenced as either relative or absolute. Relative paths point to a may be referenced as either relative, absolute, or external. Relative paths
static file relative to the page file within the directory structure of the point to a static file relative to the page file within the directory
Gollum repo (even though after conversion, all page files appear to be top structure of the Gollum repo (even though after conversion, all page files
level). These paths are NOT prefixed with a slash. For example: appear to be top level). These paths are NOT prefixed with a slash. For
example:
gollum.pdf gollum.pdf
docs/diagram.png docs/diagram.png
@@ -113,6 +132,12 @@ structure. These paths ARE prefixed with a slash. For example:
/pdfs/gollum.pdf /pdfs/gollum.pdf
/docs/diagram.png /docs/diagram.png
External paths are full URLs. An external path must begin with either
"http://" or "https://". For example:
http://example.com/pdfs/gollum.pdf
http://example.com/images/diagram.png
All of the examples in this README use relative paths, but you may use All of the examples in this README use relative paths, but you may use
whatever works best in your situation. whatever works best in your situation.
@@ -124,8 +149,8 @@ use the Gollum File Link Tag.
[[Gollum|gollum.pdf]] [[Gollum|gollum.pdf]]
The first part of the tag is the link text. The filename appears after the The first part of the tag is the link text. The path to the file appears after
pipe. the pipe.
## IMAGES ## IMAGES
+8 -1
View File
@@ -182,8 +182,15 @@ module Gollum
parts = tag.split('|') parts = tag.split('|')
name = parts[0].strip name = parts[0].strip
path = parts[1] && parts[1].strip path = parts[1] && parts[1].strip
path = if path && file = find_file(path)
::File.join @wiki.base_path, file.path
elsif path =~ /^https?:\/\/.+(jpg|png|gif|svg|bmp)$/
path
else
nil
end
if name && path && file = find_file(path) if name && path
%{<a href="#{::File.join @wiki.base_path, file.path}">#{name}</a>} %{<a href="#{::File.join @wiki.base_path, file.path}">#{name}</a>}
else else
nil nil