2018-10-22 03:00:50 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-08-11 02:50:56 -04:00
|
|
|
module Gitlab
|
2015-05-12 19:40:11 -04:00
|
|
|
module MarkupHelper
|
2017-04-19 20:39:29 -04:00
|
|
|
extend self
|
|
|
|
|
2021-03-16 14:11:53 -04:00
|
|
|
MARKDOWN_EXTENSIONS = %w[mdown mkd mkdn md markdown rmd].freeze
|
2018-11-02 10:32:05 -04:00
|
|
|
ASCIIDOC_EXTENSIONS = %w[adoc ad asciidoc].freeze
|
|
|
|
OTHER_EXTENSIONS = %w[textile rdoc org creole wiki mediawiki rst].freeze
|
2017-04-19 20:39:29 -04:00
|
|
|
EXTENSIONS = MARKDOWN_EXTENSIONS + ASCIIDOC_EXTENSIONS + OTHER_EXTENSIONS
|
2018-11-02 10:32:05 -04:00
|
|
|
PLAIN_FILENAMES = %w[readme index].freeze
|
2014-08-11 02:50:56 -04:00
|
|
|
|
|
|
|
# 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))
|
2014-08-11 02:50:56 -04:00
|
|
|
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))
|
2014-08-11 02:50:56 -04:00
|
|
|
end
|
2014-10-04 11:56:12 -04:00
|
|
|
|
2015-05-12 19:07:48 -04:00
|
|
|
# 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))
|
2015-05-12 19:07:48 -04:00
|
|
|
end
|
|
|
|
|
2015-07-09 05:36:09 -04:00
|
|
|
# Public: Determines if the given filename is plain text.
|
|
|
|
#
|
|
|
|
# filename - Filename string to check
|
|
|
|
#
|
|
|
|
# Returns boolean
|
|
|
|
def plain?(filename)
|
2018-11-02 10:32:05 -04:00
|
|
|
extension(filename) == 'txt' || plain_filename?(filename)
|
2015-07-09 05:36:09 -04:00
|
|
|
end
|
|
|
|
|
2014-10-04 11:56:12 -04:00
|
|
|
def previewable?(filename)
|
2015-05-12 19:54:13 -04:00
|
|
|
markup?(filename)
|
2014-10-04 11:56:12 -04:00
|
|
|
end
|
2017-04-19 20:39:29 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def extension(filename)
|
|
|
|
File.extname(filename).downcase.delete('.')
|
|
|
|
end
|
2018-11-02 10:32:05 -04:00
|
|
|
|
|
|
|
def plain_filename?(filename)
|
|
|
|
PLAIN_FILENAMES.include?(filename.downcase)
|
2018-11-02 11:10:41 -04:00
|
|
|
end
|
2014-08-11 02:50:56 -04:00
|
|
|
end
|
|
|
|
end
|