Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for inline code highlighting #3180

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Configures global options:
* ``languages``: an array of language names and aliases restricting auto detection to only these languages.
* ``languageDetectRe``: a regex to configure how CSS class names map to language (allows class names like say `color-as-php` vs the default of `language-php`, etc.)
* ``noHighlightRe``: a regex to configure which CSS classes are to be skipped completely.
* ``allCodeSelector``: a CSS selector to configure which elements are affected by ``hljs.highlightAll``. Defaults to ``'pre code'``.
* ``cssSelector``: a CSS selector to configure which elements are affected by ``hljs.highlightAll``. Defaults to ``'pre code'``.

Accepts an object representing options with the values to updated. Other options don't change
::
Expand All @@ -112,7 +112,8 @@ Accepts an object representing options with the values to updated. Other options
highlightAll
------------

Applies highlighting to all elements on a page matching ``allCodeSelector``.
Applies highlighting to all elements on a page matching the configured ``cssSelector``.
The default ``cssSelector`` value is ``'pre code'``, which highlights all code blocks.
This can be called before or after the page's ``onload`` event has fired.


Expand Down
4 changes: 2 additions & 2 deletions src/highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const HLJS = function(hljs) {
// https://github.com/highlightjs/highlight.js/issues/1086
__emitter: TokenTreeEmitter,
// https://github.com/highlightjs/highlight.js/pull/3180
joshgoebel marked this conversation as resolved.
Show resolved Hide resolved
allCodeSelector: 'pre code',
cssSelector: 'pre code',
};

/* Utility functions */
Expand Down Expand Up @@ -782,7 +782,7 @@ const HLJS = function(hljs) {
return;
}

const blocks = document.querySelectorAll(options.allCodeSelector);
const blocks = document.querySelectorAll(options.cssSelector);
blocks.forEach(highlightElement);
}

Expand Down