Skip to content

Commit

Permalink
Core: Prevent error from throwing when element does not have a parent…
Browse files Browse the repository at this point in the history
…Node in highlightElement. Fix #1203
  • Loading branch information
Golmote committed Nov 5, 2017
1 parent 1fd690d commit c33be19
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
10 changes: 6 additions & 4 deletions components/prism-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,13 @@ var _ = _self.Prism = {
// Set language on the element, if not present
element.className = element.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;

// Set language on the parent, for styling
parent = element.parentNode;
if (element.parentNode) {
// Set language on the parent, for styling
parent = element.parentNode;

if (/pre/i.test(parent.nodeName)) {
parent.className = parent.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;
if (/pre/i.test(parent.nodeName)) {
parent.className = parent.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;
}
}

var code = element.textContent;
Expand Down
2 changes: 1 addition & 1 deletion components/prism-core.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions prism.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,13 @@ var _ = _self.Prism = {
// Set language on the element, if not present
element.className = element.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;

// Set language on the parent, for styling
parent = element.parentNode;
if (element.parentNode) {
// Set language on the parent, for styling
parent = element.parentNode;

if (/pre/i.test(parent.nodeName)) {
parent.className = parent.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;
if (/pre/i.test(parent.nodeName)) {
parent.className = parent.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;
}
}

var code = element.textContent;
Expand Down

0 comments on commit c33be19

Please sign in to comment.