glimra/theme

A module that defines and manages themes for syntax highlighting.

The module provides types and functions for creating and applying color styles to different elements of code, such as variables, functions, keywords, and more. The Theme type encapsulates all the styles necessary for syntax highlighting, and the module includes functions to convert these themes into CSS.

Types

Represents an RGB color.

pub type Color {
  Color(r: Int, g: Int, b: Int)
}

Constructors

  • Color(r: Int, g: Int, b: Int)

Represents a style for syntax highlighting.

pub type Style {
  Style(color: Color, italic: Bool)
}

Constructors

  • Style(color: Color, italic: Bool)

Represents a syntax highlighting theme. This includes styles for various code elements such as variables, functions, types, keywords, punctuation, comments, and tags.

pub type Theme {
  Theme(
    background_color: Color,
    padding_x: Float,
    padding_y: Float,
    border_radius: Float,
    variable: Style,
    variable_builtin: Style,
    variable_member: Style,
    variable_parameter_builtin: Style,
    variable_parameter: Style,
    constant: Style,
    constant_builtin: Style,
    constant_macro: Style,
    module: Style,
    label: Style,
    string: Style,
    string_documentation: Style,
    string_escape: Style,
    string_regexp: Style,
    string_special: Style,
    character: Style,
    character_special: Style,
    boolean: Style,
    number: Style,
    type_: Style,
    type_builtin: Style,
    type_definition: Style,
    attribute: Style,
    attribute_builtin: Style,
    property: Style,
    function: Style,
    function_builtin: Style,
    function_call: Style,
    function_macro: Style,
    function_method: Style,
    function_method_call: Style,
    constructor: Style,
    operator: Style,
    keyword: Style,
    keyword_coroutine: Style,
    keyword_function: Style,
    keyword_operator: Style,
    keyword_import: Style,
    keyword_type: Style,
    keyword_modifier: Style,
    keyword_repeat: Style,
    keyword_return: Style,
    keyword_debug: Style,
    keyword_exception: Style,
    keyword_conditional: Style,
    keyword_conditional_ternary: Style,
    punctuation: Style,
    punctuation_bracket: Style,
    punctuation_delimiter: Style,
    punctuation_special: Style,
    comment: Style,
    comment_documentation: Style,
    tag: Style,
    tag_builtin: Style,
    tag_attribute: Style,
    tag_delimiter: Style,
  )
}

Constructors

  • Theme(
      background_color: Color,
      padding_x: Float,
      padding_y: Float,
      border_radius: Float,
      variable: Style,
      variable_builtin: Style,
      variable_member: Style,
      variable_parameter_builtin: Style,
      variable_parameter: Style,
      constant: Style,
      constant_builtin: Style,
      constant_macro: Style,
      module: Style,
      label: Style,
      string: Style,
      string_documentation: Style,
      string_escape: Style,
      string_regexp: Style,
      string_special: Style,
      character: Style,
      character_special: Style,
      boolean: Style,
      number: Style,
      type_: Style,
      type_builtin: Style,
      type_definition: Style,
      attribute: Style,
      attribute_builtin: Style,
      property: Style,
      function: Style,
      function_builtin: Style,
      function_call: Style,
      function_macro: Style,
      function_method: Style,
      function_method_call: Style,
      constructor: Style,
      operator: Style,
      keyword: Style,
      keyword_coroutine: Style,
      keyword_function: Style,
      keyword_operator: Style,
      keyword_import: Style,
      keyword_type: Style,
      keyword_modifier: Style,
      keyword_repeat: Style,
      keyword_return: Style,
      keyword_debug: Style,
      keyword_exception: Style,
      keyword_conditional: Style,
      keyword_conditional_ternary: Style,
      punctuation: Style,
      punctuation_bracket: Style,
      punctuation_delimiter: Style,
      punctuation_special: Style,
      comment: Style,
      comment_documentation: Style,
      tag: Style,
      tag_builtin: Style,
      tag_attribute: Style,
      tag_delimiter: Style,
    )

Functions

pub fn default_theme() -> Theme

Returns the default theme for syntax highlighting.

This theme is based on Catppuccin Mocha, a community-driven pastel theme.

pub fn to_css(theme theme: Theme) -> String

Converts a Theme into a complete CSS stylesheet as a string.

This function generates CSS classes for all the different styles included in the theme, ready to be applied to code elements in HTML.

Search Document