-
-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add syntax highlighting documents * More static * More dynamic stuff * More dynamic * Simplify
- Loading branch information
1 parent
905e523
commit 3246766
Showing
5 changed files
with
180 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Dynamic syntax highlighting | ||
|
||
Dynamic syntax highlighting is highlighting of code that the user can change. | ||
There is only one place where this happens, and that is the online editor. | ||
|
||
```exercism/note | ||
Code snippets, iterations, and the like are _static_ as the user can't change their code on the fly. | ||
If you'd like to know more of how we handle static syntax highlighting, check the [static syntax highlighting docs](/docs/building/tracks/new/syntax-highlighting/static). | ||
``` | ||
|
||
## Implementation | ||
|
||
Dynamic syntax highlighting is done using the [CodeMirror library](https://codemirror.net/). | ||
|
||
When adding support for your language, there are three options: | ||
|
||
1. The language is supported _out of the box_ by CodeMirror (i.e. listed as a [supported language](https://codemirror.net/5/mode/)). | ||
If so, continue to the [Enable language](#enable-language) section. | ||
2. The language is supported via an existing CodeMirror plugin. | ||
If so, continue to the [Using an existing plugin](#using-an-existing-plugin) section. | ||
3. The language is _not_ supported. | ||
There are now three options: | ||
1. Write a CodeMirror plugin from scratch, as described in the [Create a new plugin](#create-a-new-plugin) section. | ||
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. | ||
See the [Enable language](#enable-language) section for more information. | ||
3. Don't have dynamic syntax highlighting. | ||
|
||
### Enable language | ||
|
||
To enable CodeMirror support for your language, start a topic on the forum (https://forum.exercism.org/c/exercism/building-exercism/125). | ||
We (Exercism) will then create a Pull Request that enables CodeMirror support for your language on the website. | ||
|
||
### Using an existing plugin | ||
|
||
To use an existing plugin, it needs to be published on [NPM](https://www.npmjs.com/). | ||
|
||
If the plugin isn't published on NPM, you can either: | ||
|
||
1. Ask the plugin author if they want to publish on NPM. | ||
2. Fork the repository and publish it yourself. | ||
3. Have us (Exercism) fork the repository and we publish it. | ||
To do so, open a topic on the forum requesting this (https://forum.exercism.org/c/exercism/building-exercism/125). | ||
|
||
```exercism/note | ||
The CodeMirror website has a [list of community-built language plugins](https://codemirror.net/docs/community/#language). | ||
``` | ||
|
||
The next step is to [Enable language](#enable-language). | ||
|
||
### Create a new plugin | ||
|
||
If you'd like to create plugin, you have two options for hosting: | ||
|
||
1. Create a repository on your personal account and publish it yourself. | ||
2. Have us (Exercism) create a repository and let us publish it. | ||
To do so, open a topic on the forum requesting this (https://forum.exercism.org/c/exercism/building-exercism/125). | ||
|
||
```exercism/note | ||
You could consider forking the [codemirror/lang-example repository](https://github.com/codemirror/lang-example) which implements CodeMirror support for a simple language. | ||
``` | ||
|
||
Once you have a repo, follow the [language package instructions](https://codemirror.net/examples/lang-package/) to implement the plugin. | ||
|
||
You'll then need to publish the plugin on [NPM](https://www.npmjs.com/). | ||
The next step is to [Enable the language](#enable-language). | ||
|
||
### Use a different language | ||
|
||
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. | ||
To do so, configure the track using the other language's CodeMirror plugin. | ||
See the [Enable language](#enable-language) section for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Static syntax highlighting | ||
|
||
Static syntax highlighting is highlighting of code that the user _can't_ change. | ||
This includes code snippets, iterations, and more. | ||
|
||
```exercism/note | ||
The online editor does _not_ use static syntax highlighting as the user can change the code on the fly. | ||
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). | ||
``` | ||
|
||
## Implementation | ||
|
||
Static syntax highlighting is done using the [highlightjs library](https://highlightjs.org/). | ||
|
||
When adding support for your language, there are three options: | ||
|
||
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)). | ||
If so, continue to the [Configuring track](#configuring-track) section. | ||
2. The language is supported via an existing highlightjs plugin. | ||
If so, continue to the [Using an existing plugin](#using-an-existing-plugin) section. | ||
3. The language is _not_ supported. | ||
There are now three options: | ||
1. Write a highlightjs plugin from scratch, as described in the [Create a new plugin](#create-a-new-plugin) section. | ||
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. | ||
See the [Configuring track](#configuring-track) section for more information. | ||
3. Don't have static syntax highlighting. | ||
|
||
### Configuring track | ||
|
||
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). | ||
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). | ||
|
||
#### Example | ||
|
||
```json | ||
{ | ||
"online_editor": { | ||
"highlightjs_language": "csharp" | ||
} | ||
} | ||
``` | ||
|
||
### Using an existing plugin | ||
|
||
To use an existing plugin, it needs to be published on [NPM](https://www.npmjs.com/). | ||
If the plugin isn't published on NPM, you can either: | ||
|
||
1. Ask the plugin author if they want to publish on NPM. | ||
2. Fork the repository and publish it yourself. | ||
3. Have us (Exercism) fork the repository and we publish it. | ||
To do so, open a topic on the forum requesting this (https://forum.exercism.org/c/exercism/building-exercism/125). | ||
|
||
The next step is to [Enable the plugin](#enable-plugin). | ||
|
||
### Enable plugin | ||
|
||
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). | ||
We (Exercism) will then create a Pull Request that adds the plugin to the website. | ||
Once the PR is merged, you can enable highlightjs support by following the instructions in the [Configuring track](#configuring-track) section. | ||
|
||
### Create a new plugin | ||
|
||
If you'd like to create plugin, you have two options for hosting: | ||
|
||
1. Create a repository on your personal account and publish it yourself. | ||
2. Have us (Exercism) create a repository and let us publish it. | ||
To do so, open a topic on the forum requesting this (https://forum.exercism.org/c/exercism/building-exercism/125). | ||
|
||
Once you have a repo, follow the [language contribution instructions](https://highlightjs.readthedocs.io/en/latest/language-contribution.html) to implement the plugin. | ||
|
||
You'll then need to publish the plugin on [NPM](https://www.npmjs.com/). | ||
The next step is to [Enable the plugin](#enable-plugin). | ||
|
||
### Use a different language | ||
|
||
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. | ||
To do so, configure the track to use the other language's highlightjs language identifier. | ||
See the [Configuring track](#configuring-track) section for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Syntax highlighting | ||
|
||
There are two types of syntax highlighting on the website: | ||
|
||
1. Highlighting _static_ code (code snippets, iterations, and such). | ||
Check [static syntax highlighting docs](/docs/building/tracks/new/syntax-highlighting/static) for more information. | ||
2. Highlighting _dynamic_ code (the online editor). | ||
Check [dynamic syntax highlighting docs](/docs/building/tracks/new/syntax-highlighting/dynamic) for more information. | ||
|
||
```exercism/note | ||
The requirements for static and dynamic syntax highlighting are _very_ different, which is why they use different libraries. | ||
``` |