|
| 1 | +*This is a work in progress. PRs to improve these docs (or the process) would be welcome.* |
| 2 | + |
| 3 | +## Getting Started |
| 4 | + |
| 5 | +So you'd like to create and share you're own language for Highlight.js. That's awesome. |
| 6 | + |
| 7 | +Take a look at some of the real-life examples first: |
| 8 | + |
| 9 | +- https://github.com/highlightjs/highlightjs-cypher |
| 10 | +- https://github.com/highlightjs/highlightjs-robots-txt |
| 11 | + |
| 12 | +Basically: |
| 13 | + |
| 14 | +- Checkout highlight-js from github... |
| 15 | +- 3rd party languages are placed into the `extra` directory |
| 16 | + |
| 17 | +So if you had a `xzy` language you'd create an `extra/xyz` folder, and that would be your language module. All paths below are relative to that. |
| 18 | + |
| 19 | +- Put your language file in `src/languages/name.js`. |
| 20 | +- Add detect tests in `test/detect/`. |
| 21 | +- Add markup tests in `test/markup/`. |
| 22 | +- Perhaps add a `package.json` for Node. |
| 23 | +- Add a nice `README`. |
| 24 | +- Don't forget to add a `LICENSE`. |
| 25 | + |
| 26 | + |
| 27 | +## Testing |
| 28 | + |
| 29 | +To test (detect and markup tests), just build highlight.js and test it. Your tests should be automatically run with the suite: |
| 30 | + |
| 31 | +``` |
| 32 | +node ./tools/build.js -t node |
| 33 | +npm run test |
| 34 | +``` |
| 35 | + |
| 36 | +If you can't get the auto-detect tests passing you should simply turn off auto-detection for your language in it's definition with `disableAutodetect: true`. Auto-detection is hard. |
| 37 | + |
| 38 | + |
| 39 | +## Packaging |
| 40 | + |
| 41 | +Users will expect your package to include a minified CDN distributable in your `dist` folder. This should allow them to add the module to their website with only a single `<script>` tag. |
| 42 | + |
| 43 | +Luckily, the highlight.js CDN build process will build this file for you automatically. You can simply commit it to your repo, and done. |
| 44 | + |
| 45 | +``` |
| 46 | +node ./tools/build.js -t cdn |
| 47 | +
|
| 48 | +... |
| 49 | +Building extra/highlightjs-xyz/dist/xyz.min.js. |
| 50 | +... |
| 51 | +``` |
| 52 | + |
| 53 | + |
| 54 | +## Publishing |
| 55 | + |
| 56 | +We're happy to host 3rd party module repos inside the `highlightjs` organization on GitHub. Just file an issue and request a repository. |
| 57 | + |
| 58 | +Publish it to NPM also if you'd like. This will make it much easier for anyone using Node to use it. |
| 59 | + |
| 60 | +When your language module is ready create a PR that adds it to the `README.md` file in the list of languages. |
| 61 | + |
| 62 | + |
| 63 | +## The Future |
| 64 | + |
| 65 | +More work could be done on: |
| 66 | + |
| 67 | +- Allowing you to ONLY run your own tests, not the whole suite. |
| 68 | +- Allowing you to maintain a 3rd party module WITHOUT it being inside of a `highlight-js` checkout (this requires discussion though) |
| 69 | +- Simply make some easier tools or scripts to simply the existing process. |
| 70 | +- Improving these docs |
0 commit comments