Skip to content

Commit

Permalink
(chore) older API defers to highlightAll() now
Browse files Browse the repository at this point in the history
  • Loading branch information
joshgoebel committed Mar 17, 2021
1 parent e67494f commit aa5a3e7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
5 changes: 5 additions & 0 deletions VERSION_11_UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
- remove apache, http, nginx, properties, coffeescript from :common #2848


### Behavior changes

- `initHighlighting` and `initHighlightingOnLoad` call `highlightAll`
- Calling `highlightAll` over and over is not guarded against

### Grammar's removed or renamed

- remove the old htmlbars stub, use handlebars
Expand Down
5 changes: 3 additions & 2 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@ Accepts an object representing options with the values to updated. Other options
::

hljs.configure({
tabReplace: ' ', // 4 spaces
noHighlightRe: /^do-not-highlightme$/i,
languageDetectRe: /\bgrammar-([\w-]+)\b/i, // for `grammar-swift` style CSS naming
classPrefix: '' // don't append class prefix
// … other options aren't changed
});
hljs.initHighlighting();
hljs.highlightAll();


``highlightAll()``
Expand Down
19 changes: 4 additions & 15 deletions src/highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -684,27 +684,16 @@ const HLJS = function(hljs) {
options = inherit(options, userOptions);
}

/**
* Highlights to all <pre><code> blocks on a page
*
* @type {Function & {called?: boolean}}
*/
// TODO: remove v12, deprecated
const initHighlighting = () => {
if (initHighlighting.called) return;
initHighlighting.called = true;

logger.deprecated("10.6.0", "initHighlighting() is deprecated. Use highlightAll() instead.");

const blocks = document.querySelectorAll('pre code');
blocks.forEach(highlightElement);
highlightAll();
logger.deprecated("10.6.0", "initHighlighting() deprecated. Use highlightAll() now.");
};

// Higlights all when DOMContentLoaded fires
// TODO: remove v12, deprecated
function initHighlightingOnLoad() {
logger.deprecated("10.6.0", "initHighlightingOnLoad() is deprecated. Use highlightAll() instead.");
wantsHighlight = true;
highlightAll();
logger.deprecated("10.6.0", "initHighlightingOnLoad() deprecated. Use highlightAll() now.");
}

let wantsHighlight = false;
Expand Down

0 comments on commit aa5a3e7

Please sign in to comment.