wcoder / highlightjs-line-numbers.js

Line numbering plugin for Highlight.js
https://wcoder.github.io/highlightjs-line-numbers.js/
MIT License
544 stars 126 forks source link

Use of async makes things difficult. Use promises instead. #71

Open bendavis78 opened 4 years ago

bendavis78 commented 4 years ago

I'm trying to use this in conjunction with printedjs, but it doesn't work because this library manipulates dom in a setTimeout(). Is there a good reason this needs to be wrapped in a setTimeout? If so, why not use promises? That would give us more control over the situation.

T3sT3ro commented 1 year ago

I modified the code and replaced current implementation with the following in my script:

function lineNumbersBlock (element, options) {
    if (typeof element !== 'object') return;

    return new Promise((resolve, reject) => {
        element.innerHTML = lineNumbersInternal(element, options);
        resolve();
    })
}

and it forks for me ¯\_(ツ)_/¯