View Source Makeup.Registry (Makeup v1.1.0)
A registry that allows users to dynamically register new makeup lexers.
Lexers should register themselves on application start. That way, you can add support for new programming languages by depending on the relevant lexers. This is useful for projects such as ExDoc, which might contain code in a number of different programming languages.
Link to this section Summary
Functions
Fetches a lexer from Makeup's registry with the given file extension
.
Fetches the lexer from Makeup's registry with the given file extension
.
Fetches the lexer from Makeup's registry with the given name
.
Fetches the lexer from Makeup's registry with the given name
.
Gets the lexer from Makeup's registry with the given file extension
.
Gets the lexer from Makeup's registry with the given name
.
Add a new lexer to Makeup's registry under the given names and extensions.
Adds a new lexer to Makeup's registry under the given extension
.
Adds a new lexer to Makeup's registry under the given name
.
Gets the list of supported language extensions.
Gets the list of supported language names.
Link to this section Functions
Fetches a lexer from Makeup's registry with the given file extension
.
Returns either {:ok, {lexer, options}}
or :error
.
This behaviour is based on Map.fetch/2
.
Fetches the lexer from Makeup's registry with the given file extension
.
Returns either {:ok, {lexer, options}}
or raises a KeyError
.
This behaviour is based on Map.fetch/2
.
Fetches the lexer from Makeup's registry with the given name
.
Returns either {:ok, {lexer, options}}
or :error
.
This behaviour is based on Map.fetch/2
.
Fetches the lexer from Makeup's registry with the given name
.
Returns either {lexer, options}
or raises a KeyError
.
This behaviour is based on Map.fetch!/2
.
Gets the lexer from Makeup's registry with the given file extension
.
Returns either {lexer, options}
or the default
value
(which by default is nil
).
This behaviour is based on Map.get/3
.
Gets the lexer from Makeup's registry with the given name
.
Returns either {lexer, options}
or the default
value
(which by default is nil
).
This behaviour is based on Map.get/3
.
Add a new lexer to Makeup's registry under the given names and extensions.
Expects a lexer lexer
and a number of options:
:options
(default:[]
) - the lexer options. If your lexer doesn't take any options, you'll want the default value of[]
.:names
(default:[]
) - a list of strings with the language names for the lexer. Language names are strings, not atoms. Even if there is only one valid name, you must supply a list with that name. To avoid filling the registry unnecessarily, you should normalize your language names to lowercase strings. If the caller wants to support upper case language names for some reason, they can normalize the language names themselves.:extensions
(default:[]
) - the list of file extensions for the languages supported by the lexer. For example, the elixir lexer should support the"ex"
and"exs"
file extensions. The extensions should not include the dot. That is, you should register"ex"
and not".ex"
. Even if there is only a supported extension, you must supply a list.
example
Example
alias Makeup.Registry
alias Makeup.Lexers.ElixirLexer
# The `:options` key is not required
Registry.register_lexer(ElixirLexer, names: ["elixir", "iex"], extensions: ["ex", "exs"])
Adds a new lexer to Makeup's registry under the given extension
.
This function expects a file extension (e.g. "ex"
) and a pair containing
a lexer
and a list of options
.
You might want to use the Makeup.Registry.register_lexer/2
function instead.
examples
Examples
alias Makeup.Lexers.ElixirLexer
alias Makeup.Registry
Registry.register_lexer_with_extension("ex"), {ElixirLexer, []})
Registry.register_lexer_with_extension("exs"), {ElixirLexer, []})
Adds a new lexer to Makeup's registry under the given name
.
This function expects a language name (e.g. "elixir"
) and a pair containing
a lexer
and a list of options
.
You might want to use the Makeup.Registry.register_lexer/2
function instead.
examples
Examples
alias Makeup.Lexers.ElixirLexer
alias Makeup.Registry
Registry.register_lexer_with_name("elixir", {ElixirLexer, []})
Registry.register_lexer_with_name("iex", {ElixirLexer, []})
Gets the list of supported language extensions.
Gets the list of supported language names.