Skip to content

Commit c24831b

Browse files
libantemaRunDevelopment
authored andcommitted
Command line: Fix for uncaught errors for empty 'commandLine' object. (#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.
1 parent 59d4323 commit c24831b

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

plugins/command-line/prism-command-line.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ Prism.hooks.add('before-insert', function (env) {
7979

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

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

125125
// Remove the prompt from the output lines. -- cwells
126-
for (var i = 0; i < commandLine.outputLines.length; i++) {
126+
for (var i = 0, l = (commandLine.outputLines || []).length; i < l; i++) {
127127
if (commandLine.outputLines.hasOwnProperty(i)) {
128128
var node = prompt.children[i];
129129
node.removeAttribute('data-user');

plugins/command-line/prism-command-line.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)