Skip to content

Commit 4901990

Browse files
authored
Merge pull request #1 from highlightjs/npm
NPM packaging
2 parents 5f00ee2 + ad35f1e commit 4901990

File tree

2 files changed

+70
-10
lines changed

2 files changed

+70
-10
lines changed

README.md

+68-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Apex - a language grammar for the [Salesforce Platform](https://developer.salesforce.com)
22

3+
[![NPM](https://nodei.co/npm/highlightjs-apex.png)](https://npmjs.org/package/highlightjs-apex)
4+
35
## Demo
46

57
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
810

911
## Usage
1012

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.
1214

1315
### Static website or simple usage
1416

1517
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.
1618

1719
```html
1820
<script type="text/javascript" src="/path/to/highlight.min.js"></script>
19-
<script type="text/javascript" src="/path/to/highlightjs-apex/dist/apex.min.js"></script>
21+
<script type="text/javascript" src="/path/to/apex.min.js"></script>
2022
<!-- Use any stylesheet you'd like - though it's best to choose from those in highlightjs core repo -->
21-
<link rel="stylesheet" href="/path/to/highlightjs-apex/demo/highlight.css" />
23+
<link rel="stylesheet" href="https://unpkg.com/highlightjs/styles/vs.css" />
2224
<script type="text/javascript">
2325
hljs.highlightAll();
2426
</script>
2527
```
2628

27-
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+
<code class="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).
40+
41+
### Using directly from the UNPKG CDN
42+
43+
```html
44+
<script type="text/javascript"
45+
src="https://unpkg.com/highlightjs-apex/dist/apex.min.js"></script>
46+
```
47+
48+
- More info: <https://unpkg.com>
2849

2950
### With Node or another build system
3051

3152
If you're using Node / Webpack / Rollup / Browserify, etc, simply require the language module, then register it with Highlight.js.
3253

3354
```javascript
34-
var hljs = require('highlight.js');
35-
var hljsApexTxt = require('highlightjs-apex');
55+
var hljs = require('highlightjs');
56+
var hljsApex = require('highlightjs-apex');
3657

37-
hljs.registerLanguage('apex', hljsApexTxt);
58+
hljs.registerLanguage('apex', hljsApex);
3859
hljs.highlightAll();
3960
```
4061

62+
63+
### React
64+
65+
You need to import both Highlight.js and third-party language like Apex:
66+
67+
```js
68+
import React, {Component} from 'react'
69+
import 'highlight.js/scss/vs.scss' # your favourite theme
70+
import apex from './apex'
71+
import hljs from 'highlight.js'
72+
hljs.registerLanguage('apex', apex);
73+
74+
class Highlighter extends Component
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+
export default Highlighter;
97+
```
98+
4199
## License
42100

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.
44103

45104
## Author
46105

47-
[David Schach](https://github.com/dschach)
106+
David Schach [[David Schach](https://github.com/dschach)](https://github.com/dschach)
48107

49108
## Contribution
50109

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"scripts": {
77
"test": "./node_modules/.bin/mocha --reporter spec",
88
"mocha": "mocha test/markup",
9-
"changelog": "auto-changelog --output HISTORY.md --hide-credit -p --commit-limit false"
9+
"changelog": "auto-changelog --output HISTORY.md --hide-credit -p --commit-limit false",
10+
"npm-patch": "npm version patch && npm publish"
1011
},
1112
"repository": {
1213
"type": "git",

0 commit comments

Comments
 (0)