{"id":19391829,"url":"https://github.com/joeltg/hast-util-from-lezer","last_synced_at":"2026-01-12T05:17:47.833Z","repository":{"id":57261715,"uuid":"377315914","full_name":"joeltg/hast-util-from-lezer","owner":"joeltg","description":"Render styled Lezer syntax trees to hast","archived":false,"fork":false,"pushed_at":"2025-09-16T02:21:39.000Z","size":339,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-15T09:11:08.158Z","etag":null,"topics":["abstract-syntax-tree","ast","hast","hast-util","lezer"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/joeltg.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,"zenodo":null}},"created_at":"2021-06-15T23:17:32.000Z","updated_at":"2025-09-16T02:21:43.000Z","dependencies_parsed_at":"2024-06-21T05:45:39.932Z","dependency_job_id":"52895be6-1d63-4acc-af5e-7fd875784fa3","html_url":"https://github.com/joeltg/hast-util-from-lezer","commit_stats":null,"previous_names":["joeltg/hast-util-from-codemirror"],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/joeltg/hast-util-from-lezer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joeltg%2Fhast-util-from-lezer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joeltg%2Fhast-util-from-lezer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joeltg%2Fhast-util-from-lezer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joeltg%2Fhast-util-from-lezer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joeltg","download_url":"https://codeload.github.com/joeltg/hast-util-from-lezer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joeltg%2Fhast-util-from-lezer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28335167,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T00:36:25.062Z","status":"online","status_checked_at":"2026-01-12T02:00:08.677Z","response_time":98,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["abstract-syntax-tree","ast","hast","hast-util","lezer"],"created_at":"2024-11-10T10:29:21.734Z","updated_at":"2026-01-12T05:17:47.812Z","avatar_url":"https://github.com/joeltg.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# hast-util-from-lezer\n\n[![standard-readme compliant](https://img.shields.io/badge/readme%20style-standard-brightgreen.svg)](https://github.com/RichardLitt/standard-readme) [![license](https://img.shields.io/github/license/joeltg/hast-util-from-lezer)](https://opensource.org/licenses/MIT) [![NPM version](https://img.shields.io/npm/v/hast-util-from-lezer)](https://www.npmjs.com/package/hast-util-from-lezer) ![TypeScript types](https://img.shields.io/npm/types/hast-util-from-lezer)\n\nRender styled [Lezer syntax trees](https://github.com/lezer-parser/common) to [hast](https://github.com/syntax-tree/hast).\n\n## Table of contents\n\n- [Install](#install)\n- [Usage](#usage)\n- [API](#api)\n- [Contributing](#contributing)\n- [License](#license)\n\n## Install\n\n```\nnpm i hast-util-from-lezer\n```\n\n## Usage\n\n```typescript\nimport { fromLezer } from \"hast-util-from-lezer\"\nimport { parser as javascriptParser } from \"@lezer/javascript\"\nimport { toHtml } from \"hast-util-to-html\"\n\nconst source = `function norm(a: number, b: number): number {\n\treturn Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2))\n}`\n\nconst tree = javascriptParser.parse(source)\nconst element = fromLezer(source, tree)\nconsole.log(toHtml(element))\n```\n\nyields the following HTML:\n\n```\n\u003cspan class=\"tok-keyword\"\u003efunction\u003c/span\u003e \u003cspan class=\"tok-variableName\"\u003enorm\u003c/span\u003e\u003cspan class=\"tok-punctuation\"\u003e(\u003c/span\u003e\u003cspan class=\"tok-variableName tok-definition\"\u003ea\u003c/span\u003e\u003cspan class=\"tok-punctuation\"\u003e:\u003c/span\u003e \u003cspan class=\"tok-typeName\"\u003enumber\u003c/span\u003e\u003cspan class=\"tok-punctuation\"\u003e,\u003c/span\u003e \u003cspan class=\"tok-variableName tok-definition\"\u003eb\u003c/span\u003e\u003cspan class=\"tok-punctuation\"\u003e:\u003c/span\u003e \u003cspan class=\"tok-typeName\"\u003enumber\u003c/span\u003e\u003cspan class=\"tok-punctuation\"\u003e)\u003c/span\u003e\u003cspan class=\"tok-punctuation\"\u003e:\u003c/span\u003e \u003cspan class=\"tok-typeName\"\u003enumber\u003c/span\u003e \u003cspan class=\"tok-punctuation\"\u003e{\u003c/span\u003e\n        \u003cspan class=\"tok-keyword\"\u003ereturn\u003c/span\u003e \u003cspan class=\"tok-variableName\"\u003eMath\u003c/span\u003e\u003cspan class=\"tok-operator\"\u003e.\u003c/span\u003e\u003cspan class=\"tok-propertyName\"\u003esqrt\u003c/span\u003e\u003cspan class=\"tok-punctuation\"\u003e(\u003c/span\u003e\u003cspan class=\"tok-variableName\"\u003eMath\u003c/span\u003e\u003cspan class=\"tok-operator\"\u003e.\u003c/span\u003e\u003cspan class=\"tok-propertyName\"\u003epow\u003c/span\u003e\u003cspan class=\"tok-punctuation\"\u003e(\u003c/span\u003e\u003cspan class=\"tok-variableName\"\u003ea\u003c/span\u003e\u003cspan class=\"tok-punctuation\"\u003e,\u003c/span\u003e \u003cspan class=\"tok-number\"\u003e2\u003c/span\u003e\u003cspan class=\"tok-punctuation\"\u003e)\u003c/span\u003e \u003cspan class=\"tok-operator\"\u003e+\u003c/span\u003e \u003cspan class=\"tok-variableName\"\u003eMath\u003c/span\u003e\u003cspan class=\"tok-operator\"\u003e.\u003c/span\u003e\u003cspan class=\"tok-propertyName\"\u003epow\u003c/span\u003e\u003cspan class=\"tok-punctuation\"\u003e(\u003c/span\u003e\u003cspan class=\"tok-variableName\"\u003eb\u003c/span\u003e\u003cspan class=\"tok-punctuation\"\u003e,\u003c/span\u003e \u003cspan class=\"tok-number\"\u003e2\u003c/span\u003e\u003cspan class=\"tok-punctuation\"\u003e)\u003c/span\u003e\u003cspan class=\"tok-punctuation\"\u003e)\u003c/span\u003e\n\u003cspan class=\"tok-punctuation\"\u003e}\u003c/span\u003e\n```\n\n## API\n\n```typescript\nimport type { Tree } from \"@lezer/common\"\nimport type { Root } from \"hast\"\n\ndeclare function fromLezer(source: string, tree: Tree): Root\n```\n\n`tree` must already be styled if you want highlighting classnames in the resulting hast. This means the Lezer grammar you're using has to support highlight style props, typically included with a `highlight.js` file and a `@external propSource` directive in the grammar source. All the Lezer grammars maintained by the Lezer project do; you shouldn't have to worry about it.\n\n## Contributing\n\nhast-util-from-lezer is meant to be a minimal utility library - it's unlikely that I'll want to add new features to it, but if you find bugs, have interface or API suggestions, or general feedback, feel free to open an issue to discuss it!\n\n## License\n\nMIT (c) 2024 Joel Gustafson\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoeltg%2Fhast-util-from-lezer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoeltg%2Fhast-util-from-lezer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoeltg%2Fhast-util-from-lezer/lists"}