|
| 1 | +# Static syntax highlighting |
| 2 | + |
| 3 | +Static syntax highlighting is highlighting of code that the user _can't_ change. |
| 4 | +This includes code snippets, iterations, and more. |
| 5 | + |
| 6 | +```exercism/note |
| 7 | +The online editor does _not_ use static syntax highlighting as the user can change the code on the fly. |
| 8 | +If you'd like to know more of how we handle syntax highlighting in the online editor, check the [dynamic syntax highlighting docs](/docs/building/tracks/new/syntax-highlighting/dynamic). |
| 9 | +``` |
| 10 | + |
| 11 | +## Implementation |
| 12 | + |
| 13 | +Static syntax highlighting is done using the [highlightjs library](https://highlightjs.org/). |
| 14 | + |
| 15 | +When adding support for your language, there are three options: |
| 16 | + |
| 17 | +1. The language is supported _out of the box_ by highlightjs (i.e. listed as a [supported language](https://github.com/highlightjs/highlight.js/blob/main/SUPPORTED_LANGUAGES.md)). |
| 18 | + If so, continue to the [Configuring track](#configuring-track) section. |
| 19 | +2. The language is supported via an existing highlightjs plugin. |
| 20 | + If so, continue to the [Using an existing plugin](#using-an-existing-plugin) section. |
| 21 | +3. The language is _not_ supported. |
| 22 | + There are now three options: |
| 23 | + 1. Write a highlightjs plugin from scratch, as described in the [Create a new plugin](#create-a-new-plugin) section. |
| 24 | + 2. Your language's syntax (closely) resembles another language's syntax (e.g. Unison's syntax resembles Haskell), in which case you could consider using the syntax highlighting of that language for your language. |
| 25 | + See the [Configuring track](#configuring-track) section for more information. |
| 26 | + 3. Don't have static syntax highlighting. |
| 27 | + |
| 28 | +### Configuring track |
| 29 | + |
| 30 | +To enable highlightjs support for your track's language, you'll need to modify the track's [config.json file](/docs/building/tracks/config-json). |
| 31 | +Within the `config.json` file, add/set the `online_editor.highlightjs_language` key to the appropriate highlightjs language identifier (which can be found in the documentation). |
| 32 | + |
| 33 | +#### Example |
| 34 | + |
| 35 | +```json |
| 36 | +{ |
| 37 | + "online_editor": { |
| 38 | + "highlightjs_language": "csharp" |
| 39 | + } |
| 40 | +} |
| 41 | +``` |
| 42 | + |
| 43 | +### Using an existing plugin |
| 44 | + |
| 45 | +To use an existing plugin, it needs to be published on [NPM](https://www.npmjs.com/). |
| 46 | +If the plugin isn't published on NPM, you can either: |
| 47 | + |
| 48 | +1. Ask the plugin author if they want to publish on NPM. |
| 49 | +2. Fork the repository and publish it yourself. |
| 50 | +3. Have us (Exercism) fork the repository and we publish it. |
| 51 | + To do so, open a topic on the forum requesting this (https://forum.exercism.org/c/exercism/building-exercism/125). |
| 52 | + |
| 53 | +The next step is to [Enable the plugin](#enable-plugin). |
| 54 | + |
| 55 | +### Enable plugin |
| 56 | + |
| 57 | +To enable a plugin (which must be published on [NPM](https://www.npmjs.com/)), start a topic on the forum requesting us to add support for the plugin to the website (https://forum.exercism.org/c/exercism/building-exercism/125). |
| 58 | +We (Exercism) will then create a Pull Request that adds the plugin to the website. |
| 59 | +Once the PR is merged, you can enable highlightjs support by following the instructions in the [Configuring track](#configuring-track) section. |
| 60 | + |
| 61 | +### Create a new plugin |
| 62 | + |
| 63 | +If you'd like to create plugin, you have two options for hosting: |
| 64 | + |
| 65 | +1. Create a repository on your personal account and publish it yourself. |
| 66 | +2. Have us (Exercism) create a repository and let us publish it. |
| 67 | + To do so, open a topic on the forum requesting this (https://forum.exercism.org/c/exercism/building-exercism/125). |
| 68 | + |
| 69 | +Once you have a repo, follow the [language contribution instructions](https://highlightjs.readthedocs.io/en/latest/language-contribution.html) to implement the plugin. |
| 70 | + |
| 71 | +You'll then need to publish the plugin on [NPM](https://www.npmjs.com/). |
| 72 | +The next step is to [Enable the plugin](#enable-plugin). |
| 73 | + |
| 74 | +### Use a different language |
| 75 | + |
| 76 | +Your language's syntax (closely) resembles another language's syntax, in which case you could consider using the syntax highlighting of that language for your language. |
| 77 | +To do so, configure the track to use the other language's highlightjs language identifier. |
| 78 | +See the [Configuring track](#configuring-track) section for more information. |
0 commit comments