Skip to content

Commit

Permalink
Added support for Shell sessions
Browse files Browse the repository at this point in the history
This adds support for a Shell session pseudo language.
  • Loading branch information
RunDevelopment authored Jun 12, 2019
2 parents 6f53f74 + 0b48301 commit 31fb8bc
Show file tree
Hide file tree
Showing 13 changed files with 108 additions and 6 deletions.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,11 @@
"title": "Scheme",
"owner": "bacchus123"
},
"shell-session": {
"title": "Shell session",
"require": "bash",
"owner": "RunDevelopment"
},
"smalltalk": {
"title": "Smalltalk",
"owner": "Golmote"
Expand Down
2 changes: 1 addition & 1 deletion components/prism-bash.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,6 @@
for(var i = 0; i < toBeCopied.length; i++) {
inside[toBeCopied[i]] = Prism.languages.bash[toBeCopied[i]];
}

Prism.languages.shell = Prism.languages.bash;
})(Prism);
21 changes: 21 additions & 0 deletions components/prism-shell-session.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Prism.languages['shell-session'] = {
'command': {
pattern: /\$(?:[^\r\n'"<]|(["'])(?:\\[\s\S]|\$\([^)]+\)|`[^`]+`|(?!\1)[^\\])*\1|((?:^|[^<])<<\s*)["']?(\w+?)["']?\s*(?:\r\n?|\n)(?:[\s\S])*?(?:\r\n?|\n)\3)+/,
inside: {
'bash': {
pattern: /(\$\s*)[\s\S]+/,
lookbehind: true,
alias: 'language-bash',
inside: Prism.languages.bash
},
'sh': {
pattern: /^\$/,
alias: 'important'
}
}
},
'output': {
pattern: /.(?:.*(?:\r\n?|\n|.$))*/
// output highlighting?
}
}
1 change: 1 addition & 0 deletions components/prism-shell-session.min.js

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

10 changes: 10 additions & 0 deletions examples/prism-shell-session.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<h2>Full example</h2>
<pre><code>$ git checkout master
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
$ git push
Everything up-to-date
$ echo "Foo
> Bar"
Foo
Bar</code></pre>
1 change: 1 addition & 0 deletions plugins/autoloader/prism-autoloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
"sass": "css",
"scss": "css",
"scala": "java",
"shell-session": "bash",
"smarty": "markup-templating",
"soy": "markup-templating",
"swift": "clike",
Expand Down
2 changes: 1 addition & 1 deletion plugins/autoloader/prism-autoloader.min.js

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

1 change: 1 addition & 0 deletions plugins/show-language/prism-show-language.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
"sas": "SAS",
"sass": "Sass (Sass)",
"scss": "Sass (Scss)",
"shell-session": "Shell session",
"sql": "SQL",
"soy": "Soy (Closure Template)",
"tap": "TAP",
Expand Down
2 changes: 1 addition & 1 deletion plugins/show-language/prism-show-language.min.js

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

4 changes: 2 additions & 2 deletions tests/languages/scss/atrule_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
["punctuation", ")"]
]],
["punctuation", "{"],
["punctuation", "}"]
["punctuation", "}"]
]

----------------------------------------------------

Checks for at-rules.
Checks for at-rules.
31 changes: 31 additions & 0 deletions tests/languages/shell-session/command_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
$ git checkout master
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
$ git push
Everything up-to-date

----------------------------------------------------

[
["command", [
["sh", "$"],
["bash", [
["function", "git"],
" checkout master"
]]
]],
["output", "Switched to branch 'master'\nYour branch is up-to-date with 'origin/master'.\n"],

["command", [
["sh", "$"],
["bash", [
["function", "git"],
" push"
]]
]],
["output", "Everything up-to-date"]
]

----------------------------------------------------

Checks for commands.
32 changes: 32 additions & 0 deletions tests/languages/shell-session/command_string_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
$ echo 'Foo
> Bar'
$ echo "Foo
> Bar"

----------------------------------------------------

[
["command", [
["sh", "$"],
["bash", [
["builtin", "echo"],
["string", [
"'Foo\n> Bar'"
]]
]]
]],

["command", [
["sh", "$"],
["bash", [
["builtin", "echo"],
["string", [
"\"Foo\n> Bar\""
]]
]]
]]
]

----------------------------------------------------

Checks for multi-line strings inside commands.

0 comments on commit 31fb8bc

Please sign in to comment.