debian-mirror-gitlab/lib/gitlab/markup_helper.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

65 lines
1.6 KiB
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
2015-09-11 14:41:01 +05:30
module Gitlab
module MarkupHelper
2017-08-17 22:00:37 +05:30
extend self
2021-04-29 21:17:54 +05:30
MARKDOWN_EXTENSIONS = %w[mdown mkd mkdn md markdown rmd].freeze
2018-12-13 13:39:08 +05:30
ASCIIDOC_EXTENSIONS = %w[adoc ad asciidoc].freeze
OTHER_EXTENSIONS = %w[textile rdoc org creole wiki mediawiki rst].freeze
2017-08-17 22:00:37 +05:30
EXTENSIONS = MARKDOWN_EXTENSIONS + ASCIIDOC_EXTENSIONS + OTHER_EXTENSIONS
2018-12-13 13:39:08 +05:30
PLAIN_FILENAMES = %w[readme index].freeze
2015-09-11 14:41:01 +05:30
# Public: Determines if a given filename is compatible with GitHub::Markup.
#
# filename - Filename string to check
#
# Returns boolean
def markup?(filename)
2017-08-17 22:00:37 +05:30
EXTENSIONS.include?(extension(filename))
2015-09-11 14:41:01 +05:30
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-08-17 22:00:37 +05:30
MARKDOWN_EXTENSIONS.include?(extension(filename))
2015-09-11 14:41:01 +05:30
end
# Public: Determines if the given filename has AsciiDoc extension.
#
# filename - Filename string to check
#
# Returns boolean
def asciidoc?(filename)
2017-08-17 22:00:37 +05:30
ASCIIDOC_EXTENSIONS.include?(extension(filename))
2015-09-11 14:41:01 +05:30
end
# Public: Determines if the given filename is plain text.
#
# filename - Filename string to check
#
# Returns boolean
def plain?(filename)
2018-12-13 13:39:08 +05:30
extension(filename) == 'txt' || plain_filename?(filename)
2015-09-11 14:41:01 +05:30
end
def previewable?(filename)
markup?(filename)
end
2017-08-17 22:00:37 +05:30
private
def extension(filename)
File.extname(filename).downcase.delete('.')
end
2018-12-13 13:39:08 +05:30
def plain_filename?(filename)
PLAIN_FILENAMES.include?(filename.downcase)
end
2015-09-11 14:41:01 +05:30
end
end