class Qiita::Markdown::Filters::SyntaxHighlight

Constants

DEFAULT_LANGUAGE
DEFAULT_OPTION
DEFAULT_TIMEOUT

Public Instance Methods

call() click to toggle source
# File lib/qiita/markdown/filters/syntax_highlight.rb, line 9
def call
  elapsed = 0
  timeout_fallback_language = nil
  doc.search("pre").each do |node|
    elapsed += measure_time do
      Highlighter.call(
        default_language: default_language,
        node: node,
        specific_language: timeout_fallback_language,
      )
    end
    if elapsed >= timeout
      timeout_fallback_language = DEFAULT_LANGUAGE
      result[:syntax_highlight_timed_out] = true
    end
  end
  doc
end

Private Instance Methods

default_language() click to toggle source
# File lib/qiita/markdown/filters/syntax_highlight.rb, line 30
def default_language
  context[:default_language] || DEFAULT_LANGUAGE
end
measure_time() { || ... } click to toggle source
# File lib/qiita/markdown/filters/syntax_highlight.rb, line 34
def measure_time
  t1 = Time.now
  yield
  t2 = Time.now
  t2 - t1
end
timeout() click to toggle source
# File lib/qiita/markdown/filters/syntax_highlight.rb, line 41
def timeout
  context[:syntax_highlight_timeout] || DEFAULT_TIMEOUT
end