Skip to content

Commit

Permalink
add a :content option to http (#1592)
Browse files Browse the repository at this point in the history
this allows overriding of the auto-detected lexer for the content.

Co-authored-by: http://jneen.net/ <jneen@jneen.net>
  • Loading branch information
jneen and http://jneen.net/ authored Sep 25, 2020
1 parent 593f3c9 commit 86ca47d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/rouge/lexers/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,22 @@ class HTTP < RegexLexer
title "HTTP"
desc 'http requests and responses'

option :content, "the language for the content (default: auto-detect)"

def self.http_methods
@http_methods ||= %w(GET POST PUT DELETE HEAD OPTIONS TRACE PATCH)
end

def content_lexer
@content_lexer ||= (lexer_option(:content) || guess_content_lexer)
end

def guess_content_lexer
return Lexers::PlainText unless @content_type

@content_lexer ||= Lexer.guess_by_mimetype(@content_type)
Lexer.guess_by_mimetype(@content_type)
rescue Lexer::AmbiguousGuess
@content_lexer = Lexers::PlainText
Lexers::PlainText
end

start { @content_type = 'text/plain' }
Expand Down

0 comments on commit 86ca47d

Please sign in to comment.