View Source Makeup.Lexer.Groups (Makeup v1.1.2)

Utilities to highlight groups of tokens on mouseover.

The typical example is to highlight matching pairs of delimiters, such as parenthesis, angle brackets, etc.

Summary

Functions

Defines a function with the given name that takes a list of tokens and divides matching delimiters into groups.

Returns a random prefix for group ids in an HTML file.

Functions

Link to this macro

defgroupmatcher(name, stacks, opts \\ [])

View Source (macro)

Defines a function with the given name that takes a list of tokens and divides matching delimiters into groups.

Takes as arguments a name for the function (must be an atom) and a list containing the patterns describing the matching groups.

Examples

# Extracted from the default elixir lexer that ships with ExDoc
defgroupmatcher :match_groups, [
  # Match opening and closing parenthesis
  parentheses: [
    open: [[{:punctuation, %{language: :elixir}, "("}]],
    close: [[{:punctuation, %{language: :elixir}, ")"}]]
  ],

  # Match more complex delimiters, but still an open and close delimiter
  fn_end: [
    open: [[{:keyword, %{language: :elixir}, "fn"}]],
    close: [[{:keyword, %{language: :elixir}, "end"}]]
  ]

  # Match delimiters with middle components
  do_end: [
    open: [
      [{:keyword, %{language: :elixir}, "do"}]
    ],
    middle: [
      [{:keyword, %{language: :elixir}, "else"}],
      [{:keyword, %{language: :elixir}, "catch"}],
      [{:keyword, %{language: :elixir}, "rescue"}],
      [{:keyword, %{language: :elixir}, "after"}]
    ],
    close: [
      [{:keyword, %{language: :elixir}, "end"}]
    ]
  ]
]

Returns a random prefix for group ids in an HTML file.

This is useful to avoid collisions. The group ids should be unique for a certain HTML document, and the easiest way of guaranteeing it is by generating long random prefixes.