├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── examples ├── app │ ├── index.js │ └── input.md └── run.js ├── index.js ├── package-lock.json ├── package.json └── test.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | output/ 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "10" 4 | - "12" 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Juho Vepsalainen 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![build status](https://secure.travis-ci.org/bebraw/highlight-loader.png)](http://travis-ci.org/bebraw/highlight-loader) 2 | # highlight-loader - Applies highlight.js to given module 3 | 4 | This loader can apply syntax-highlighting via [highlight.js](https://www.npmjs.com/package/highlight.js) in two ways: 5 | 6 | 1. Given HTML (either straight HTML or the output of something like [markdown-loader](https://github.com/peerigon/markdown-loader)), it will replace the contents of `` blocks with syntax-highlighted HTML generated by highlight.js. This is the default behavior. 7 | 8 | 2. Given a raw file, it will return syntax-highlighted HTML generated by highlight.js. This can be enabled by using the `raw` parameter. 9 | 10 | You probably want to pass the HTML output of this loader through [html-loader](https://github.com/webpack/html-loader). 11 | 12 | ## Parameters 13 | 14 | ### raw 15 | 16 | If any value is provided, the loader will interpret its input as a raw string to run through highlight.js. 17 | 18 | By default, the language is auto-detected. To specify a language, use the `lang` parameter. 19 | 20 | ### lang 21 | 22 | Specify a language for highlight.js. Only works in combination with the `raw` parameter. 23 | 24 | (To specify a language for non-raw input, apply `lang-[something]` classes to your `` blocks.) 25 | 26 | ### exec 27 | 28 | Execute the input that `highlight-loader` receives. Useful in cases when chaining another loader which returns a function. One use case is to combine this with the [apply-loader](https://github.com/mogelbrod/apply-loader). 29 | 30 | By default, exec is `false` and simply treats its input as a string. 31 | 32 | ## Installation 33 | 34 | Install with npm: 35 | 36 | ```bash 37 | npm install highlight-loader --save-dev 38 | ``` 39 | 40 | Make sure [`highlightjs`](https://github.com/isagalaev/highlight.js) is included and initialized on your page. 41 | 42 | ## Usage 43 | 44 | Add `highlight-loader` as a [webpack loader](https://webpack.github.io/docs/loaders.html): 45 | 46 | ```javascript 47 | module: { 48 | loaders: [ 49 | { 50 | test: /\.md$/, 51 | loader: 'html!highlight!markdown', 52 | include: PATHS.markdown 53 | } 54 | ] 55 | } 56 | ``` 57 | 58 | ## Examples 59 | 60 | ```javascript 61 | // Reading HTML from parsed markdown 62 | var highlightedMarkdown = require('html!highlight!markdown!./README.md'); 63 | 64 | // Reading a file's raw contents and auto-detecting the language 65 | var highlightedRaw = require('html!highlight?raw=true!./example-script.js'); 66 | 67 | // Reading a file's raw contents and specifying the language 68 | var highlightedRawCss = require('html!highlight?raw=true&lang=css!./example-stylesheet.css'); 69 | 70 | // Reading HTML from a template loader 71 | var highlightedRenderedJadeTemplate = require('html!highlight?exec!apply!jade!./index.jade') 72 | ``` 73 | 74 | ## Contributors 75 | 76 | * [David Clark](https://github.com/davidtheclark) - Added `raw` and `lang` parameters 77 | * [Zane Miller](https://github.com/ZaneMiller) - Added missing `hljs` class to `pre` element 78 | * [Javier Castro](https://github.com/jacargentina) - Added Node support 79 | * [Sidd Sridharan](https://github.com/sidd) - Added support for `exec` parameter 80 | * [M.K. Safi](https://github.com/msafi) - Added installation instructions 81 | 82 | ## License 83 | 84 | highlight-loader is available under MIT. See LICENSE for more details. 85 | -------------------------------------------------------------------------------- /examples/app/index.js: -------------------------------------------------------------------------------- 1 | require('./input'); 2 | 3 | -------------------------------------------------------------------------------- /examples/app/input.md: -------------------------------------------------------------------------------- 1 | # Demo 2 | 3 | This is just some **demo** and `something that should not get highlighted`. 4 | 5 | Just go and `run