{"id":13903086,"url":"https://github.com/NSHipster/SwiftSyntaxHighlighter","last_synced_at":"2025-07-18T00:33:15.684Z","repository":{"id":40346150,"uuid":"154196273","full_name":"NSHipster/SwiftSyntaxHighlighter","owner":"NSHipster","description":"A syntax highlighter for Swift code that uses SwiftSyntax to generate Pygments-compatible HTML.","archived":true,"fork":false,"pushed_at":"2021-05-13T16:05:54.000Z","size":123,"stargazers_count":276,"open_issues_count":0,"forks_count":12,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-10-30T04:32:54.293Z","etag":null,"topics":["pygments","swift","swiftsyntax","syntax-highlighter"],"latest_commit_sha":null,"homepage":"https://nshipster.com/swiftsyntax/","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/NSHipster.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-22T18:38:10.000Z","updated_at":"2024-10-25T10:10:50.000Z","dependencies_parsed_at":"2022-08-03T04:16:05.148Z","dependency_job_id":null,"html_url":"https://github.com/NSHipster/SwiftSyntaxHighlighter","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NSHipster%2FSwiftSyntaxHighlighter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NSHipster%2FSwiftSyntaxHighlighter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NSHipster%2FSwiftSyntaxHighlighter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NSHipster%2FSwiftSyntaxHighlighter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NSHipster","download_url":"https://codeload.github.com/NSHipster/SwiftSyntaxHighlighter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226320884,"owners_count":17606374,"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":["pygments","swift","swiftsyntax","syntax-highlighter"],"created_at":"2024-08-06T22:01:36.716Z","updated_at":"2024-11-25T11:31:16.455Z","avatar_url":"https://github.com/NSHipster.png","language":"Swift","funding_links":[],"categories":["Swift","HarmonyOS"],"sub_categories":["Windows Manager"],"readme":"# SwiftSyntaxHighlighter\n\n![CI][ci badge]\n[![Documentation][documentation badge]][documentation]\n\nA syntax highlighter for Swift code that uses\n[SwiftSyntax](https://github.com/apple/swift-syntax).\nYou can use it either from the command-line,\nvia the `swift-highlight` executable,\nor in Swift code using the `SwiftSyntaxHighlighter` module.\n\nThis functionality is discussed in the NSHipster article\n[SwiftSyntax](https://nshipster.com/swiftsyntax/).\n\n## Requirements\n\n- Swift 5.3+\n\n## Command-Line Usage\n\nThe `swift-highlight` executable can be run from the command line\nto highlight either a path to a source file or source code:\n\n```terminal\n$ swift highlight 'print(\"Hello, world!\")'\n\u003cpre class=\"highlight\"\u003e\u003ccode\u003e\u003cspan class=\"keyword\"\u003elet\u003c/span\u003e \u003cspan class=\"variable\"\u003egreeting\u003c/span\u003e = \u003cspan class=\"string literal\"\u003e\u0026quot;\u003c/span\u003e\u003cspan class=\"string literal\"\u003eHello, world!\u003c/span\u003e\u003cspan class=\"string literal\"\u003e\u0026quot;\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\n```\n\nPass the `--scheme pygments` option\nto generate [Pygments](http://pygments.org)-compatible HTML:\n\n```terminal\n$ swift highlight 'print(\"Hello, world!\")' --scheme pygments\n\u003cpre class=\"highlight\"\u003e\u003ccode\u003e\u003cspan class=\"n\"\u003eprint\u003c/span\u003e\u003cspan class=\"p\"\u003e(\u003c/span\u003e\u003cspan class=\"p\"\u003e\u0026quot;\u003c/span\u003e\u003cspan class=\"s2\"\u003eHello, world!\u003c/span\u003e\u003cspan class=\"p\"\u003e\u0026quot;\u003c/span\u003e\u003cspan class=\"p\"\u003e)\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\n```\n\n`swift-highlight` also accepts arguments piped from standard input (`stdin`):\n\n```terminal\necho 'print(\"Hello, world!\")' | swift highlight\n\u003cpre class=\"highlight\"\u003e\u003ccode\u003e\u003cspan class=\"variable\"\u003eprint\u003c/span\u003e(\u003cspan class=\"string literal\"\u003e\u0026quot;\u003c/span\u003e\u003cspan class=\"string literal\"\u003eHello, world!\u003c/span\u003e\u003cspan class=\"string literal\"\u003e\u0026quot;\u003c/span\u003e)\n\u003c/code\u003e\u003c/pre\u003e\n```\n\n### Installation\n\n#### Homebrew\n\nRun the following command to install using [homebrew](https://brew.sh/):\n\n```terminal\n$ brew install nshipster/formulae/swift-syntax-highlight\n```\n\n#### Manually\n\nRun the following commands to build and install manually:\n\n```terminal\n$ git clone https://github.com/NSHipster/SwiftSyntaxHighlighter.git\n$ cd SwiftSyntaxHighlighter\n$ make install\n```\n\n## Code Usage\n\n`SwiftSyntaxHighlighter` provides type methods named `highlight`\nthat take either\nsource code as a `String`,\na source file `URL`,\nor a `SourceFileSyntax` AST created by SwiftSyntax.\n\n```swift\nimport SwiftSyntaxHighlighter\n\nlet code = \"\"\"\nprint(\"Hello, world!\")\n\"\"\"\n\nlet html = try SwiftSyntaxHighlighter.highlight(source: source, using: Xcode.self)\n```\n\nAfter running this code,\n`html` contains the following string:\n\n```\n\u003cpre class=\"highlight\"\u003e\u003ccode\u003e\u003cspan class=\"keyword\"\u003elet\u003c/span\u003e \u003cspan class=\"variable\"\u003egreeting\u003c/span\u003e = \u003cspan class=\"string literal\"\u003e\u0026quot;\u003c/span\u003e\u003cspan class=\"string literal\"\u003eHello, world!\u003c/span\u003e\u003cspan class=\"string literal\"\u003e\u0026quot;\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\n```\n\n### Installation\n\n#### Swift Package Manager\n\nAdd the SwiftSyntaxHighlighter package to your target dependencies in `Package.swift`:\n\n```swift\nimport PackageDescription\n\nlet package = Package(\n  name: \"YourProject\",\n  dependencies: [\n    .package(\n        url: \"https://github.com/NSHipster/SwiftSyntaxHighlighter\",\n        from: \"1.2.4\"\n    ),\n  ]\n)\n```\n\nThen run the `swift build` command to build your project.\n\n## Known Issues\n\n- Xcode cannot run unit tests (\u003ckbd\u003e⌘\u003c/kbd\u003e\u003ckbd\u003eU\u003c/kbd\u003e)\n  when opening the SwiftSyntaxHighlighter package directly,\n  as opposed first to generating an Xcode project file with\n  `swift package generate-xcodeproj`.\n  (The reported error is:\n  `Library not loaded: @rpath/lib_InternalSwiftSyntaxParser.dylib`).\n  As a workaround,\n  you can [install the latest toolchain](https://swift.org/download/)\n  and enable it in \"Xcode \u003e Preferences \u003e Components \u003e Toolchains\".\n  Alternatively,\n  you can run unit tests from the command line\n  with `swift test`.\n\n## License\n\nMIT\n\n## Contact\n\nMattt ([@mattt](https://twitter.com/mattt))\n\n[ci badge]: https://github.com/NSHipster/SwiftSyntaxHighlighter/workflows/CI/badge.svg\n[documentation badge]: https://github.com/NSHipster/SwiftSyntaxHighlighter/workflows/Documentation/badge.svg\n[documentation]: https://github.com/NSHipster/SwiftSyntaxHighlighter/wiki\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNSHipster%2FSwiftSyntaxHighlighter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FNSHipster%2FSwiftSyntaxHighlighter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNSHipster%2FSwiftSyntaxHighlighter/lists"}