Welcome to mirror list, hosted at ThFree Co, Russian Federation.

other_markup.rb « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2368ea3ad285c22a4a634c8e1c099d9e6ff345bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# frozen_string_literal: true

module Gitlab
  # Parser/renderer for markups without other special support code.
  module OtherMarkup
    RENDER_TIMEOUT = 10.seconds

    # Public: Converts the provided markup into HTML.
    #
    # input         - the source text in a markup format
    #
    def self.render(file_name, input, context)
      html = render_markup(file_name, input, context).force_encoding(input.encoding)

      context[:pipeline] ||= :markup

      html = Banzai.render(html, context)
      html.html_safe
    end

    def self.render_markup(file_name, input, context)
      Gitlab::RenderTimeout.timeout(foreground: RENDER_TIMEOUT) { GitHub::Markup.render(file_name, input) }
    rescue Timeout::Error => e
      class_name = name.demodulize
      timeout_counter.increment(source: class_name)
      Gitlab::ErrorTracking.track_exception(e, project_id: context[:project]&.id, class_name: class_name,
                                               file_name: file_name)

      ActionController::Base.helpers.simple_format(input)
    end

    def self.timeout_counter
      Gitlab::Metrics.counter(:banzai_filter_timeouts_total, 'Count of the Banzai filters that time out')
    end
  end
end