{"id":20631066,"url":"https://github.com/zsnout/syntaxcolor","last_synced_at":"2026-04-18T08:02:40.121Z","repository":{"id":104247865,"uuid":"269997279","full_name":"zSnout/SyntaxColor","owner":"zSnout","description":"Having trouble with syntax highlighting? Need a simple, yet powerful parser? Welcome to SyntaxColor, a simple yet powerful syntax highlighter. It's the last one you'll ever need.","archived":false,"fork":false,"pushed_at":"2020-06-06T17:45:39.000Z","size":106,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-15T18:31:22.807Z","etag":null,"topics":["highlight","syntax","syntax-highlighter","syntax-highlighting","syntaxcolor","zsnout"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zSnout.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":"2020-06-06T13:57:47.000Z","updated_at":"2020-06-06T17:45:41.000Z","dependencies_parsed_at":"2023-07-22T10:30:15.107Z","dependency_job_id":null,"html_url":"https://github.com/zSnout/SyntaxColor","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zSnout/SyntaxColor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zSnout%2FSyntaxColor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zSnout%2FSyntaxColor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zSnout%2FSyntaxColor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zSnout%2FSyntaxColor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zSnout","download_url":"https://codeload.github.com/zSnout/SyntaxColor/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zSnout%2FSyntaxColor/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31961348,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T00:39:45.007Z","status":"online","status_checked_at":"2026-04-18T02:00:07.018Z","response_time":103,"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":["highlight","syntax","syntax-highlighter","syntax-highlighting","syntaxcolor","zsnout"],"created_at":"2024-11-16T14:10:43.798Z","updated_at":"2026-04-18T08:02:40.075Z","avatar_url":"https://github.com/zSnout.png","language":"JavaScript","readme":"# SyntaxColor\nHaving trouble with syntax highlighting? Need a simple, yet powerful parser? Welcome to SyntaxColor, a simple yet powerful syntax highlighter. It's the last one you'll ever need.\n\n---\n\n## Rules\n\nThe SyntaxColor parser requires that you pass rules for it to color. A rule is an object that contains properties that help the parser decide what to color.\n\nEach rule must contain the `regex` and `token` properties, and may contain `next` and/or `caseSensitive` properties.\n\n#### `regex`\nThe `regex` property contains either a regular expression to match, or a regular expression in the form of a string.\nFor example, `/Hello world/` and `\"Hello world\"` are both valid values, but `23` is not.\nAny flags except `i` on the regular expression will be removed.\n\n#### `token` (aliases: `tokenList`, `tokenArray`)\nThe `token` property can contain either a string, an array, or a function.\n\n##### String\nIf the `token` property is a string, the result matched by `regex` will be wrapped in a `\u003cspan\u003e` with a class of `token`.\nTo add several classes, use class names seperated by `.`. Note that classes will have a prefix applied to them, so `abc` becomes `sc_abc`.\n\n##### Array\nIf the `token` property is an array, each group in the `regex` will have the classes specified in the array added to them in order.\n\n\u003e **WARNING:** Make sure that you have as many groups in your `regex` as there are elements in the list, otherwise you may get unexpected results.\n\n\u003e **WARNING:** You should make sure that every character in your `regex` is contained in a group, and that groups are non-nested, otherwise you may get unexpected results.\n\n##### Function\nIf the `token` property is a function, SyntaxColor will evaluate the function, passing the matched result in the way the browser returned it.\nSyntaxColor will then take the returned result and evaluate it in the manner above.\n\n#### `next` (alias: `nextState`)\nThe `next` property is **NOT REQUIRED**, and defaults to the current state.\nIt specifies the next state for the parser to go to. More on states later.\n\n#### `caseSensitive`\nThe `caseSensitive` property is **NOT REQUIRED**, and defaults to `true`.\nIt specifies whether the regular expression should be matched as case-sensitive.\n\n\u003e **WARNING:** If the `i` flag is set on the regular expression, it overrides the `caseSensitive` option.\n\n---\n\n## States\n\nThe SyntaxColor parser groups rules into different states, which the parser goes through based on the rules specified.\n\nThe parser always starts in the `\"start\"` state, so that state is where you should put your beginnng rules.\n\nThen, as the parser evaluates your rules, if it encounters a match and the `next` property is set, it goes to the state specified by the `next` property.\n\n---\n\n## Rule\n\nA rule is a JavaScript object containing the `regex`, `token`, `next?`, and `caseSensitive?` properties.\n\nHere's the format for a rule:\n``` javascript\n{\n    regex: RegExp or String,\n    token: String, Array, or Function\n    [,next: String]\n    [,caseSensitive: Boolean]\n}\n```\n\n---\n\n## Rule Set\n\nA rule set is a JavaScript array containing several rules.\n\nHere's the format for a rule set:\n``` javascript\n[\n    rule1,\n    rule2,\n    ...\n]\n```\n\n---\n\n## Complete Rule Set\n\nA complete rule set is a JavaScript object containing several states and their rule sets.\n\nHere's the format for a complete rule set:\n``` javascript\n{\n    state1: ruleSet1,\n    state2: ruleSet2,\n    ...\n}\n```\n\n---\n\n## `highlight(text,rules[,prefix = \"zsnout_\"])`\n\nThe `highlight()` function highlights the `text` given with the `rules` given. If `rules` is an array, it is converted to `{start: rules}`.\n\nIt also applies a prefix of `prefix` to each class, so as not to get mixed up with other classes. The `prefix` option defaults to `\"zsnout_\"`.\n\nIt returns the HTML string with the classes applied.\n\n---\n\n## Exposed Functions\n\n### `escapeText(text)` = escaped HTML\nThe `escapeText()` function escapes common HTML characters (`\u003c\u003e'\"\u0026`) into their \u0026xxx; forms.\n\n### `escapeChar(text)` = escaped character / non-escaped text\nThe `escapeChar()` function escapes the text provided IF it is a single character; otherwise it returns the text.\n\n### `parseRules(rules)` = parsed rules\nThe `parseRules()` function converts the rules provided into a more machine-readable format. It converts all strings to regular expressions, converts aliases to their original forms, removes flags from regular expressions, and adds the `i` flag if set.\n\n### `addClasses(match,token,prefix)` = \u0026lt;span\u0026gt;match\u0026lt;/span\u0026gt;\nThe `addClasses()` function wraps the match provided in a `\u003cspan\u003e` tag with classes based on `token`, prefixed with `prefix`.\n\n### `compress(html)` = compressed text\nThe `compress()` function compresses `\u003cspan\u003e`s like so: `\u003cspan class=\"abc\"\u003ea\u003c/span\u003e\u003cspan class=\"abc\"\u003eb\u003c/span\u003e\u003cspan class=\"abc\"\u003ec\u003c/span\u003e` --\u003e `\u003cspan class=\"abc\"\u003eabc\u003c/span\u003e`.\n\n### `changeSpaces(html)` = replaced text\nThe `changeSpaces()` function replaces a series of at least two spaces with a string of `\"\u0026zwnj;\u0026nbsp;\"`s.\n\n### `highlightLine(line,allRules,state,prefix)` = {html: highlighted html,state: current state}\nThe `highlightLine()` function highlights a single line of code based on the current state.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzsnout%2Fsyntaxcolor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzsnout%2Fsyntaxcolor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzsnout%2Fsyntaxcolor/lists"}