You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The below screenshot was captured from a [demo webpage](demo/testcode.html) after dropping `highlight.min.js` to a `dist` folder.
@@ -8,43 +10,100 @@ The below screenshot was captured from a [demo webpage](demo/testcode.html) afte
8
10
9
11
## Usage
10
12
11
-
Simply include the Highlight.js library in your webpage, then load this module.
13
+
Simply include the Highlight.js library in your webpage or Node app, then load this module.
12
14
13
15
### Static website or simple usage
14
16
15
17
Simply load this module after loading Highlight.js. You'll use the minified version found in the `dist` directory. This module is just a CDN build of the language, so it will register itself as the Javascript is loaded.
For more details of the usage see [Highlight.js main page](https://github.com/highlightjs/highlight.js#highlightjs).
29
+
This will find and highlight code inside of `<pre><code>` tags; it tries to detect the language automatically. If automatic detection doesn’t work for you, you can specify the language in the `class` attribute:
30
+
31
+
```html
32
+
<pre>
33
+
<codeclass="language-apex">
34
+
...
35
+
</code>
36
+
</pre>
37
+
```
38
+
39
+
For more details see [Highlight.js main page](https://github.com/highlightjs/highlight.js#highlightjs).
If you're using Node / Webpack / Rollup / Browserify, etc, simply require the language module, then register it with Highlight.js.
32
53
33
54
```javascript
34
-
var hljs =require('highlight.js');
35
-
varhljsApexTxt=require('highlightjs-apex');
55
+
var hljs =require('highlightjs');
56
+
varhljsApex=require('highlightjs-apex');
36
57
37
-
hljs.registerLanguage('apex', hljsApexTxt);
58
+
hljs.registerLanguage('apex', hljsApex);
38
59
hljs.highlightAll();
39
60
```
40
61
62
+
63
+
### React
64
+
65
+
You need to import both Highlight.js and third-party language like Apex:
66
+
67
+
```js
68
+
importReact, {Component} from'react'
69
+
import'highlight.js/scss/vs.scss' # your favourite theme
70
+
importapexfrom'./apex'
71
+
importhljsfrom'highlight.js'
72
+
hljs.registerLanguage('apex', apex);
73
+
74
+
classHighlighterextendsComponent
75
+
{
76
+
constructor(props)
77
+
{
78
+
super(props);
79
+
hljs.highlightAll();
80
+
}
81
+
82
+
render()
83
+
{
84
+
let {children} =this.props;
85
+
return
86
+
{
87
+
<pre ref={(node) =>this.node= node}>
88
+
<code className="language-apex">
89
+
{children}
90
+
</code>
91
+
</pre>
92
+
}
93
+
}
94
+
}
95
+
96
+
exportdefaultHighlighter;
97
+
```
98
+
41
99
## License
42
100
43
-
Highlight.js is released under the BSD 3-Clause License. See [LICENSE](/LICENSE) file for details.
101
+
Highlight.js is released under the BSD 3-Clause License. See [LICENSE](https://github.com/highlightjs/highlight.js/blob/main/LICENSE) file for details.
102
+
Highlightjs-apex is released under the MIT License. See [LICENSE](/LICENSE.md) file for details.
0 commit comments