Skip to content

Commit 3246766

Browse files
Add syntax highlighting docs (#548)
* Add syntax highlighting documents * More static * More dynamic stuff * More dynamic * Simplify
1 parent 905e523 commit 3246766

5 files changed

+180
-0
lines changed

building/config.json

+18
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,24 @@
242242
"path": "building/tracks/new/launch.md",
243243
"title": "Launch!"
244244
},
245+
{
246+
"uuid": "81169858-41f0-44da-875c-b1bb432f90b0",
247+
"slug": "tracks/new/syntax-highlighting",
248+
"path": "building/tracks/new/syntax-highlighting.md",
249+
"title": "Enable syntax highlighting"
250+
},
251+
{
252+
"uuid": "374e2596-db7d-433d-b3c0-0f3dc75c453b",
253+
"slug": "tracks/new/syntax-highlighting/static",
254+
"path": "building/tracks/new/static-syntax-highlighting.md",
255+
"title": "Static syntax highlighting"
256+
},
257+
{
258+
"uuid": "a443c67c-fb01-48f0-ab44-8710c065b3ea",
259+
"slug": "tracks/new/syntax-highlighting/dynamic",
260+
"path": "building/tracks/new/dynamic-syntax-highlighting.md",
261+
"title": "Dynamic syntax highlighting"
262+
},
245263
{
246264
"uuid": "f697a7c1-ad33-460c-8458-18cd6d149920",
247265
"slug": "tracks/new/implement-tooling",

building/tracks/new/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ Once you've completed that step, the next steps are:
1717
- [Prepare for launch](/docs/building/tracks/new/prepare-for-launch)
1818
- [Find Maintainers](/docs/building/tracks/new/find-maintainers)
1919
- [Launch!](/docs/building/tracks/new/launch)
20+
- [Enable syntax highlighting](/docs/building/tracks/new/syntax-highlighting)
2021
- [Implement additional tooling](/docs/building/tracks/new/implement-tooling)
2122
- [Prepare for open source contributions from strangers](/docs/building/tracks/new/prepare-for-contributions)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Dynamic syntax highlighting
2+
3+
Dynamic syntax highlighting is highlighting of code that the user can change.
4+
There is only one place where this happens, and that is the online editor.
5+
6+
```exercism/note
7+
Code snippets, iterations, and the like are _static_ as the user can't change their code on the fly.
8+
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).
9+
```
10+
11+
## Implementation
12+
13+
Dynamic syntax highlighting is done using the [CodeMirror library](https://codemirror.net/).
14+
15+
When adding support for your language, there are three options:
16+
17+
1. The language is supported _out of the box_ by CodeMirror (i.e. listed as a [supported language](https://codemirror.net/5/mode/)).
18+
If so, continue to the [Enable language](#enable-language) section.
19+
2. The language is supported via an existing CodeMirror 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 CodeMirror 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 [Enable language](#enable-language) section for more information.
26+
3. Don't have dynamic syntax highlighting.
27+
28+
### Enable language
29+
30+
To enable CodeMirror support for your language, start a topic on the forum (https://forum.exercism.org/c/exercism/building-exercism/125).
31+
We (Exercism) will then create a Pull Request that enables CodeMirror support for your language on the website.
32+
33+
### Using an existing plugin
34+
35+
To use an existing plugin, it needs to be published on [NPM](https://www.npmjs.com/).
36+
37+
If the plugin isn't published on NPM, you can either:
38+
39+
1. Ask the plugin author if they want to publish on NPM.
40+
2. Fork the repository and publish it yourself.
41+
3. Have us (Exercism) fork the repository and we publish it.
42+
To do so, open a topic on the forum requesting this (https://forum.exercism.org/c/exercism/building-exercism/125).
43+
44+
```exercism/note
45+
The CodeMirror website has a [list of community-built language plugins](https://codemirror.net/docs/community/#language).
46+
```
47+
48+
The next step is to [Enable language](#enable-language).
49+
50+
### Create a new plugin
51+
52+
If you'd like to create plugin, you have two options for hosting:
53+
54+
1. Create a repository on your personal account and publish it yourself.
55+
2. Have us (Exercism) create a repository and let us publish it.
56+
To do so, open a topic on the forum requesting this (https://forum.exercism.org/c/exercism/building-exercism/125).
57+
58+
```exercism/note
59+
You could consider forking the [codemirror/lang-example repository](https://github.com/codemirror/lang-example) which implements CodeMirror support for a simple language.
60+
```
61+
62+
Once you have a repo, follow the [language package instructions](https://codemirror.net/examples/lang-package/) to implement the plugin.
63+
64+
You'll then need to publish the plugin on [NPM](https://www.npmjs.com/).
65+
The next step is to [Enable the language](#enable-language).
66+
67+
### Use a different language
68+
69+
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.
70+
To do so, configure the track using the other language's CodeMirror plugin.
71+
See the [Enable language](#enable-language) section for more information.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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.
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Syntax highlighting
2+
3+
There are two types of syntax highlighting on the website:
4+
5+
1. Highlighting _static_ code (code snippets, iterations, and such).
6+
Check [static syntax highlighting docs](/docs/building/tracks/new/syntax-highlighting/static) for more information.
7+
2. Highlighting _dynamic_ code (the online editor).
8+
Check [dynamic syntax highlighting docs](/docs/building/tracks/new/syntax-highlighting/dynamic) for more information.
9+
10+
```exercism/note
11+
The requirements for static and dynamic syntax highlighting are _very_ different, which is why they use different libraries.
12+
```

0 commit comments

Comments
 (0)