gitlab-org--gitlab-foss/lib/gitlab/markup_helper.rb

58 lines
1.5 KiB
Ruby
Raw Normal View History

module Gitlab
2015-05-12 19:40:11 -04:00
module MarkupHelper
2017-04-19 20:39:29 -04:00
extend self
MARKDOWN_EXTENSIONS = %w(mdown mkd mkdn md markdown).freeze
ASCIIDOC_EXTENSIONS = %w(adoc ad asciidoc).freeze
OTHER_EXTENSIONS = %w(textile rdoc org creole wiki mediawiki rst).freeze
EXTENSIONS = MARKDOWN_EXTENSIONS + ASCIIDOC_EXTENSIONS + OTHER_EXTENSIONS
# Public: Determines if a given filename is compatible with GitHub::Markup.
#
# filename - Filename string to check
#
# Returns boolean
def markup?(filename)
2017-04-19 20:39:29 -04:00
EXTENSIONS.include?(extension(filename))
end
# Public: Determines if a given filename is compatible with
# GitLab-flavored Markdown.
#
# filename - Filename string to check
#
# Returns boolean
def gitlab_markdown?(filename)
2017-04-19 20:39:29 -04:00
MARKDOWN_EXTENSIONS.include?(extension(filename))
end
# Public: Determines if the given filename has AsciiDoc extension.
#
# filename - Filename string to check
#
# Returns boolean
def asciidoc?(filename)
2017-04-19 20:39:29 -04:00
ASCIIDOC_EXTENSIONS.include?(extension(filename))
end
# Public: Determines if the given filename is plain text.
#
# filename - Filename string to check
#
# Returns boolean
def plain?(filename)
2017-04-19 20:39:29 -04:00
extension(filename) == 'txt' || filename.casecmp('readme').zero?
end
def previewable?(filename)
markup?(filename)
end
2017-04-19 20:39:29 -04:00
private
def extension(filename)
File.extname(filename).downcase.delete('.')
end
end
end