{"id":51133701,"url":"https://github.com/trananhtung/parse-css-font","last_synced_at":"2026-06-28T18:00:41.460Z","repository":{"id":366563163,"uuid":"1276596202","full_name":"trananhtung/parse-css-font","owner":"trananhtung","description":"Parse the CSS font shorthand into its components (style, variant, weight, stretch, size, line-height, family). A faithful Rust port of parse-css-font. Zero deps, no_std.","archived":false,"fork":false,"pushed_at":"2026-06-22T14:46:53.000Z","size":16,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-06-25T15:37:14.086Z","etag":null,"topics":["css","font","no-std","parser","rust"],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/trananhtung.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-22T05:56:52.000Z","updated_at":"2026-06-22T14:49:10.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/trananhtung/parse-css-font","commit_stats":null,"previous_names":["trananhtung/parse-css-font"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/trananhtung/parse-css-font","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trananhtung%2Fparse-css-font","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trananhtung%2Fparse-css-font/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trananhtung%2Fparse-css-font/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trananhtung%2Fparse-css-font/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/trananhtung","download_url":"https://codeload.github.com/trananhtung/parse-css-font/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trananhtung%2Fparse-css-font/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34823788,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-26T02:00:06.560Z","response_time":106,"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":["css","font","no-std","parser","rust"],"created_at":"2026-06-25T15:01:51.265Z","updated_at":"2026-06-26T16:00:56.811Z","avatar_url":"https://github.com/trananhtung.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# parse-css-font\n\n[![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors-)\n\n[![Crates.io](https://img.shields.io/crates/v/parse-css-font.svg)](https://crates.io/crates/parse-css-font)\n[![Documentation](https://docs.rs/parse-css-font/badge.svg)](https://docs.rs/parse-css-font)\n[![CI](https://github.com/trananhtung/parse-css-font/actions/workflows/ci.yml/badge.svg)](https://github.com/trananhtung/parse-css-font/actions/workflows/ci.yml)\n[![License](https://img.shields.io/crates/l/parse-css-font.svg)](#license)\n\n**Parse the CSS [`font`](https://developer.mozilla.org/en-US/docs/Web/CSS/font)\nshorthand** into its parts — style, variant, weight, stretch, size, line-height and\nthe font-family list — or recognise a system-font keyword. A faithful Rust port of\nthe [`parse-css-font`](https://www.npmjs.com/package/parse-css-font) npm package.\nZero dependencies and `#![no_std]`.\n\n```rust\nuse parse_css_font::{parse, Font, LineHeight};\n\nlet Font::Shorthand(f) = parse(\"italic bold 12px/1.5 Arial, sans-serif\").unwrap() else {\n    unreachable!()\n};\nassert_eq!(f.style, \"italic\");\nassert_eq!(f.weight, \"bold\");\nassert_eq!(f.size, \"12px\");\nassert_eq!(f.line_height, LineHeight::Number(1.5));\nassert_eq!(f.family, [\"Arial\", \"sans-serif\"]);\n\nassert!(matches!(parse(\"caption\"), Ok(Font::System(_))));\n```\n\n## Why parse-css-font?\n\nThe `font` shorthand packs up to seven properties into one string with an order-\nindependent prefix, an optional `size/line-height`, and a quoted, comma-separated\nfamily list. Canvas text rendering, PDF generation, and layout tools all need to\npull those apart. This is the small, dependency-free piece that does exactly that —\nmatching the canonical JS implementation.\n\n```toml\n[dependencies]\nparse-css-font = \"0.1\"\n```\n\n## API\n\n| Item | Purpose |\n| --- | --- |\n| `parse(value)` | `Result\u003cFont, ParseError\u003e` |\n| `Font::System(SystemFont)` | A system-font keyword (`caption`, `icon`, `menu`, …) |\n| `Font::Shorthand(Shorthand)` | The parsed parts |\n| `Shorthand { style, variant, weight, stretch, size, line_height, family }` | Strings, with `family: Vec\u003cString\u003e` |\n| `LineHeight` | `Normal`, `Number(f64)` (unitless), or `Other(String)` (e.g. `\"14px\"`) |\n\n## Behavior\n\n- `style`, `variant`, `weight`, and `stretch` may appear in any order before the\n  size, and each defaults to `\"normal\"`.\n- The `font-size` is required; a `/line-height` after it is optional. A unitless\n  line-height becomes `LineHeight::Number`, a `normal` one becomes `Normal`, and any\n  other (e.g. `14px`) becomes `Other`.\n- `font-family` is required, split on top-level commas, with surrounding quotes\n  removed.\n- System-font keywords are matched exactly (case-sensitive) and returned as\n  `Font::System`.\n- Missing size/family, an empty string, or a repeated property returns a\n  `ParseError`.\n\n## Contributors ✨\n\nThis project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind are welcome — code, docs, bug reports, ideas, reviews! See the [emoji key](https://allcontributors.org/docs/en/emoji-key) for how each contribution is recognized, and open a PR or issue to get involved.\n\nThanks goes to these wonderful people:\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\u003c!-- prettier-ignore-start --\u003e\n\u003c!-- markdownlint-disable --\u003e\n\u003ctable\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"14.28%\"\u003e\u003ca href=\"https://github.com/trananhtung\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/30992229?v=4?s=100\" width=\"100px;\" alt=\"Tung Tran\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eTung Tran\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/trananhtung/parse-css-font/commits?author=trananhtung\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"#maintenance-trananhtung\" title=\"Maintenance\"\u003e🚧\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n\u003c!-- markdownlint-restore --\u003e\n\u003c!-- prettier-ignore-end --\u003e\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n\n## License\n\nLicensed under either of [Apache-2.0](LICENSE-APACHE) or [MIT](LICENSE-MIT) at\nyour option.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrananhtung%2Fparse-css-font","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftrananhtung%2Fparse-css-font","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrananhtung%2Fparse-css-font/lists"}