Miniparser/lib/lang_detect.rb
2023-08-24 06:41:11 -06:00

14 lines
365 B
Ruby

# frozen_string_literal: true
module Miniparser
class LanguageDetector
def detect(code)
return :html if code.match?(/<\s*html.*>|<\s*head.*>|<\s*body.*>/i)
return :css if code.match?(/^\s*(\.\w+|#\w+|body)\s*\{/)
return :js if code.match?(/function\s+\w+\s*\(|var\s+\w+\s*=|let\s+\w+\s*=|const\s+\w+\s*=/)
:unknown
end
end
end