Merge pull request #637 from jamesdabbs/custom-markup
Allow registering custom markup engines
This commit is contained in:
@@ -80,8 +80,8 @@ choose. Special footers can be created in `footer files`. Other content
|
|||||||
## PAGE FILES
|
## PAGE FILES
|
||||||
|
|
||||||
Page files may be written in any format supported by
|
Page files may be written in any format supported by
|
||||||
[GitHub-Markup](http://github.com/github/markup) (except roff). The
|
[GitHub-Markup](http://github.com/github/markup) (except roff). By default,
|
||||||
current list of formats and allowed extensions is:
|
Gollum recognizes the following extensions:
|
||||||
|
|
||||||
* ASCIIDoc: .asciidoc
|
* ASCIIDoc: .asciidoc
|
||||||
* Creole: .creole
|
* Creole: .creole
|
||||||
@@ -93,8 +93,14 @@ current list of formats and allowed extensions is:
|
|||||||
* Textile: .textile
|
* Textile: .textile
|
||||||
* MediaWiki: .mediawiki, .wiki
|
* MediaWiki: .mediawiki, .wiki
|
||||||
|
|
||||||
|
You may also register your own extensions and parsers:
|
||||||
|
|
||||||
|
Gollum::Markup.register(:angry, "Angry") do |content|
|
||||||
|
content.upcase
|
||||||
|
end
|
||||||
|
|
||||||
Gollum detects the page file format via the extension, so files must have one
|
Gollum detects the page file format via the extension, so files must have one
|
||||||
of the supported extensions in order to be converted.
|
of the default or registered extensions in order to be converted.
|
||||||
|
|
||||||
Page file names may contain any printable UTF-8 character except space
|
Page file names may contain any printable UTF-8 character except space
|
||||||
(U+0020) and forward slash (U+002F). If you commit a page file with any of
|
(U+0020) and forward slash (U+002F). If you commit a page file with any of
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ require File.expand_path('../gollum/page', __FILE__)
|
|||||||
require File.expand_path('../gollum/file', __FILE__)
|
require File.expand_path('../gollum/file', __FILE__)
|
||||||
require File.expand_path('../gollum/file_view', __FILE__)
|
require File.expand_path('../gollum/file_view', __FILE__)
|
||||||
require File.expand_path('../gollum/markup', __FILE__)
|
require File.expand_path('../gollum/markup', __FILE__)
|
||||||
|
require File.expand_path('../gollum/markups', __FILE__)
|
||||||
require File.expand_path('../gollum/sanitization', __FILE__)
|
require File.expand_path('../gollum/sanitization', __FILE__)
|
||||||
require File.expand_path('../gollum/web_sequence_diagram', __FILE__)
|
require File.expand_path('../gollum/web_sequence_diagram', __FILE__)
|
||||||
require File.expand_path('../gollum/frontend/uri_encode_component', __FILE__)
|
require File.expand_path('../gollum/frontend/uri_encode_component', __FILE__)
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
module Precious
|
module Precious
|
||||||
module Editable
|
module Editable
|
||||||
def formats(selected = @page.format)
|
def formats(selected = @page.format)
|
||||||
Gollum::Page::FORMAT_NAMES.map do |key, val|
|
Gollum::Markup.formats.map do |key, val|
|
||||||
{ :name => val,
|
{ :name => val[:name],
|
||||||
:id => key.to_s,
|
:id => key.to_s,
|
||||||
:selected => selected == key}
|
:selected => selected == key}
|
||||||
end.sort do |a, b|
|
end.sort do |a, b|
|
||||||
|
|||||||
@@ -15,6 +15,28 @@ module Gollum
|
|||||||
class Markup
|
class Markup
|
||||||
include Precious::Helpers
|
include Precious::Helpers
|
||||||
|
|
||||||
|
@formats = {}
|
||||||
|
|
||||||
|
class << self
|
||||||
|
attr_reader :formats
|
||||||
|
|
||||||
|
# Register a file extension and associated markup type
|
||||||
|
#
|
||||||
|
# ext - The file extension
|
||||||
|
# name - The name of the markup type
|
||||||
|
# options - Hash of options:
|
||||||
|
# regexp - Regexp to match against.
|
||||||
|
# Defaults to exact match of ext.
|
||||||
|
#
|
||||||
|
# If given a block, that block will be registered with GitHub::Markup to
|
||||||
|
# render any matching pages
|
||||||
|
def register(ext, name, options = {}, &block)
|
||||||
|
regexp = options[:regexp] || Regexp.new(ext.to_s)
|
||||||
|
@formats[ext] = { :name => name, :regexp => regexp }
|
||||||
|
GitHub::Markup.add_markup(regexp, &block) if block_given?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
attr_accessor :toc
|
attr_accessor :toc
|
||||||
attr_reader :metadata
|
attr_reader :metadata
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
module Gollum
|
||||||
|
class Markup
|
||||||
|
register(:markdown, "Markdown", :regexp => /md|mkdn?|mdown|markdown/)
|
||||||
|
register(:textile, "Textile")
|
||||||
|
register(:rdoc, "RDoc")
|
||||||
|
register(:org, "Org-mode")
|
||||||
|
register(:creole, "Creole")
|
||||||
|
register(:rest, "reStructuredText", :regexp => /re?st(\.txt)?/)
|
||||||
|
register(:asciidoc, "AsciiDoc")
|
||||||
|
register(:mediawiki, "MediaWiki", :regexp => /(media)?wiki/)
|
||||||
|
register(:pod, "Pod")
|
||||||
|
end
|
||||||
|
end
|
||||||
+22
-54
@@ -5,17 +5,6 @@ module Gollum
|
|||||||
|
|
||||||
Wiki.page_class = self
|
Wiki.page_class = self
|
||||||
|
|
||||||
VALID_PAGE_RE = /^(.+)\.(md|mkdn?|mdown|markdown|textile|rdoc|org|creole|re?st(\.txt)?|asciidoc|pod|(media)?wiki)$/i
|
|
||||||
FORMAT_NAMES = { :markdown => "Markdown",
|
|
||||||
:textile => "Textile",
|
|
||||||
:rdoc => "RDoc",
|
|
||||||
:org => "Org-mode",
|
|
||||||
:creole => "Creole",
|
|
||||||
:rest => "reStructuredText",
|
|
||||||
:asciidoc => "AsciiDoc",
|
|
||||||
:mediawiki => "MediaWiki",
|
|
||||||
:pod => "Pod" }
|
|
||||||
|
|
||||||
# Sets a Boolean determing whether this page is a historical version.
|
# Sets a Boolean determing whether this page is a historical version.
|
||||||
#
|
#
|
||||||
# Returns nothing.
|
# Returns nothing.
|
||||||
@@ -26,13 +15,29 @@ module Gollum
|
|||||||
# Returns a Page
|
# Returns a Page
|
||||||
attr_accessor :parent_page
|
attr_accessor :parent_page
|
||||||
|
|
||||||
# Checks if a filename has a valid extension understood by GitHub::Markup.
|
|
||||||
|
# Checks a filename against the registered markup extensions
|
||||||
|
#
|
||||||
|
# filename - String filename, like "Home.md"
|
||||||
|
#
|
||||||
|
# Returns e.g. ["Home", :markdown], or [] if the extension is unregistered
|
||||||
|
def self.parse_filename(filename)
|
||||||
|
return [] unless filename =~ /^(.+)\.([a-zA-Z]\w*)$/i
|
||||||
|
pref, ext = $1, $2
|
||||||
|
|
||||||
|
Gollum::Markup.formats.each_pair do |name, format|
|
||||||
|
return [pref, name] if ext =~ format[:regexp]
|
||||||
|
end
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
|
||||||
|
# Checks if a filename has a valid, registered extension
|
||||||
#
|
#
|
||||||
# filename - String filename, like "Home.md".
|
# filename - String filename, like "Home.md".
|
||||||
#
|
#
|
||||||
# Returns the matching String basename of the file without the extension.
|
# Returns the matching String basename of the file without the extension.
|
||||||
def self.valid_filename?(filename)
|
def self.valid_filename?(filename)
|
||||||
filename && filename.to_s =~ VALID_PAGE_RE && $1
|
self.parse_filename(filename).first
|
||||||
end
|
end
|
||||||
|
|
||||||
# Checks if a filename has a valid extension understood by GitHub::Markup.
|
# Checks if a filename has a valid extension understood by GitHub::Markup.
|
||||||
@@ -51,34 +56,9 @@ module Gollum
|
|||||||
#
|
#
|
||||||
# filename - The String filename.
|
# filename - The String filename.
|
||||||
#
|
#
|
||||||
# Returns the Symbol format of the page. One of:
|
# Returns the Symbol format of the page; one of the registered format types
|
||||||
# [ :markdown | :textile | :rdoc | :org | :rest | :asciidoc | :pod |
|
|
||||||
# :roff ]
|
|
||||||
def self.format_for(filename)
|
def self.format_for(filename)
|
||||||
case filename.to_s
|
self.parse_filename(filename).last
|
||||||
when /\.(md|mkdn?|mdown|markdown)$/i
|
|
||||||
:markdown
|
|
||||||
when /\.(textile)$/i
|
|
||||||
:textile
|
|
||||||
when /\.(rdoc)$/i
|
|
||||||
:rdoc
|
|
||||||
when /\.(org)$/i
|
|
||||||
:org
|
|
||||||
when /\.(creole)$/i
|
|
||||||
:creole
|
|
||||||
when /\.(re?st(\.txt)?)$/i
|
|
||||||
:rest
|
|
||||||
when /\.(asciidoc)$/i
|
|
||||||
:asciidoc
|
|
||||||
when /\.(pod)$/i
|
|
||||||
:pod
|
|
||||||
when /\.(\d)$/i
|
|
||||||
:roff
|
|
||||||
when /\.(media)?wiki$/i
|
|
||||||
:mediawiki
|
|
||||||
else
|
|
||||||
nil
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Reusable filter to turn a filename (without path) into a canonical name.
|
# Reusable filter to turn a filename (without path) into a canonical name.
|
||||||
@@ -249,9 +229,7 @@ module Gollum
|
|||||||
|
|
||||||
# Public: The format of the page.
|
# Public: The format of the page.
|
||||||
#
|
#
|
||||||
# Returns the Symbol format of the page. One of:
|
# Returns the Symbol format of the page; one of the registered format types
|
||||||
# [ :markdown | :textile | :rdoc | :org | :rest | :asciidoc | :pod |
|
|
||||||
# :roff ]
|
|
||||||
def format
|
def format
|
||||||
self.class.format_for(@blob.name)
|
self.class.format_for(@blob.name)
|
||||||
end
|
end
|
||||||
@@ -359,17 +337,7 @@ module Gollum
|
|||||||
#
|
#
|
||||||
# Returns the String extension (no leading period).
|
# Returns the String extension (no leading period).
|
||||||
def self.format_to_ext(format)
|
def self.format_to_ext(format)
|
||||||
case format
|
format == :markdown ? "md" : format.to_s
|
||||||
when :markdown then 'md'
|
|
||||||
when :textile then 'textile'
|
|
||||||
when :rdoc then 'rdoc'
|
|
||||||
when :org then 'org'
|
|
||||||
when :creole then 'creole'
|
|
||||||
when :rest then 'rest'
|
|
||||||
when :asciidoc then 'asciidoc'
|
|
||||||
when :pod then 'pod'
|
|
||||||
when :mediawiki then 'mediawiki'
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
#########################################################################
|
#########################################################################
|
||||||
|
|||||||
@@ -6,3 +6,4 @@ b16b3d9fad9d78e5a669e7f33d94c96da374eccd b0de6e794dfdc7ef3400e894225bfe23308aae5
|
|||||||
b0de6e794dfdc7ef3400e894225bfe23308aae5c cfea406f5f77afc7fb673a43e97721234385b1bd Darren Oakley <daz.oakley@gmail.com> 1341830099 +0100 push
|
b0de6e794dfdc7ef3400e894225bfe23308aae5c cfea406f5f77afc7fb673a43e97721234385b1bd Darren Oakley <daz.oakley@gmail.com> 1341830099 +0100 push
|
||||||
cfea406f5f77afc7fb673a43e97721234385b1bd 629aa678272b017a4d136d35e77ac94d80b08dc2 Darren Oakley <daz.oakley@gmail.com> 1341830833 +0100 push
|
cfea406f5f77afc7fb673a43e97721234385b1bd 629aa678272b017a4d136d35e77ac94d80b08dc2 Darren Oakley <daz.oakley@gmail.com> 1341830833 +0100 push
|
||||||
629aa678272b017a4d136d35e77ac94d80b08dc2 7d6aeab8b84c895f21f6c66b84a457b0fced9693 Daniel Kimsey <dekimsey@ufl.edu> 1352501984 -0500 push
|
629aa678272b017a4d136d35e77ac94d80b08dc2 7d6aeab8b84c895f21f6c66b84a457b0fced9693 Daniel Kimsey <dekimsey@ufl.edu> 1352501984 -0500 push
|
||||||
|
7d6aeab8b84c895f21f6c66b84a457b0fced9693 563cc3701db990caf63e4ce9c3697a062890ca48 James Dabbs <jamesdabbs@gmail.com> 1361843315 -0500 push
|
||||||
|
|||||||
@@ -6,3 +6,4 @@ b16b3d9fad9d78e5a669e7f33d94c96da374eccd b0de6e794dfdc7ef3400e894225bfe23308aae5
|
|||||||
b0de6e794dfdc7ef3400e894225bfe23308aae5c cfea406f5f77afc7fb673a43e97721234385b1bd Darren Oakley <daz.oakley@gmail.com> 1341830099 +0100 push
|
b0de6e794dfdc7ef3400e894225bfe23308aae5c cfea406f5f77afc7fb673a43e97721234385b1bd Darren Oakley <daz.oakley@gmail.com> 1341830099 +0100 push
|
||||||
cfea406f5f77afc7fb673a43e97721234385b1bd 629aa678272b017a4d136d35e77ac94d80b08dc2 Darren Oakley <daz.oakley@gmail.com> 1341830833 +0100 push
|
cfea406f5f77afc7fb673a43e97721234385b1bd 629aa678272b017a4d136d35e77ac94d80b08dc2 Darren Oakley <daz.oakley@gmail.com> 1341830833 +0100 push
|
||||||
629aa678272b017a4d136d35e77ac94d80b08dc2 7d6aeab8b84c895f21f6c66b84a457b0fced9693 Daniel Kimsey <dekimsey@ufl.edu> 1352501984 -0500 push
|
629aa678272b017a4d136d35e77ac94d80b08dc2 7d6aeab8b84c895f21f6c66b84a457b0fced9693 Daniel Kimsey <dekimsey@ufl.edu> 1352501984 -0500 push
|
||||||
|
7d6aeab8b84c895f21f6c66b84a457b0fced9693 563cc3701db990caf63e4ce9c3697a062890ca48 James Dabbs <jamesdabbs@gmail.com> 1361843315 -0500 push
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1 +1 @@
|
|||||||
7d6aeab8b84c895f21f6c66b84a457b0fced9693
|
563cc3701db990caf63e4ce9c3697a062890ca48
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ context "Wiki" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "parents with default master ref" do
|
test "parents with default master ref" do
|
||||||
ref = '7d6aeab8b84c895f21f6c66b84a457b0fced9693'
|
ref = '563cc3701db990caf63e4ce9c3697a062890ca48'
|
||||||
committer = Gollum::Committer.new(@wiki)
|
committer = Gollum::Committer.new(@wiki)
|
||||||
assert_equal ref, committer.parents.first.sha
|
assert_equal ref, committer.parents.first.sha
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ context "GitAccess" do
|
|||||||
assert @access.ref_map.empty?
|
assert @access.ref_map.empty?
|
||||||
assert @access.tree_map.empty?
|
assert @access.tree_map.empty?
|
||||||
@access.tree 'master'
|
@access.tree 'master'
|
||||||
assert_equal({"master"=>"7d6aeab8b84c895f21f6c66b84a457b0fced9693"}, @access.ref_map)
|
assert_equal({"master"=>"563cc3701db990caf63e4ce9c3697a062890ca48"}, @access.ref_map)
|
||||||
|
|
||||||
@access.tree '1db89ebba7e2c14d93b94ff98cfa3708a4f0d4e3'
|
@access.tree '1db89ebba7e2c14d93b94ff98cfa3708a4f0d4e3'
|
||||||
map = @access.tree_map['1db89ebba7e2c14d93b94ff98cfa3708a4f0d4e3']
|
map = @access.tree_map['1db89ebba7e2c14d93b94ff98cfa3708a4f0d4e3']
|
||||||
|
|||||||
@@ -237,3 +237,17 @@ if $METADATA
|
|||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "with custom markup engines" do
|
||||||
|
setup do
|
||||||
|
Gollum::Markup.register(:redacted, "Redacted", :regexp => /rd/) { |content| content.gsub /\S/, '-' }
|
||||||
|
@wiki = Gollum::Wiki.new(testpath("examples/lotr.git"))
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should use the specified engine" do
|
||||||
|
page = @wiki.page('Riddles')
|
||||||
|
assert_equal :redacted, page.format
|
||||||
|
assert page.raw_data.include? 'Time'
|
||||||
|
assert page.raw_data =~ /^[\s\-]*$/
|
||||||
|
end
|
||||||
|
end
|
||||||
+1
-1
@@ -61,7 +61,7 @@ context "Wiki" do
|
|||||||
test "list files" do
|
test "list files" do
|
||||||
files = @wiki.files
|
files = @wiki.files
|
||||||
assert_equal \
|
assert_equal \
|
||||||
['Data.csv', 'eye.jpg', 'todo.txt'],
|
['Data.csv', 'Riddles.rd', 'eye.jpg', 'todo.txt'],
|
||||||
files.map { |p| p.filename }.sort
|
files.map { |p| p.filename }.sort
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user