{"id":13489672,"url":"https://github.com/soffes/SyntaxKit","last_synced_at":"2025-03-28T05:31:09.463Z","repository":{"id":56922449,"uuid":"37453251","full_name":"soffes/SyntaxKit","owner":"soffes","description":"TextMate-style syntax highlighting","archived":true,"fork":false,"pushed_at":"2019-08-11T18:12:58.000Z","size":95,"stargazers_count":473,"open_issues_count":7,"forks_count":64,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-03-02T02:52:59.275Z","etag":null,"topics":["carthage","ios","macos","swift","watchos"],"latest_commit_sha":null,"homepage":null,"language":"Swift","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/soffes.png","metadata":{"files":{"readme":"Readme.markdown","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}},"created_at":"2015-06-15T08:36:15.000Z","updated_at":"2025-01-06T03:41:50.000Z","dependencies_parsed_at":"2022-08-21T04:50:16.051Z","dependency_job_id":null,"html_url":"https://github.com/soffes/SyntaxKit","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soffes%2FSyntaxKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soffes%2FSyntaxKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soffes%2FSyntaxKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soffes%2FSyntaxKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/soffes","download_url":"https://codeload.github.com/soffes/SyntaxKit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245978200,"owners_count":20703675,"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":["carthage","ios","macos","swift","watchos"],"created_at":"2024-07-31T19:00:32.926Z","updated_at":"2025-03-28T05:31:07.945Z","avatar_url":"https://github.com/soffes.png","language":"Swift","readme":"# SyntaxKit\n\n[![Version](https://img.shields.io/github/release/soffes/SyntaxKit.svg)](https://github.com/soffes/SyntaxKit/releases) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) [![CocoaPods compatible](https://img.shields.io/cocoapods/v/SyntaxKit.svg)](https://cocoapods.org/pods/SyntaxKit)\n\nSyntaxKit makes TextMate-style syntax highlighting easy. It works on iOS, watchOS, and OS X.\n\nSyntaxKit was abstracted from [Whiskey](http://usewhiskey.com).\n\n\n## Building\n\nSyntaxKit is written in Swift 2 so Xcode 7 is required. There aren't any dependencies besides system frameworks.\n\n\n## Installation\n\n[Carthage](https://github.com/carthage/carthage) is the recommended way to install SyntaxKit. Add the following to your Cartfile:\n\n``` ruby\ngithub \"soffes/SyntaxKit\"\n```\n\nYou can also install with [CocoaPods](https://cocoapods.org):\n\n``` ruby\npod 'SyntaxKit'\n```\n\nFor manual installation, I recommend adding the project as a subproject to your project or workspace and adding the appropriate framework as a target dependency.\n\n\n## Usage\n\nSyntaxKit uses `tmLanguage` and `tmTheme` files to highlight source code. None are provided with SyntaxKit. Thankfully, there are tons available at [TextMate's GitHub org](https://github.com/textmate).\n\n### Basic Parsing\n\nOnce you have a language, you can get started:\n\n```swift\nimport SyntaxKit\n\nlet path = \"path to your .tmLanguage file\"\nlet plist = NSDictionary(contentsOfFile: path)! as [NSObject: AnyObject]\nlet yaml = Language(dictionary: plist)\n\nlet parser = Parser(language: yaml)\n```\n\n`Parser` is a very simple class that just calls a block when it finds something the language file knows about. Let's print all of the elements in this string:\n\n```swift\nlet input = \"title: \\\"Hello World\\\"\\n\"\nparser.parse(input) { scope, range in\n    print(\"\\(scope) - \\(range)\")\n}\n```\n\n`scope` is the name of an element. This is something like `\"string\"` or `\"constant.numeric\"`. `range` is an `NSRange` struct representing where the scope falls in the input string.\n\n\n### Working with Attributed Strings\n\nSyntaxKit also comes with `AttributedParser`. This is a simple subclass of `Parser` that knows how to work with themes.\n\n```swift\nlet tomorrow = Theme(dictionary: themePlist)\nlet attributedParser = AttributedParser(language: yaml, theme: tomorrow)\n\nattributedParser.parse(input) { scope, range, attributes in\n    print(\"\\(scope) - \\(range) - \\(attributes)\")\n}\n```\n\nNotice that `attributes` is the third paramenter to the block now. This is a dictionary of attributes you can give to `NSAttributedString`. Other values may be included here that don't work with `NSAttributedString`. You can do your own inspection and do something custom if you want.\n\n`AttributedParser` includes a convenience method for turning a `String` of source code into an `NSAttributedString`:\n\n```swift\nlet attributedString = attributedParser.attributedStringForString(input)\n```\n\nEasy as that. This method takes an optional `baseAttributes` parameter to customize how the string is created. This is great if you want to specify a font, etc.\n\n\n### Custom Parsers\n\nIf you want to build your own parser (for example, to generate HTML) you can subclass whichever one meets your needs. Go wild.\n\nEnjoy.\n","funding_links":[],"categories":["Libs","Swift"],"sub_categories":["Text"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoffes%2FSyntaxKit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoffes%2FSyntaxKit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoffes%2FSyntaxKit/lists"}