From b53832cd1c4e1dcc106cf3b46258bcc5c063e98e Mon Sep 17 00:00:00 2001 From: at055612 <22818309+at055612@users.noreply.github.com> Date: Wed, 23 Feb 2022 11:30:35 +0000 Subject: [PATCH] Command Line: Add support for command continuation prefix (#3344) --- plugins/command-line/index.html | 98 +++++++++++++++++-- plugins/command-line/prism-command-line.js | 41 +++++--- .../command-line/prism-command-line.min.js | 2 +- 3 files changed, 119 insertions(+), 22 deletions(-) diff --git a/plugins/command-line/index.html b/plugins/command-line/index.html index c8cd9c44be..2aa0fed7e7 100644 --- a/plugins/command-line/index.html +++ b/plugins/command-line/index.html @@ -25,7 +25,8 @@
Add class command-line to your <pre>
. For a server command line, specify the user and host names using the data-user
and data-host
attributes. The resulting prompt displays a # for the root user and $ for all other users. For any other command line, such as a Windows prompt, you may specify the entire prompt using the data-prompt
attribute.
Optional: You may specify the lines to be presented as output (no prompt and no highlighting) through the data-output
attribute on the <pre>
element in the following simple format:
You may specify the lines to be presented as output (no prompt and no highlighting) through the data-output
attribute on the <pre>
element in the following simple format:
Optional: To automatically present some lines as output, you can prefix those lines with any string and specify the prefix using the data-filter-output
attribute on the <pre>
element. For example, data-filter-output="(out)"
will treat lines beginning with (out)
as output and remove the prefix.
To automatically present some lines as output, you can prefix those lines with any string and specify the prefix using the data-filter-output
attribute on the <pre>
element. For example, data-filter-output="(out)"
will treat lines beginning with (out)
as output and remove the prefix.
Output lines are user selectable by default, so if you select the whole content of the code block, it will select the shell commands and any output lines. This may not be desireable if you want to copy/paste just the commands and not the output. If you want to make the output not user selectable then add the following to your CSS:
+A blank line will render as an empty line with a prompt. If you want an empty line without a prompt then you can use a line containing just the output prefix, e.g. (out)
. See the blank lines in the examples below.
Output lines are user selectable by default, so if you select the whole content of the code block, it will select the shell commands and any output lines. This may not be desirable if you want to copy/paste just the commands and not the output. If you want to make the output not user selectable then add the following to your CSS:
.command-line span.token.output {
user-select: none;
}
- Optional: For multi-line commands you can specify the data-continuation-str
attribute on the <pre>
element. For example, data-continuation-str="\"
will treat lines ending with \
as being continued on the following line. Continued lines will have a prompt as set by the attribute data-continuation-prompt
or a default of >
.
You can configure the plugin to handle multi-line commands. This can be done in two ways; setting a line continuation string (as in Bash); or explicitly marking continuation lines with a prefix for languages that do not have a continuation string/character, e.g. SQL, Scala, etc..
+ +data-continuation-str
data-continuation-str="\"
data-filter-continuation
data-filter-output
. Prefix all continuation lines with the value of data-filter-continuation
and they will be displayed with the prompt set in data-continuation-prompt
. For example, data-filter-continuation="(con)"
will treat lines beginning with (con)
as continuation lines and remove the prefix.data-continuation-prompt
data-continuation-prompt="->"
. If this attribute is not set then a default of >
will be used.<pre class="command-line">
+
+cd ~/.vim
+
+vim vimrc
+
<pre class="command-line"
+ data-user="root"
+ data-host="localhost">
+
cd /usr/local/etc
cp php.ini php.ini.bak
vi php.ini
<pre class="command-line"
+ data-user="chris"
+ data-host="remotehost"
+ data-output="2, 4-8">
+
pwd
/usr/home/chris/bin
ls -la
@@ -78,6 +113,11 @@ Non-Root User With Output
-rwxr-xr-x 1 chris chris 642 Jan 17 14:42 deploy
<pre class="command-line"
+ data-prompt="PS C:\Users\Chris>"
+ data-output="2-19">
+
dir
@@ -99,7 +139,14 @@ Windows PowerShell With Output
d-r-- 10/14/2015 5:06 PM Videos
echo "hello"
+
+<pre class="command-line"
+ data-filter-output="(out)"
+ data-continuation-str="\" >
+
+
+export MY_VAR=123
+echo "hello"
(out)hello
echo one \
two \
@@ -110,7 +157,14 @@ Line continuation with Output (bash)
(out)goodbye
Line continuation with Output (PowerShell)
-Write-Host `
+
+<pre class="command-line"
+ data-prompt="ps c:\users\chris>"
+ data-continuation-prompt=">>"
+ data-filter-output="(out)"
+ data-continuation-str=" `">
+
+Write-Host `
'Hello' `
'from' `
'PowerShell!'
@@ -118,6 +172,37 @@ Line continuation with Output (PowerShell)
Write-Host 'Goodbye from PowerShell!'
(out)Goodbye from PowerShell!
+ Line continuation using prefix (MySQL/SQL)
+
+<pre class="command-line"
+ data-prompt="mysql>"
+ data-continuation-prompt="->"
+ data-filter-output="(out)"
+ data-filter-continuation="(con)">
+
+set @my_var = 'foo';
+set @my_other_var = 'bar';
+(out)
+CREATE TABLE people (
+(con)first_name VARCHAR(30) NOT NULL,
+(con)last_name VARCHAR(30) NOT NULL
+(con));
+(out)Query OK, 0 rows affected (0.09 sec)
+(out)
+insert into people
+(con)values ('John', 'Doe');
+(out)Query OK, 1 row affected (0.02 sec)
+(out)
+select *
+(con)from people
+(con)order by last_name;
+(out)+------------+-----------+
+(out)| first_name | last_name |
+(out)+------------+-----------+
+(out)| John | Doe |
+(out)+------------+-----------+
+(out)1 row in set (0.00 sec)
+