Skip to content

Commit a9a3981

Browse files
authored
Use proper syntax highlighting for code blocks (facebook#615)
* Better syntax highlighting * Better syntax highlighting
1 parent 327ef85 commit a9a3981

21 files changed

+268
-227
lines changed

CONTRIBUTING.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ A good test plan has the exact commands you ran and their output, provides scree
109109

110110
When adding a new breaking change, follow this template in your pull request:
111111

112-
```
112+
```md
113113
### New breaking change here
114114

115115
* **Who does this affect**:
@@ -122,7 +122,7 @@ When adding a new breaking change, follow this template in your pull request:
122122

123123
Copy and paste this to the top of your new file(s):
124124

125-
```JS
125+
```js
126126
/**
127127
* Copyright (c) 2017-present, Facebook, Inc.
128128
*

admin/extending-remarkable.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ Docusaurus uses [Remarkable](https://github.com/jonschlinkert/remarkable) to con
44

55
Users of GitHub Pages have come to expect certain features provided by GitHub Flavored Markdown. One such example would be heading anchors, where every sub-header has an associated anchor that matches the heading text. This makes it possible to link to a specific section in a document by passing a fragment that matches the heading. For example, to link to this very section, you may create a link like so:
66

7-
```
8-
[Link to this section](#why-extend-remarkable)
7+
```md
8+
[Link to this section](#why-extend-remarkable)
99
```
1010

1111
## A Brief Overview of How A Markdown Parser/Renderer Works
@@ -26,7 +26,7 @@ Inline tokens are simple tokens that have text as a child. They are leaf nodes,
2626

2727
A block token is a bit more complex. It may wrap one or more tokens, and can span more than one line of text. An example of this is the heading token:
2828

29-
```
29+
```md
3030
### Hi there
3131
```
3232

@@ -52,7 +52,7 @@ Now that you have a better idea of how parsing/rendering works, we can proceed t
5252

5353
The default heading renderers may look like this (you can refer to the Remarkable source code here):
5454

55-
```
55+
```js
5656
md.renderer.rules.heading_open = function(tokens, idx /*, options, env */) {
5757
return '<h' + tokens[idx].hLevel + '>';
5858
};
@@ -64,13 +64,13 @@ md.renderer.rules.heading_close = function(tokens, idx /*, options, env */) {
6464

6565
That's pretty straightforward: whenever these tokens are found, we render a `<hN>` or `</hN>` HTML tag, where N is the `hLevel` for this heading. That would result in `<h3>Hi there</h3>` being output. But what we want is something closer to this:
6666

67-
```
67+
```html
6868
<h3><a class="anchor" id="hi-there"></a>Hi there <a class="hash-link" href="#hi-there">#</a></h3>
6969
```
7070

7171
In that case, we need to override our heading rules like so:
7272

73-
```
73+
```js
7474
md.renderer.rules.heading_open = function(tokens, idx /*, options, env */) {
7575
return '<h' + tokens[idx].hLevel + '>' + '<a class="anchor" id="' + toSlug(tokens[idx+1].content) + '"></a>';
7676
};
@@ -86,7 +86,7 @@ Note that we are referring to `tokens[idx+1]` and `tokens[idx-1]` at various poi
8686

8787
We now need to tell Remarkable to use our extension. We can wrap our rules in a function called `anchors`:
8888

89-
```
89+
```js
9090
function anchors(md) {
9191
md.renderer.rules.heading_open = function(tokens, idx /*, options, env */) {
9292
return '<h' + tokens[idx].hLevel + '>' + '<a class="anchor" id="' + toSlug(tokens[idx+1].content) + '"></a>';
@@ -100,10 +100,10 @@ function anchors(md) {
100100

101101
We can now tell Remarkable to load this function as a plugin (`md` is our instance of Remarkable):
102102

103-
```
103+
```js
104104
this.md.use(anchors);
105105
```
106106

107107
### Future Work
108108

109-
A more advanced extension might add additional parser rules. These rules may add support for new markdown syntax not covered by Remarkable. Say, for example, a custom syntax to embed video when a tag like `@video` is found can be supported by generating a new type of token, that is later used by the renderer to output the necessary `<embed>` HTML tags. This is left as an exercise to the reader for now.
109+
A more advanced extension might add additional parser rules. These rules may add support for new markdown syntax not covered by Remarkable. Say, for example, a custom syntax to embed video when a tag like `@video` is found can be supported by generating a new type of token, that is later used by the renderer to output the necessary `<embed>` HTML tags. This is left as an exercise to the reader for now.

admin/local-third-party-project-testing.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ There are two reasonable ways to use a local version of the Docusaurus npm packa
1010
1111
### Install the package from the Docusaurus repo
1212

13-
```
13+
```bash
1414
cd /path/to/testing_project
1515
mkdir website # if this does not exist already
1616
cd website
1717
```
1818

1919
If you do not have a `package.json` file in the `website` directory, create one with the following content:
2020

21-
```
21+
```json
2222
{
2323
"scripts": {
2424
"start": "docusaurus-start",
@@ -31,7 +31,7 @@ If you do not have a `package.json` file in the `website` directory, create one
3131

3232
Then:
3333

34-
```
34+
```sh
3535
# Path to your Docusaurus clone
3636
npm install ../../path/to/docusaurus/
3737
```
@@ -46,7 +46,7 @@ Error: Couldn't find preset "react" relative to directory
4646

4747
So, you should install these packages locally. **Base the versions on the versions defined in the Docusaurus `package.json`**. e.g.,
4848

49-
```
49+
```bash
5050
# Still in the website directory of the testing project
5151
npm install babel-plugin-transform-class-properties@^6.24.1
5252
npm install babel-plugin-transform-object-rest-spread@^6.26.0
@@ -57,7 +57,7 @@ npm install babel-preset-react@^6.24.0
5757

5858
### Test
5959

60-
```
60+
```bash
6161
./node_modules/.bin/docusaurus-examples # or whatever you want to test, if anything
6262
./node_modules/.bin/docusaurus-start
6363
```
@@ -68,7 +68,7 @@ Verdaccio is a good local npm server that you can use to test your packages.
6868

6969
### Install verdaccio
7070

71-
```
71+
```bash
7272
npm install --global verdaccio
7373
```
7474

@@ -78,13 +78,13 @@ When you are ready to test the code that could make up the next version of your
7878

7979
Run verdaccio in a **separate terminal window**:
8080

81-
```
81+
```bash
8282
verdaccio
8383
```
8484

8585
In another terminal window, get ready to publish your local npm package:
8686

87-
```
87+
```bash
8888
# Your clone of Docusaurus
8989
cd /path/to/docusaurus/
9090

@@ -101,15 +101,15 @@ You can navigate to localhost:4873 and you can see that your package was publish
101101

102102
Now install the package in the repo you want to test Docusaurus on.
103103

104-
```
104+
```bash
105105
cd /path/to/testing_project/
106106
mkdir website # if this does not exist already
107107
cd website
108108
```
109109

110110
If you do not have a `package.json` file in the `website` directory, create one with the following content:
111111

112-
```
112+
```json
113113
{
114114
"scripts": {
115115
"start": "docusaurus-start",
@@ -122,7 +122,7 @@ If you do not have a `package.json` file in the `website` directory, create one
122122

123123
Then:
124124

125-
```
125+
```bash
126126
npm install docusaurus --registry http://localhost:4873 # this may be slower than the normal npm registry
127127
npm run examples # or whatever you want to test, if anything
128128
npm run start

admin/publish.md

+10-7
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@ If you are not currently logged into npm locally:
1818

1919
The version number should generally increase by some factor than the current one. You can check current version by looking in `package.json`.
2020

21-
```
22-
"name": "docusaurus",
23-
"version": "1.0.0-alpha.41",
24-
"repository": {
25-
"type": "git",
26-
"url": "https://github.com/facebook/Docusaurus.git"
27-
},
21+
```json
22+
{
23+
"name": "docusaurus",
24+
"version": "1.0.0-alpha.41",
25+
"repository": {
26+
"type": "git",
27+
"url": "https://github.com/facebook/Docusaurus.git"
28+
}
29+
...
30+
}
2831
```
2932

3033
For the above example, you may want to bump the version to `1.0.0-alpha.42` or `1.0.0-beta.1` or `1.0.1`.

admin/testing-changes-on-Docusaurus-itself.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ If you are developing the Docusaurus core and you want a quick way to test your
66

77
It is straightforward to test your Docusaurus changes with Docusaurus.
88

9-
```
9+
```bash
1010
cd /path/to/docusaurus-repo
1111
npm install
1212
cd website
@@ -21,7 +21,7 @@ npm run start
2121

2222
Use the following code in VSCode to enable breakpoints. Please ensure you have a later version of node for non-legacy debugging.
2323

24-
```
24+
```json
2525
{
2626
"version": "0.2.0",
2727
"configurations": [

docs/api-commands.md

+11-4
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ Docusaurus provides a set of scripts to help you generate, serve, and deploy you
1313

1414
The scripts can be run using either Yarn or npm. If you've already gone through our Getting Started guide, you may already be familiar with the `start` command. It's the command that tells Docusaurus to run the `docusaurus-start` script which generates the site and starts up a server, and it's usually invoked like so:
1515

16-
```
16+
```bash
1717
yarn run start
1818
```
1919

2020
The same script can be invoked using npm:
2121

22-
```
22+
```bash
2323
npm run start
2424
```
2525

@@ -29,13 +29,13 @@ To run a particular script, just replace the `start` command in the examples abo
2929

3030
Some commands support optional arguments. For example, to start a server on port 8080, you can specify the `--port` argument when running `start`:
3131

32-
```
32+
```bash
3333
yarn run start --port 8080
3434
```
3535

3636
If you run Docusaurus using npm, you can still use the command line arguments by inserting a `--` between `npm run <command>` and the command arguments:
3737

38-
```
38+
```bash
3939
npm run start -- --port 8080
4040
```
4141

@@ -54,6 +54,7 @@ Docusaurus provides some default mappings to allow you to run commands following
5454
## Reference
5555

5656
### `docusaurus-build`
57+
5758
Alias: `build`.
5859

5960
Generates the static website, applying translations if necessary. Useful for building the website prior to deployment.
@@ -63,13 +64,15 @@ See also [`docusaurus-start`](api-commands.md#docusaurus-start-port-number).
6364
---
6465

6566
### `docusaurus-examples [feature]`
67+
6668
Alias: `examples`
6769

6870
When no feature is specified, sets up a minimally configured example website in your project. This command is covered in depth in the [Site Preparation guide](getting-started-preparation.md). Specify a feature `translations` or `versions` to generate the extra example files for that feature.
6971

7072
---
7173

7274
### `docusaurus-publish`
75+
7376
Alias: `publish-gh-pages`
7477

7578
[Builds](api-commands.md#docusaurus-build), then deploys the static website to GitHub Pages. This command is meant to be run during the deployment step in Circle CI, and therefore expects a few environment variables to be defined:
@@ -100,6 +103,7 @@ You can learn more about configuring automatic deployments with CircleCI in the
100103
---
101104

102105
### `docusaurus-rename-version <currentVersion> <newVersion>`
106+
103107
Alias: `rename-version`
104108

105109
Renames an existing version of the docs to a new version name.
@@ -109,13 +113,15 @@ See the [Versioning guide](guides-versioning.md#renaming-existing-versions) to l
109113
---
110114

111115
### `docusaurus-start [--port <number>]`
116+
112117
Alias: `start`.
113118

114119
This script will build the static website, apply translations if necessary, and then start a local server. The website will be served from port 3000 by default.
115120

116121
---
117122

118123
### `docusaurus-version <version>`
124+
119125
Alias: `version`
120126

121127
Generates a new version of the docs. This will result in a new copy of your site being generated and stored in its own versioned folder. Useful for capturing snapshots of API docs that map to specific versions of your software. Accepts any string as a version number.
@@ -125,6 +131,7 @@ See the [Versioning guide](guides-versioning.md) to learn more.
125131
---
126132

127133
### `docusaurus-write-translations`
134+
128135
Alias: `write-translations`
129136

130137
Writes the English for any strings that need to be translated into an `website/i18n/en.json` file. The script will go through every file in `website/pages/en` and through the `siteConfig.js` file and other config files to fetch English strings that will then be translated on Crowdin. See the [Translation guide](guides-translation.md) to learn more.

0 commit comments

Comments
 (0)