{"id":13587002,"url":"https://github.com/sourcegraph/syntect_server","last_synced_at":"2025-04-07T18:35:28.979Z","repository":{"id":47091893,"uuid":"100684623","full_name":"sourcegraph/syntect_server","owner":"sourcegraph","description":"HTTP code syntax highlighting server written in Rust.","archived":true,"fork":false,"pushed_at":"2021-09-13T22:45:47.000Z","size":5596,"stargazers_count":90,"open_issues_count":5,"forks_count":16,"subscribers_count":70,"default_branch":"master","last_synced_at":"2024-05-02T05:14:22.255Z","etag":null,"topics":["http","repo-type-backend","rust","server","syntax-highlighting","syntect"],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sourcegraph.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}},"created_at":"2017-08-18T07:17:52.000Z","updated_at":"2024-03-29T09:02:48.000Z","dependencies_parsed_at":"2022-09-03T21:52:04.220Z","dependency_job_id":null,"html_url":"https://github.com/sourcegraph/syntect_server","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sourcegraph%2Fsyntect_server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sourcegraph%2Fsyntect_server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sourcegraph%2Fsyntect_server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sourcegraph%2Fsyntect_server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sourcegraph","download_url":"https://codeload.github.com/sourcegraph/syntect_server/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223290344,"owners_count":17120894,"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":["http","repo-type-backend","rust","server","syntax-highlighting","syntect"],"created_at":"2024-08-01T15:05:57.541Z","updated_at":"2024-11-06T05:31:04.593Z","avatar_url":"https://github.com/sourcegraph.png","language":"Rust","readme":"# 🚨 Note: this repo has been archived and its contents are now in the [sourcegraph/sourcegraph](https://github.com/sourcegraph/sourcegraph/tree/main/docker-images/syntax-highlighter) repo. \n\n# Syntect Server\n\nThis is an HTTP server that exposes the Rust [Syntect](https://github.com/trishume/syntect) syntax highlighting library for use by other services. Send it some code, and it'll send you syntax-highlighted code in response.\n\nTechnologies:\n\n- [Syntect](https://github.com/trishume/syntect) -\u003e Syntax highlighting of code.\n- [Rocket.rs](https://rocket.rs) -\u003e Web framework.\n- [Serde](https://serde.rs/) -\u003e JSON serialization / deserialization .\n- [Rayon](https://github.com/nikomatsakis/rayon) -\u003e data parallelism for `SyntaxSet` across Rocket server threads.\n- [lazy_static](https://crates.io/crates/lazy_static) -\u003e lazily evaluated static `ThemeSet` (like a global).\n\n## Usage\n\n```bash\ndocker run --detach --name=syntect_server -p 9238:9238 sourcegraph/syntect_server\n```\n\nYou can then e.g. `GET` http://localhost:9238/health or http://host.docker.internal:9238/health to confirm it is working.\n\n## API\n\n- `POST` to `/` with `Content-Type: application/json`. The following fields are required:\n  - `filepath` string, e.g. `the/file.go` or `file.go` or `Dockerfile`, see \"Supported file extensions\" section below.\n  - `theme` string, e.g. `Solarized (dark)`, see \"Embedded themes\" section below.\n  - `code` string, i.e. the literal code to highlight.\n- The response is a JSON object of either:\n  - A successful response (`data` field):\n    - `data` string with syntax highlighted response. The input `code` string [is properly escaped](https://github.com/sourcegraph/syntect_server/blob/ee3810f70e5701b961b7249393dbac8914c162ce/syntect/src/html.rs#L6) and as such can be directly rendered in the browser safely.\n    - `plaintext` boolean indicating whether a syntax could not be found for the file and instead it was rendered as plain text.\n  - An error response (`error` field), one of:\n    - `{\"error\": \"invalid theme\", \"code\": \"invalid_theme\"}`\n    - `{\"error\": \"resource not found\", \"code\": \"resource_not_found\"}`\n- `GET` to `/health` to receive an `OK` health check response / ensure the service is alive.\n\n## Client\n\n[gosyntect](https://github.com/sourcegraph/gosyntect) is a Go package + CLI program to make requests against syntect_server.\n\n## Configuration\n\nBy default on startup, `syntect_server` will list all features (themes + file types) it supports. This can be disabled by setting `QUIET=true` in the environment.\n\n## Development\n\n1. [Install Rust **nightly**](https://rocket.rs/guide/getting-started/#installing-rust).\n2. `git clone` this repository anywhere on your filesystem.\n3. Use `cargo run` to download dependencies + compile + run the server.\n\n## Building\n\nInvoke `cargo build --release` and an optimized binary will be built (e.g. to `./target/release/syntect_server`).\n\n## Building docker image\n\n`./build.sh` will build your current repository checkout into a final Docker image.\n\n## Publishing docker image\n\nRun `./publish.sh` after merging your changes.\n\n## Updating Sourcegraph\n\nOnce published, the image version will need to be updated in the following locations to make Sourcegraph use it:\n\n- [`sourcegraph/sourcegraph \u003e dev/syntect_server.sh`](https://sourcegraph.com/github.com/sourcegraph/sourcegraph/-/blob/dev/syntect_server.sh?subtree=true#L26:82)\n- [`sourcegraph/sourcegraph \u003e docker-images/syntax-highlighter/build.sh`](https://sourcegraph.com/github.com/sourcegraph/sourcegraph/-/blob/docker-images/syntax-highlighter/build.sh?subtree=true#L9:29)\n- [`sourcegraph/sourcegraph \u003e cmd/server/Dockerfile`](https://sourcegraph.com/github.com/sourcegraph/sourcegraph/-/blob/cmd/server/Dockerfile?subtree=true#L54:13)\n- [`sourcegraph/sourcegraph \u003e sg.config.yaml`](https://sourcegraph.com/github.com/sourcegraph/sourcegraph/-/blob/sg.config.yaml?subtree=true#L206:7)\n\nAdditionally, it's worth doing a [search](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/sourcegraph/sourcegraph%24+sourcegraph/syntect_server:\u0026patternType=literal) for other uses in case this list is stale.\n\n## Code hygiene\n\n- Use `cargo fmt` or an editor extension to format code.\n\n## Adding themes\n\n- Copy a `.tmTheme` file anywhere under `./syntect/testdata` (make a new dir if needed) [in our fork](https://github.com/slimsag/syntect).\n- `cd syntect \u0026\u0026 make assets`\n- In this repo, `cargo update -p syntect`.\n- Build a new binary.\n\n## Adding languages:\n\n#### 1) Find an open-source `.tmLanguage` or `.sublime-syntax` file and send a PR to our package registry\n\nhttps://github.com/slimsag/Packages is the package registry we use which holds all of the syntax definitions we use in syntect_server and Sourcegraph. Send a PR there by following [these steps](https://github.com/slimsag/Packages/blob/master/README.md#adding-a-new-language)\n\n#### 2) Update our temporary fork of `syntect`\n\nWe use a temporary fork of `syntect` as a hack to get our `Packages` registry into the binary. Update it by creating a PR with two commits like:\n\n- https://github.com/slimsag/syntect/commit/9976d2095e49fd91607026364466cd7b389b938e\n- https://github.com/slimsag/syntect/commit/1182dd3bd7c82b6655d8466c9896a1e4f458c71e\n\n#### 3) Update syntect_server to use the new version of `syntect`\n\nSend a PR to this repository [with the result of running `cargo update -p syntect`](https://github.com/sourcegraph/syntect_server/commit/1c72addeac3cb54f2c1a7735e8c4ca75eb16d0b3).\n\n#### 4) Publish a new image, use it in Sourcegraph\n\nRun `./publish.sh` to build and release a new image of `syntect_server`, and then send a PR to the main Sourcegraph repository like [this](https://github.com/sourcegraph/sourcegraph/pull/15634/commits/2b8c2a09ab52dbf840495fe0200abd21619b2856). Once merged, it will automatically rollout to Sourcegraph.com and go in the next Sourcegraph release.\n\n## Embedded themes:\n\n- `InspiredGitHub`\n- `Monokai`\n- `Solarized (dark)`\n- `Solarized (light)`\n- `Sourcegraph`\n- `Sourcegraph (light)`\n- `TypeScript`\n- `TypeScriptReact`\n- `Visual Studio`\n- `Visual Studio Dark`\n- `base16-eighties.dark`\n- `base16-mocha.dark`\n- `base16-ocean.dark`\n- `base16-ocean.light`\n\n## Supported file extensions:\n\n- Plain Text (`txt`)\n- ASP (`asa`)\n- HTML (ASP) (`asp`)\n- ASP vb.NET (`vb`)\n- HTML (ASP.net) (`aspx`, `ascx`, `master`)\n- ActionScript (`as`)\n- AppleScript (`applescript`, `script editor`)\n- Batch File (`bat`, `cmd`)\n- NAnt Build File (`build`)\n- C# (`cs`, `csx`)\n- C++ (`cpp`, `cc`, `cp`, `cxx`, `c++`, `C`, `h`, `hh`, `hpp`, `hxx`, `h++`, `inl`, `ipp`)\n- C (`c`, `h`)\n- CMake Cache (`CMakeCache.txt`)\n- CMake Listfile (`CMakeLists.txt`, `cmake`)\n- ACUCOBOL (``)\n- COBOL (`cbl`, `cpy`, `cob`, `dds`, `ss`, `wks`, `pco`)\n- OpenCOBOL (``)\n- jcl (`jcl`)\n- CSS (`css`, `css.erb`, `css.liquid`)\n- Cap’n Proto (`capnp`)\n- Cg (`cg`)\n- Clojure (`clj`, `cljc`, `cljs`, `cljx`, `edn`)\n- Coq (`v`)\n- Crontab (`crontab`)\n- CUDA C++ (`cu`, `cuh`)\n- D (`d`, `di`)\n- DMD Output (``)\n- Dart Doc Comments (``)\n- Dart (`dart`)\n- Diff (`diff`, `patch`)\n- Dockerfile (`Dockerfile`)\n- DM (`dm`, `dme`)\n- Elixir (EEx) (`ex.eex`, `exs.eex`)\n- Elixir (`ex`, `exs`)\n- HTML (EEx) (`html.eex`, `html.leex`)\n- Regular Expressions (Elixir) (`ex.re`)\n- SQL (Elixir) (`ex.sql`)\n- Elm (`elm`)\n- Erlang (`erl`, `hrl`, `Emakefile`, `emakefile`, `escript`)\n- HTML (Erlang) (`yaws`)\n- Solidity (`sol`)\n- Vyper (`vy`)\n- F Sharp (`fs`)\n- friendly interactive shell (fish) (`fish`)\n- Forth (`frt`, `fs`)\n- ESSL (`essl`, `f.essl`, `v.essl`, `_v.essl`, `_f.essl`, `_vs.essl`, `_fs.essl`)\n- GLSL (`vs`, `fs`, `gs`, `vsh`, `fsh`, `gsh`, `vshader`, `fshader`, `gshader`, `vert`, `frag`, `geom`, `tesc`, `tese`, `comp`, `glsl`)\n- Git Attributes (`attributes`, `gitattributes`, `.gitattributes`)\n- Git Commit (`COMMIT_EDITMSG`, `MERGE_MSG`, `TAG_EDITMSG`)\n- Git Common (``)\n- Git Config (`gitconfig`, `.gitconfig`, `.gitmodules`)\n- Git Ignore (`exclude`, `gitignore`, `.gitignore`)\n- Git Link (`.git`)\n- Git Log (`gitlog`)\n- Git Mailmap (`.mailmap`, `mailmap`)\n- Git Rebase Todo (`git-rebase-todo`)\n- Go (`go`)\n- GraphQL (`graphql`, `graphqls`, `gql`, `graphcool`)\n- Graphviz (DOT) (`dot`, `DOT`, `gv`)\n- Groovy (`groovy`, `gvy`, `gradle`, `Jenkinsfile`)\n- HLSL (`fx`, `fxh`, `hlsl`, `hlsli`, `usf`)\n- HTML (`html`, `htm`, `shtml`, `xhtml`)\n- Haskell (`hs`)\n- Literate Haskell (`lhs`)\n- INI (`cfg`, `conf`, `ini`, `lng`, `url`, `.buckconfig`, `.flowconfig`, `.hgrc`)\n- REG (`reg`)\n- JSON (`json`, `sublime-settings`, `sublime-menu`, `sublime-keymap`, `sublime-mousemap`, `sublime-theme`, `sublime-build`, `sublime-project`, `sublime-completions`, `sublime-commands`, `sublime-macro`, `sublime-color-scheme`, `ipynb`, `Pipfile.lock`)\n- Java Server Page (JSP) (`jsp`)\n- Java (`java`, `bsh`)\n- Javadoc (``)\n- Java Properties (`properties`)\n- JS Custom - Default (`js`, `htc`)\n- JS Custom - React (`js`, `jsx`)\n- Regular Expressions (Javascript) (``)\n- JS Custom (Embedded) (``)\n- Julia (`jl`)\n- Kotlin (`kt`, `kts`)\n- LESS (`less`)\n- BibTeX (`bib`)\n- LaTeX Log (``)\n- LaTeX (`tex`, `ltx`)\n- TeX (`sty`, `cls`)\n- Lisp (`lisp`, `cl`, `clisp`, `l`, `mud`, `el`, `scm`, `ss`, `lsp`, `fasl`)\n- Lua (`lua`)\n- MSBuild (`proj`, `targets`, `msbuild`, `csproj`, `vbproj`, `fsproj`, `vcxproj`)\n- Make Output (``)\n- Makefile (`make`, `GNUmakefile`, `makefile`, `Makefile`, `makefile.am`, `Makefile.am`, `makefile.in`, `Makefile.in`, `OCamlMakefile`, `mak`, `mk`)\n- Man (`man`)\n- Markdown (`md`, `mdown`, `markdown`, `markdn`)\n- MultiMarkdown (``)\n- MATLAB (`matlab`)\n- Maven POM (`pom.xml`)\n- Mediawiki (`mediawiki`, `wikipedia`, `wiki`)\n- Move (`move`)\n- Ninja (`ninja`)\n- Nix (`nix`)\n- OCaml (`ml`, `mli`)\n- OCamllex (`mll`)\n- OCamlyacc (`mly`)\n- camlp4 (``)\n- Objective-C++ (`mm`, `M`, `h`)\n- Objective-C (`m`, `h`)\n- PHP Source (``)\n- PHP (`php`, `php3`, `php4`, `php5`, `php7`, `phps`, `phpt`, `phtml`)\n- Regular Expressions (PHP) (``)\n- Pascal (`pas`, `p`, `dpr`)\n- Perl (`pl`, `pc`, `pm`, `pmc`, `pod`, `t`)\n- Property List (XML) (``)\n- Postscript (`ps`, `eps`)\n- PowerShell (`ps1`, `psm1`, `psd1`)\n- Protocol Buffer (`proto`)\n- Puppet (`pp`, `epp`)\n- Python (`py`, `py3`, `pyw`, `pyi`, `pyx`, `pyx.in`, `pxd`, `pxd.in`, `pxi`, `pxi.in`, `rpy`, `cpy`, `SConstruct`, `Sconstruct`, `sconstruct`, `SConscript`, `pyst`, `pyst-include`, `gyp`, `gypi`, `Snakefile`, `vpy`, `wscript`, `bazel`, `bzl`)\n- Regular Expressions (Python) (``)\n- R Console (``)\n- R (`R`, `r`, `Rprofile`)\n- Rd (R Documentation) (`rd`)\n- HTML (Rails) (`rails`, `rhtml`, `erb`, `html.erb`)\n- JavaScript (Rails) (`js.erb`)\n- Ruby Haml (`haml`)\n- Ruby on Rails (`rxml`, `builder`)\n- SQL (Rails) (`erbsql`, `sql.erb`)\n- Regular Expression (`re`)\n- reStructuredText (`rst`, `rest`)\n- Ruby (`rb`, `Appfile`, `Appraisals`, `Berksfile`, `Brewfile`, `capfile`, `cgi`, `Cheffile`, `config.ru`, `Deliverfile`, `Fastfile`, `fcgi`, `Gemfile`, `gemspec`, `Guardfile`, `irbrc`, `jbuilder`, `Podfile`, `podspec`, `prawn`, `rabl`, `rake`, `Rakefile`, `Rantfile`, `rbx`, `rjs`, `ruby.rail`, `Scanfile`, `simplecov`, `Snapfile`, `thor`, `Thorfile`, `Vagrantfile`)\n- Cargo Build Results (``)\n- Rust Enhanced (`rs`)\n- Sass (`sass`, `scss`)\n- SQL (`sql`, `ddl`, `dml`)\n- Scala (`scala`, `sbt`, `sc`)\n- Bourne Again Shell (bash) (`sh`, `bash`, `zsh`, `ash`, `.bash_aliases`, `.bash_completions`, `.bash_functions`, `.bash_login`, `.bash_logout`, `.bash_profile`, `.bash_variables`, `.bashrc`, `.profile`, `.textmate_init`, `.zlogin`, `.zlogout`, `.zprofile`, `.zshenv`, `.zshrc`, `PKGBUILD`, `.ebuild`, `.eclass`)\n- Shell-Unix-Generic (``)\n- commands-builtin-shell-bash (``)\n- Smalltalk (`st`)\n- Smarty (`tpl`)\n- Starlark (`build_defs`, `BUILD.in`, `BUILD`, `WORKSPACE`, `bzl`, `sky`, `star`, `BUILD.bazel`, `WORKSPACE`, `WORKSPACE.bazel`)\n- Stylus (`styl`, `stylus`)\n- Swift (`swift`)\n- HTML (Tcl) (`adp`)\n- Tcl (`tcl`)\n- TOML (`toml`)\n- Terraform (`tf`, `tfvars`, `hcl`)\n- Textile (`textile`)\n- Thrift (`thrift`, `frugal`)\n- TypeScript (`ts`)\n- TypeScriptReact (`tsx`)\n- VimL (`vim`, `.vimrc`, `.gvimrc`)\n- Vue Component (`vue`)\n- XML (`xml`, `xsd`, `xslt`, `tld`, `dtml`, `rng`, `rss`, `opml`, `svg`)\n- YAML (`yaml`, `yml`, `sublime-syntax`)\n- Zig (`zig`)\n","funding_links":[],"categories":["Rust"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsourcegraph%2Fsyntect_server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsourcegraph%2Fsyntect_server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsourcegraph%2Fsyntect_server/lists"}