highlight.js-async-webpack

webpack async for highlight.js

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
highlight.js-async-webpack
011.0.46 years ago6 years agoMinified + gzip package size for highlight.js-async-webpack in KB

Readme

highlight.js-async-webpack
async language request from highlight.js

Install

npm install highlight.js-async-webpack

Usage

import hljs from 'highlight.js-async-webpack'
hljs.hljsBlock(dom, lang, function(){
// do something...
});

Example

function highLightCodex(str, callback) {
    var dom = document.createElement('div');
    dom.innerHTML = str;
    var pre_code = dom.querySelectorAll('pre.hljs > code');
    if (pre_code) {
        var cnt = 0;
        var deal = 0;
        for (var i = 0; i < pre_code.length; i++) {
            if (pre_code[i].className.length > 0) {
                cnt = cnt + 1;
                hljs.hljsBlock(pre_code[i], pre_code[i].className, function() {
                    deal = deal + 1;
                    if (deal == cnt) {
                        callback(dom.innerHTML);
                    }
                });
            }
        }
    }
}

Version

  • 1.0.4 If highlight error return false.
  • 1.0.3 Add async files list(file.lang.hljs.js).
  • 1.0.2 Add callback function