{"id":15144207,"url":"https://github.com/ollema/glimra","last_synced_at":"2025-10-23T20:32:12.926Z","repository":{"id":254759752,"uuid":"847429975","full_name":"ollema/glimra","owner":"ollema","description":"Zero runtime syntax highlighter for lustre/ssg.","archived":false,"fork":false,"pushed_at":"2024-09-08T00:14:11.000Z","size":224,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-09-27T10:22:32.043Z","etag":null,"topics":["gleam","lustre","nif","rustler","tree-sitter"],"latest_commit_sha":null,"homepage":"","language":"Gleam","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ollema.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-25T19:50:35.000Z","updated_at":"2024-09-08T19:17:24.000Z","dependencies_parsed_at":"2024-09-07T22:45:56.585Z","dependency_job_id":"706dcb56-98c1-45b5-b84f-7edbd7ca978b","html_url":"https://github.com/ollema/glimra","commit_stats":null,"previous_names":["ollema/glans","ollema/glimra"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ollema%2Fglimra","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ollema%2Fglimra/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ollema%2Fglimra/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ollema%2Fglimra/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ollema","download_url":"https://codeload.github.com/ollema/glimra/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219867847,"owners_count":16555812,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gleam","lustre","nif","rustler","tree-sitter"],"created_at":"2024-09-26T10:22:42.207Z","updated_at":"2025-10-23T20:32:07.575Z","avatar_url":"https://github.com/ollema.png","language":"Gleam","funding_links":[],"categories":[],"sub_categories":[],"readme":"# glimra\n\n[![Package Version](https://img.shields.io/hexpm/v/glimra)](https://hex.pm/packages/glimra)\n[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/glimra/)\n![Erlang-compatible](https://img.shields.io/badge/target-erlang-b83998)\n\nZero runtime syntax highlighter for [`lustre/ssg`](https://github.com/lustre-labs/ssg).\n\n\u003e In Swedish, `glimra` describes the brilliant gleam or lustre that comes from a polished, reflective surface, capturing the essence of light shining off something smooth and glossy.\n\n## Platform support\n\n`glimra` uses [NIFs](https://www.erlang.org/doc/system/nif) to extract syntax highlighting events provided by the [`tree-sitter`](https://crates.io/crates/tree-sitter) and [`tree-sitter-highlight`](https://crates.io/crates/tree-sitter-highlight) crates. This allows `glimra` to provide syntax highlighting for a wide range of languages with minimal effort.\n\nUnfortunately, this also means that `glimra` only works with the Erlang target. You can use the provided precompiled binaries for the supported platforms or compile the NIFs yourself with the Rust toolchain.\n\nCurrently, the following operating systems and architectures are supported:\n\n| OS      | Architecture(s) |\n| ------- | --------------- |\n| Linux   | x86_64          |\n| macOS   | aarch64, x86_64 |\n| Windows | x86_64          |\n\n## Installation\n\n```sh\ngleam add glimra\n```\n\n## Usage\n\n`glimra` can be used to highlight source code snippets in a variety of languages. While the primary use case is to provide syntax highlighting for code snippets in the `lustre/ssg` static site generator, it can also be used in a more standalone fashion:\n\n```gleam\nimport glimra\nimport glimra/theme\n\npub fn main() {\n  let syntax_highlighter =\n    glimra.new_syntax_highlighter() |\u003e glimra.set_theme(theme.default_theme())\n\n  let source = \"let greeting = \\\"Hello, Joe!\\\"\"\n  let language = \"gleam\"\n\n  let highlighted_snippet =\n    syntax_highlighter\n    |\u003e glimra.syntax_highlight(source:, language:)\n\n  let css = syntax_highlighter |\u003e glimra.to_css()\n}\n```\n\n### Usage with `lustre/ssg`\n\n`glimra` provides a set of utilities to make it easier to work with `glimra` and `lustre/ssg`.\n\nGiven a typical `lustre/ssg` `build.gleam` file with the following `main()` function, you can generate and add the static stylesheet using the `add_static_stylesheet` builder:\n\n```gleam\nimport glimra\nimport glimra/theme\n\npub fn main() {\n  let syntax_highlighter =\n    glimra.new_syntax_highlighter()\n    |\u003e glimra.set_theme(theme.default_theme())\n\n  let build = ssg.new(\"./priv\")\n    |\u003e ssg.add_static_route(\"/\", index.view())\n    |\u003e ssg.add_static_route(\"/blog\", blog.view(posts.all()))\n    // the `add_static_stylesheet` builder works with your existing `lustre/ssg` config\n    |\u003e glimra.add_static_stylesheet(syntax_highlighter: syntax_highlighter)\n    |\u003e ssg.build\n}\n```\n\nYou can also link to the generated static stylesheet in your header:\n\n```gleam\nimport glimra\n\nfn head(title: String, description: String) {\n  html.head([], [\n    html.title([], title),\n    html.meta([attribute.attribute(\"charset\", \"utf-8\")]),\n    html.meta([\n      attribute.attribute(\"name\", \"viewport\"),\n      attribute.attribute(\"content\", \"width=device-width, initial-scale=1\"),\n    ]),\n    html.link([attribute.href(\"/style.css\"), attribute.rel(\"stylesheet\")]),\n    // `link_static_stylesheet` will use the same path as `add_static_stylesheet`\n    glimra.link_static_stylesheet(),\n  ])\n}\n```\n\nFinally, you can use the included `codeblock_renderer` with your `lustre/ssg/djot` render configuration:\n\n```gleam\npub fn parse(\n  from filepath: String,\n  // pass in the same `syntax_highlighter` you used to generate the stylesheet\n  syntax_highlighter syntax_highlighter: Config(HasTheme),\n) -\u003e String {\n  let renderer =\n    djot.Renderer(\n      ..djot.default_renderer(),\n      // this will use `codeblock_renderer` to highlight code snippets\n      codeblock: glimra.codeblock_renderer(syntax_highlighter),\n    )\n\n  let content = {\n    use file \u003c- result.try(\n      simplifile.read(filepath) |\u003e result.replace_error(Nil),\n    )\n    djot.render(file, renderer)\n  }\n\n  case content {\n    Ok(content) -\u003e content\n    Error(_) -\u003e {\n      let error_message = \"could not parse content from file: \" \u003c\u003e filepath\n      panic as error_message\n    }\n  }\n}\n```\n\n## Configuration\n\n`glimra` can be configured to include line numbers, to keep or trim whitespace, and to use a custom theme. The following configuration options are available:\n\n```gleam\npub type Config(HasTheme) {\n  line_numbers: Bool,\n  trim_whitespace: Bool,\n  theme: theme.Theme,\n}\n```\n\nThese are set with the builder pattern:\n\n```gleam\nlet syntax_highlighter =\n  glimra.new_syntax_highlighter()\n  |\u003e glimra.set_line_numbers(true)\n  |\u003e glimra.set_trim_whitespace(true)\n  |\u003e glimra.set_theme(theme.default_theme())\n```\n\nNote that the `theme` is required for any CSS generation to work!\n\n---\n\nFurther documentation can be found at \u003chttps://hexdocs.pm/glimra\u003e.\n\n## Development\n\n```sh\ngleam test  # run the tests\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Follema%2Fglimra","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Follema%2Fglimra","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Follema%2Fglimra/lists"}