Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const HLJS = function(hljs) {
// calling the `hljs.configure` function.
/** @type HLJSOptions */
let options = {
ignoreUnescapedHTML: false,
noHighlightRe: /^(no-?highlight)$/i,
languageDetectRe: /\blang(?:uage)?-([\w-]+)\b/i,
classPrefix: 'hljs-',
Expand Down Expand Up @@ -668,15 +669,20 @@ const HLJS = function(hljs) {

if (shouldNotHighlight(language)) return;

// support for v10 API
fire("before:highlightElement",
{ el: element, language: language });

// we should be all text, no child nodes
if (!options.ignoreUnescapedHTML && element.children.length > 0) {
console.warn("One of your code blocks includes unescaped HTML. This is a potentially serious security risk.");
console.warn("https://github.com/highlightjs/highlight.js/issues/2886");
console.warn(element);
}

node = element;
const text = node.textContent;
const result = language ? highlight(text, { language, ignoreIllegals: true }) : highlightAuto(text);

// support for v10 API
fire("after:highlightElement", { el: element, result, text });

element.innerHTML = result.value;
Expand Down
1 change: 1 addition & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ interface HLJSOptions {
classPrefix: string
languages?: string[]
__emitter: EmitterConstructor
ignoreUnescapedHTML?: boolean
}

interface CallbackResponse {
Expand Down