Skip to content

Commit

Permalink
Command line: Fix for uncaught errors for empty 'commandLine' object. (
Browse files Browse the repository at this point in the history
…#1862)

This fixes the issue that the Command line plugin throws an error when the 'commandLine' object is not defined/an empty object. This always happens when an element with no text is highlighted.
  • Loading branch information
libantema authored and RunDevelopment committed Apr 27, 2019
1 parent 59d4323 commit c24831b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions plugins/command-line/prism-command-line.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Prism.hooks.add('before-insert', function (env) {

// Reinsert the output lines into the highlighted code. -- cwells
var codeLines = env.highlightedCode.split('\n');
for (var i = 0; i < commandLine.outputLines.length; i++) {
for (var i = 0, l = (commandLine.outputLines || []).length; i < l; i++) {
if (commandLine.outputLines.hasOwnProperty(i)) {
codeLines[i] = commandLine.outputLines[i];
}
Expand Down Expand Up @@ -107,7 +107,7 @@ Prism.hooks.add('complete', function (env) {
};

// Create the "rows" that will become the command-line prompts. -- cwells
var promptLines = new Array(commandLine.numberOfLines + 1);
var promptLines = new Array((commandLine.numberOfLines || 0) + 1);
var promptText = getAttribute('data-prompt', '');
if (promptText !== '') {
promptLines = promptLines.join('<span data-prompt="' + promptText + '"></span>');
Expand All @@ -123,7 +123,7 @@ Prism.hooks.add('complete', function (env) {
prompt.innerHTML = promptLines;

// Remove the prompt from the output lines. -- cwells
for (var i = 0; i < commandLine.outputLines.length; i++) {
for (var i = 0, l = (commandLine.outputLines || []).length; i < l; i++) {
if (commandLine.outputLines.hasOwnProperty(i)) {
var node = prompt.children[i];
node.removeAttribute('data-user');
Expand Down
2 changes: 1 addition & 1 deletion plugins/command-line/prism-command-line.min.js

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

0 comments on commit c24831b

Please sign in to comment.