class Rouge::TextAnalyzer
Public Instance Methods
doctype()
click to toggle source
Return the contents of the doctype tag if present, nil otherwise.
# File lib/rouge/text_analyzer.rb, line 24 def doctype return @doctype if instance_variable_defined? :@doctype self =~ %r(\A\s* (?:<\?.*?\?>\s*)? # possible <?xml...?> tag <!DOCTYPE\s+(.+?)> )xm @doctype = $1 end
doctype?(type=//)
click to toggle source
Check if the doctype matches a given regexp or string
# File lib/rouge/text_analyzer.rb, line 35 def doctype?(type=//) type === doctype end
lexes_cleanly?(lexer)
click to toggle source
Return true if the result of lexing with the given lexer contains no error tokens.
# File lib/rouge/text_analyzer.rb, line 41 def lexes_cleanly?(lexer) lexer.lex(self) do |(tok, _)| return false if tok.name == 'Error' end true end
shebang()
click to toggle source
Find a shebang. Returns nil if no shebang is present.
# File lib/rouge/text_analyzer.rb, line 6 def shebang return @shebang if instance_variable_defined? :@shebang self =~ /\A\s*#!(.*)$/ @shebang = $1 end
shebang?(match)
click to toggle source
Check if the given shebang is present.
This normalizes things so that ‘text.shebang?(’bash’)‘ will detect `#!/bash`, ’#!/bin/bash’, ‘#!/usr/bin/env bash’, and ‘#!/bin/bash -x’
# File lib/rouge/text_analyzer.rb, line 17 def shebang?(match) return false unless shebang match = /\b#{match}(\s|$)/ match === shebang end