Skip to content

Commit 6dea56b

Browse files
committed
Add additional documentation for code highlighting
1 parent 9c080a3 commit 6dea56b

File tree

2 files changed

+98
-5
lines changed

2 files changed

+98
-5
lines changed

exampleSite/content/cont/markdown.en.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ and this HTML:
164164
<em>rendered as italicized text</em>
165165
```
166166

167-
### strikethrough
167+
### Strikethrough
168168

169169
In GFM (GitHub flavored Markdown) you can do strikethroughs.
170170

@@ -420,7 +420,7 @@ HTML:
420420

421421
Use "fences" ```` ``` ```` to block in multiple lines of code.
422422

423-
```markup
423+
```markdown
424424
Sample text here...
425425
```
426426

@@ -434,9 +434,13 @@ HTML:
434434

435435
### Syntax highlighting
436436

437-
GFM, or "GitHub Flavored Markdown" also supports syntax highlighting. To activate it, simply add the file extension of the language you want to use directly after the first code "fence", ` ```js `, and syntax highlighting will automatically be applied in the rendered HTML. For example, to apply syntax highlighting to JavaScript code:
437+
GFM, or "GitHub Flavored Markdown" also supports syntax highlighting. To activate it, simply add the file extension of the language you want to use directly after the first code "fence", ` ```js `, and syntax highlighting will automatically be applied in the rendered HTML.
438438

439-
<!-- markdownlint-disable MD046 -->
439+
See [Code Highlighting]({{< ref "syntaxhighlight.md" >}}) for additional documentation.
440+
441+
For example, to apply syntax highlighting to JavaScript code:
442+
443+
```plaintext
440444
```js
441445
grunt.initConfig({
442446
assemble: {
@@ -457,7 +461,7 @@ GFM, or "GitHub Flavored Markdown" also supports syntax highlighting. To activat
457461
}
458462
};
459463
```
460-
<!-- markdownlint-disable MD046 -->
464+
```
461465

462466
Renders to:
463467

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
---
2+
date: 2020-06-01T13:31:12+01:00
3+
title: Code highlighting
4+
weight: 16
5+
---
6+
7+
Learn theme uses [highlight.js](https://highlightjs.org/) to provide code syntax highlighting.
8+
9+
## Markdown syntax
10+
11+
Wrap the code block with three backticks and the name of the language. Highlight will try to auto detect the language if one is not provided.
12+
13+
<!-- markdownlint-disable MD046 -->
14+
```plaintext
15+
```json
16+
[
17+
{
18+
"title": "apples",
19+
"count": [12000, 20000],
20+
"description": {"text": "...", "sensitive": false}
21+
},
22+
{
23+
"title": "oranges",
24+
"count": [17500, null],
25+
"description": {"text": "...", "sensitive": false}
26+
}
27+
]
28+
```
29+
```
30+
<!-- markdownlint-disable MD046 -->
31+
32+
Renders to:
33+
34+
```json
35+
[
36+
{
37+
"title": "apples",
38+
"count": [12000, 20000],
39+
"description": {"text": "...", "sensitive": false}
40+
},
41+
{
42+
"title": "oranges",
43+
"count": [17500, null],
44+
"description": {"text": "...", "sensitive": false}
45+
}
46+
]
47+
```
48+
49+
## Supported languages
50+
51+
Learn theme ships with its own version of highlight.js to support offline browsing. The included package supports 38 common languages, as described on the [highlight.js download page](https://highlightjs.org/download/).
52+
53+
## Identifying failed language detection
54+
55+
Highlight will write a warning to the browser console if a requested language was not found. For example, the following code block references an imaginary language `foo`. An error will be output to the console on this page.
56+
57+
```plaintext
58+
```foo
59+
bar
60+
```
61+
```
62+
63+
```nohighlight
64+
Could not find the language 'foo', did you forget to load/include a language module?(anonymous) @ highlight.pack.js
65+
```
66+
67+
## Supporting additional languages
68+
69+
To support languages other than the 38 common languages included in the default highlight.js you will need to download your own version of highlight.js and add it to your site content.
70+
71+
### Download custom highlight.js
72+
73+
Visit [https://highlightjs.org/download/](https://highlightjs.org/download/) and select your desired language support. Note that more languages means greater package size.
74+
75+
### Add custom highlight.js to static resources
76+
77+
Inside the zip archive downloaded from highlight.js extract the file named `highlight.pack.js`. Move this file to the **new** location
78+
79+
```nohighlight
80+
static/js/highlight.pack.js
81+
```
82+
83+
**Do not** replace the existing file at `themes/hugo-theme-learn/static/js/highlight.pack.js`.
84+
85+
Including the file in the correct path will override the theme default highlight.pack.js and prevent issues caused in the future if the theme default file is updated.
86+
87+
## Further usage information
88+
89+
See [https://highlightjs.org/usage/](https://highlightjs.org/usage/)

0 commit comments

Comments
 (0)