kanbanworkflowstimelinescrumrubyroadmapproject-planningproject-managementopenprojectangularissue-trackerifcgantt-chartganttbug-trackerboardsbcf
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
2.3 KiB
60 lines
2.3 KiB
13 years ago
|
#-- encoding: UTF-8
|
||
14 years ago
|
#-- copyright
|
||
12 years ago
|
# OpenProject is a project management system.
|
||
7 years ago
|
# Copyright (C) 2012-2018 the OpenProject Foundation (OPF)
|
||
14 years ago
|
#
|
||
14 years ago
|
# This program is free software; you can redistribute it and/or
|
||
12 years ago
|
# modify it under the terms of the GNU General Public License version 3.
|
||
14 years ago
|
#
|
||
11 years ago
|
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
|
||
8 years ago
|
# Copyright (C) 2006-2017 Jean-Philippe Lang
|
||
11 years ago
|
# Copyright (C) 2010-2013 the ChiliProject Team
|
||
|
#
|
||
|
# This program is free software; you can redistribute it and/or
|
||
|
# modify it under the terms of the GNU General Public License
|
||
|
# as published by the Free Software Foundation; either version 2
|
||
|
# of the License, or (at your option) any later version.
|
||
|
#
|
||
|
# This program is distributed in the hope that it will be useful,
|
||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
# GNU General Public License for more details.
|
||
|
#
|
||
|
# You should have received a copy of the GNU General Public License
|
||
|
# along with this program; if not, write to the Free Software
|
||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
#
|
||
7 years ago
|
# See docs/COPYRIGHT.rdoc for more details.
|
||
14 years ago
|
#++
|
||
|
|
||
6 years ago
|
module OpenProject
|
||
15 years ago
|
module SyntaxHighlighting
|
||
|
class << self
|
||
6 years ago
|
# Highlights +text+ as the content of +filename+
|
||
|
# Should not return line numbers nor outer pre tag
|
||
|
# use CodeRay to scan normal text, since it's smart enough to find
|
||
|
# the correct source encoding before passing it to ERB::Util.html_escape
|
||
|
def highlight_by_filename(text, filename)
|
||
|
language = guess_lexer(text, filename)
|
||
14 years ago
|
|
||
6 years ago
|
highlight_by_language(text, language)
|
||
15 years ago
|
end
|
||
14 years ago
|
|
||
6 years ago
|
# Highlights +text+ using +language+ syntax
|
||
|
def highlight_by_language(text, language, formatter = Rouge::Formatters::HTML.new)
|
||
|
Rouge.highlight(text, language, formatter).html_safe
|
||
|
end
|
||
14 years ago
|
|
||
6 years ago
|
##
|
||
|
# Guesses the appropriate lexer for the given text using rouge's guesser
|
||
|
# Can be used to extract information using the lexer's name, tag, desc methods
|
||
|
def guess_lexer(text, filename = nil)
|
||
|
guessers = [Rouge::Guessers::Source.new(text)]
|
||
|
guessers << Rouge::Guessers::Filename.new(filename) if filename.present?
|
||
14 years ago
|
|
||
6 years ago
|
Rouge::Lexer::guess guessers: guessers
|
||
15 years ago
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|