Module: Rouge

Defined in:
lib/rouge.rb,
lib/rouge/cli.rb,
lib/rouge/util.rb,
lib/rouge/lexer.rb,
lib/rouge/theme.rb,
lib/rouge/token.rb,
lib/rouge/guesser.rb,
lib/rouge/version.rb,
lib/rouge/lexers/c.rb,
lib/rouge/lexers/d.rb,
lib/rouge/lexers/j.rb,
lib/rouge/lexers/q.rb,
lib/rouge/lexers/r.rb,
lib/rouge/formatter.rb,
lib/rouge/lexers/go.rb,
lib/rouge/lexers/io.rb,
lib/rouge/lexers/p4.rb,
lib/rouge/lexers/vb.rb,
lib/rouge/themes/bw.rb,
lib/rouge/lexers/ada.rb,
lib/rouge/lexers/awk.rb,
lib/rouge/lexers/bpf.rb,
lib/rouge/lexers/bsl.rb,
lib/rouge/lexers/coq.rb,
lib/rouge/lexers/cpp.rb,
lib/rouge/lexers/css.rb,
lib/rouge/lexers/dot.rb,
lib/rouge/lexers/ecl.rb,
lib/rouge/lexers/eex.rb,
lib/rouge/lexers/elm.rb,
lib/rouge/lexers/epp.rb,
lib/rouge/lexers/erb.rb,
lib/rouge/lexers/hcl.rb,
lib/rouge/lexers/hql.rb,
lib/rouge/lexers/ini.rb,
lib/rouge/lexers/irb.rb,
lib/rouge/lexers/jsl.rb,
lib/rouge/lexers/jsp.rb,
lib/rouge/lexers/jsx.rb,
lib/rouge/lexers/lua.rb,
lib/rouge/lexers/nim.rb,
lib/rouge/lexers/nix.rb,
lib/rouge/lexers/ocl.rb,
lib/rouge/lexers/php.rb,
lib/rouge/lexers/qml.rb,
lib/rouge/lexers/rml.rb,
lib/rouge/lexers/sas.rb,
lib/rouge/lexers/sed.rb,
lib/rouge/lexers/sml.rb,
lib/rouge/lexers/sqf.rb,
lib/rouge/lexers/sql.rb,
lib/rouge/lexers/ssh.rb,
lib/rouge/lexers/tap.rb,
lib/rouge/lexers/tcl.rb,
lib/rouge/lexers/tex.rb,
lib/rouge/lexers/tsx.rb,
lib/rouge/lexers/vue.rb,
lib/rouge/lexers/xml.rb,
lib/rouge/lexers/zig.rb,
lib/rouge/lexers/abap.rb,
lib/rouge/lexers/apex.rb,
lib/rouge/lexers/biml.rb,
lib/rouge/lexers/cmhg.rb,
lib/rouge/lexers/conf.rb,
lib/rouge/lexers/csvs.rb,
lib/rouge/lexers/cuda.rb,
lib/rouge/lexers/dart.rb,
lib/rouge/lexers/diff.rb,
lib/rouge/lexers/glsl.rb,
lib/rouge/lexers/hack.rb,
lib/rouge/lexers/haml.rb,
lib/rouge/lexers/haxe.rb,
lib/rouge/lexers/hlsl.rb,
lib/rouge/lexers/html.rb,
lib/rouge/lexers/http.rb,
lib/rouge/lexers/isbl.rb,
lib/rouge/lexers/java.rb,
lib/rouge/lexers/json.rb,
lib/rouge/lexers/lean.rb,
lib/rouge/lexers/llvm.rb,
lib/rouge/lexers/m68k.rb,
lib/rouge/lexers/make.rb,
lib/rouge/lexers/mojo.rb,
lib/rouge/lexers/mxml.rb,
lib/rouge/lexers/nasm.rb,
lib/rouge/lexers/nial.rb,
lib/rouge/lexers/perl.rb,
lib/rouge/lexers/pony.rb,
lib/rouge/lexers/rego.rb,
lib/rouge/lexers/ruby.rb,
lib/rouge/lexers/rust.rb,
lib/rouge/lexers/sass.rb,
lib/rouge/lexers/scss.rb,
lib/rouge/lexers/slim.rb,
lib/rouge/lexers/stan.rb,
lib/rouge/lexers/toml.rb,
lib/rouge/lexers/twig.rb,
lib/rouge/lexers/vala.rb,
lib/rouge/lexers/vhdl.rb,
lib/rouge/lexers/viml.rb,
lib/rouge/lexers/xojo.rb,
lib/rouge/lexers/yaml.rb,
lib/rouge/lexers/yang.rb,
lib/rouge/regex_lexer.rb,
lib/rouge/lexers/clean.rb,
lib/rouge/lexers/cmake.rb,
lib/rouge/lexers/dafny.rb,
lib/rouge/lexers/email.rb,
lib/rouge/lexers/hocon.rb,
lib/rouge/lexers/idris.rb,
lib/rouge/lexers/iecst.rb,
lib/rouge/lexers/janet.rb,
lib/rouge/lexers/jinja.rb,
lib/rouge/lexers/julia.rb,
lib/rouge/lexers/lasso.rb,
lib/rouge/lexers/lutin.rb,
lib/rouge/lexers/magik.rb,
lib/rouge/lexers/mason.rb,
lib/rouge/lexers/meson.rb,
lib/rouge/lexers/mosel.rb,
lib/rouge/lexers/nginx.rb,
lib/rouge/lexers/ocaml.rb,
lib/rouge/lexers/plist.rb,
lib/rouge/lexers/plsql.rb,
lib/rouge/lexers/praat.rb,
lib/rouge/lexers/scala.rb,
lib/rouge/lexers/shell.rb,
lib/rouge/lexers/sieve.rb,
lib/rouge/lexers/slice.rb,
lib/rouge/lexers/stata.rb,
lib/rouge/lexers/swift.rb,
lib/rouge/lexers/ttcn3.rb,
lib/rouge/lexers/tulip.rb,
lib/rouge/lexers/xpath.rb,
lib/rouge/themes/tulip.rb,
lib/rouge/guessers/util.rb,
lib/rouge/lexers/apache.rb,
lib/rouge/lexers/armasm.rb,
lib/rouge/lexers/augeas.rb,
lib/rouge/lexers/bibtex.rb,
lib/rouge/lexers/ceylon.rb,
lib/rouge/lexers/csharp.rb,
lib/rouge/lexers/cypher.rb,
lib/rouge/lexers/cython.rb,
lib/rouge/lexers/digdag.rb,
lib/rouge/lexers/docker.rb,
lib/rouge/lexers/eiffel.rb,
lib/rouge/lexers/elixir.rb,
lib/rouge/lexers/erlang.rb,
lib/rouge/lexers/escape.rb,
lib/rouge/lexers/factor.rb,
lib/rouge/lexers/fluent.rb,
lib/rouge/lexers/fsharp.rb,
lib/rouge/lexers/gradle.rb,
lib/rouge/lexers/groovy.rb,
lib/rouge/lexers/hylang.rb,
lib/rouge/lexers/idlang.rb,
lib/rouge/lexers/kotlin.rb,
lib/rouge/lexers/liquid.rb,
lib/rouge/lexers/lustre.rb,
lib/rouge/lexers/matlab.rb,
lib/rouge/lexers/nesasm.rb,
lib/rouge/lexers/pascal.rb,
lib/rouge/lexers/prolog.rb,
lib/rouge/lexers/puppet.rb,
lib/rouge/lexers/python.rb,
lib/rouge/lexers/racket.rb,
lib/rouge/lexers/scheme.rb,
lib/rouge/lexers/smarty.rb,
lib/rouge/lexers/sparql.rb,
lib/rouge/lexers/svelte.rb,
lib/rouge/lexers/turtle.rb,
lib/rouge/lexers/wollok.rb,
lib/rouge/lexers/xquery.rb,
lib/rouge/text_analyzer.rb,
lib/rouge/themes/base16.rb,
lib/rouge/themes/github.rb,
lib/rouge/themes/pastie.rb,
lib/rouge/formatters/tex.rb,
lib/rouge/lexers/clojure.rb,
lib/rouge/lexers/console.rb,
lib/rouge/lexers/crystal.rb,
lib/rouge/lexers/fortran.rb,
lib/rouge/lexers/freefem.rb,
lib/rouge/lexers/ghc_cmm.rb,
lib/rouge/lexers/gherkin.rb,
lib/rouge/lexers/graphql.rb,
lib/rouge/lexers/haskell.rb,
lib/rouge/lexers/igorpro.rb,
lib/rouge/lexers/jsonnet.rb,
lib/rouge/lexers/systemd.rb,
lib/rouge/lexers/syzlang.rb,
lib/rouge/lexers/syzprog.rb,
lib/rouge/lexers/varnish.rb,
lib/rouge/lexers/verilog.rb,
lib/rouge/template_lexer.rb,
lib/rouge/themes/gruvbox.rb,
lib/rouge/themes/molokai.rb,
lib/rouge/themes/monokai.rb,
lib/rouge/formatters/html.rb,
lib/rouge/formatters/null.rb,
lib/rouge/guessers/source.rb,
lib/rouge/lexers/bbcbasic.rb,
lib/rouge/lexers/cfscript.rb,
lib/rouge/lexers/gdscript.rb,
lib/rouge/lexers/ghc_core.rb,
lib/rouge/lexers/isabelle.rb,
lib/rouge/lexers/json_doc.rb,
lib/rouge/lexers/markdown.rb,
lib/rouge/lexers/minizinc.rb,
lib/rouge/lexers/msgtrans.rb,
lib/rouge/lexers/openedge.rb,
lib/rouge/lexers/protobuf.rb,
lib/rouge/lexers/reasonml.rb,
lib/rouge/lexers/rescript.rb,
lib/rouge/lexers/velocity.rb,
lib/rouge/themes/colorful.rb,
lib/rouge/themes/igor_pro.rb,
lib/rouge/themes/magritte.rb,
lib/rouge/lexers/batchfile.rb,
lib/rouge/lexers/brainfuck.rb,
lib/rouge/lexers/cisco_ios.rb,
lib/rouge/lexers/smalltalk.rb,
lib/rouge/lexers/terraform.rb,
lib/rouge/guessers/filename.rb,
lib/rouge/guessers/mimetype.rb,
lib/rouge/guessers/modeline.rb,
lib/rouge/lexers/codeowners.rb,
lib/rouge/lexers/datastudio.rb,
lib/rouge/lexers/handlebars.rb,
lib/rouge/lexers/javascript.rb,
lib/rouge/lexers/livescript.rb,
lib/rouge/lexers/moonscript.rb,
lib/rouge/lexers/plain_text.rb,
lib/rouge/lexers/postscript.rb,
lib/rouge/lexers/powershell.rb,
lib/rouge/lexers/prometheus.rb,
lib/rouge/lexers/properties.rb,
lib/rouge/lexers/typescript.rb,
lib/rouge/plugins/redcarpet.rb,
lib/rouge/lexers/common_lisp.rb,
lib/rouge/lexers/mathematica.rb,
lib/rouge/lexers/objective_c.rb,
lib/rouge/lexers/sass/common.rb,
lib/rouge/tex_theme_renderer.rb,
lib/rouge/lexers/actionscript.rb,
lib/rouge/lexers/apiblueprint.rb,
lib/rouge/lexers/apple_script.rb,
lib/rouge/lexers/brightscript.rb,
lib/rouge/lexers/coffeescript.rb,
lib/rouge/lexers/lua/keywords.rb,
lib/rouge/lexers/ocaml/common.rb,
lib/rouge/lexers/php/keywords.rb,
lib/rouge/lexers/sqf/keywords.rb,
lib/rouge/lexers/isbl/builtins.rb,
lib/rouge/lexers/llvm/keywords.rb,
lib/rouge/lexers/objective_cpp.rb,
lib/rouge/lexers/supercollider.rb,
lib/rouge/lexers/viml/keywords.rb,
lib/rouge/themes/thankful_eyes.rb,
lib/rouge/formatters/html_table.rb,
lib/rouge/guessers/glob_mapping.rb,
lib/rouge/lexers/lasso/keywords.rb,
lib/rouge/formatters/html_inline.rb,
lib/rouge/formatters/html_legacy.rb,
lib/rouge/formatters/terminal256.rb,
lib/rouge/lexers/apache/keywords.rb,
lib/rouge/lexers/matlab/builtins.rb,
lib/rouge/lexers/matlab/keywords.rb,
lib/rouge/lexers/robot_framework.rb,
lib/rouge/themes/monokai_sublime.rb,
lib/rouge/guessers/disambiguation.rb,
lib/rouge/lexers/gherkin/keywords.rb,
lib/rouge/lexers/literate_haskell.rb,
lib/rouge/formatters/html_linewise.rb,
lib/rouge/formatters/html_pygments.rb,
lib/rouge/lexers/typescript/common.rb,
lib/rouge/lexers/objective_c/common.rb,
lib/rouge/formatters/html_line_table.rb,
lib/rouge/lexers/mathematica/keywords.rb,
lib/rouge/lexers/literate_coffeescript.rb,
lib/rouge/lexers/opentype_feature_file.rb,
lib/rouge/formatters/terminal_truecolor.rb,
lib/rouge/formatters/html_line_highlighter.rb

Overview

This file is automatically generated by ‘rake builtins:mathematica`. See tasks/builtins/mathematica.rake for more info.

Defined Under Namespace

Modules: Formatters, Guessers, HasModes, Indentation, Lexers, Plugins, Themes Classes: CLI, CSSTheme, FileReader, Formatter, Guesser, InheritableHash, InheritableList, Lexer, RegexLexer, TemplateLexer, TexThemeRenderer, TextAnalyzer, Theme, Token

Constant Summary collapse

LIB_DIR =

cache value in a constant since ‘__dir__` allocates a new string on every call.

__dir__.freeze

Class Method Summary collapse

Class Method Details

.highlight(text, lexer, formatter, &b) ⇒ Object

Highlight some text with a given lexer and formatter.

Examples:

Rouge.highlight('@foo = 1', 'ruby', 'html')
Rouge.highlight('var foo = 1;', 'js', 'terminal256')

# streaming - chunks become available as they are lexed
Rouge.highlight(large_string, 'ruby', 'html') do |chunk|
  $stdout.print chunk
end


29
30
31
32
33
34
35
36
37
# File 'lib/rouge.rb', line 29

def highlight(text, lexer, formatter, &b)
  lexer = Lexer.find(lexer) unless lexer.respond_to? :lex
  raise "unknown lexer #{lexer}" unless lexer

  formatter = Formatter.find(formatter) unless formatter.respond_to? :format
  raise "unknown formatter #{formatter}" unless formatter

  formatter.format(lexer.lex(text), &b)
end

.load_file(path) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Load a file relative to the ‘lib/rouge` path.



42
43
44
# File 'lib/rouge.rb', line 42

def load_file(path)
  Kernel::load File.join(LIB_DIR, "rouge/#{path}.rb")
end

.load_lexersObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Load the lexers in the ‘lib/rouge/lexers` directory.



49
50
51
52
53
54
# File 'lib/rouge.rb', line 49

def load_lexers
  lexer_dir = Pathname.new(LIB_DIR) / "rouge/lexers"
  Pathname.glob(lexer_dir / '*.rb').each do |f|
    Lexers.load_lexer(f.relative_path_from(lexer_dir))
  end
end

.reload!Object



14
15
16
17
# File 'lib/rouge.rb', line 14

def reload!
  Object::send :remove_const, :Rouge
  Kernel::load __FILE__
end

.versionObject



5
6
7
# File 'lib/rouge/version.rb', line 5

def self.version
  "4.4.0"
end