Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from markdumay/develop
Add command shortcode
- Loading branch information
Showing
5 changed files
with
241 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* Adapted from PrismJS 1.29.0 | ||
https://prismjs.com/download.html#themes=prism&plugins=command-line */ | ||
|
||
/** | ||
* prism.js default theme for JavaScript, CSS and HTML | ||
* Based on dabblet (http://dabblet.com) | ||
* @author Lea Verou | ||
*/ | ||
|
||
.command-line-prompt { | ||
border-right: 1px solid #999; | ||
display: block; | ||
float: left; | ||
font-size: 100%; | ||
letter-spacing: -1px; | ||
margin-right: 1em; | ||
pointer-events: none; | ||
text-align: right; | ||
-webkit-user-select: none; | ||
-moz-user-select: none; | ||
-ms-user-select: none; | ||
user-select: none; | ||
} | ||
|
||
.command-line-prompt > span::before { | ||
opacity: 0.7; | ||
content: " "; | ||
display: block; | ||
padding-right: 0.8em; | ||
} | ||
|
||
.command-line-prompt > span[data-prompt]::before { | ||
content: attr(data-prompt); | ||
} | ||
|
||
.command-line-prompt > span[data-continuation-prompt]::before { | ||
content: attr(data-continuation-prompt); | ||
} | ||
|
||
.command-line span.token.output { | ||
/* Make shell output lines a bit lighter to distinguish them from shell commands */ | ||
opacity: 0.7; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
{{ $host := .Get "host" }} | ||
{{ $user := .Get "user" }} | ||
{{ $prompt := .Get "prompt" }} | ||
{{ $filter := "(out)" }} | ||
{{ $input := trim .Inner "\n" }} | ||
|
||
{{ $shell := lower (.Get "shell") }} | ||
{{ $continuationPrompt := ">" }} | ||
{{ $continuationStr := "\\" }} | ||
{{ if eq $shell "powershell" }} | ||
{{ if not $prompt }}{{ $prompt = "PS>" }}{{ end }} | ||
{{ $continuationPrompt = ">>" }} | ||
{{ $continuationStr = "`" }} | ||
{{ else if eq $shell "sql" }} | ||
{{ if not $prompt }}{{ $prompt = "sql>" }}{{ end }} | ||
{{ $continuationPrompt = "->" }} | ||
{{ $continuationStr = "(con)" }} | ||
{{ else }} | ||
{{ $shell = "bash" }} | ||
{{ if not $prompt }}{{ $prompt = "$" }}{{ end }} | ||
{{ if (and ($host) ($user)) }} | ||
{{ $prompt = printf "[%s@%s] %s" $user $host $prompt}} | ||
{{ end }} | ||
{{ end }} | ||
|
||
|
||
|
||
|
||
{{ $lines := split $input "\n" }} | ||
{{ $prefix := ""}} | ||
{{ $prevLine := "" }} | ||
{{ $refined := "" }} | ||
{{ range $line := $lines }} | ||
{{ if hasPrefix $line $filter }} | ||
{{ $prefix = printf "%s<span></span>" $prefix }} | ||
{{ if eq $shell "sql" }} | ||
{{ $line = printf "--%s" (strings.TrimPrefix $filter $line) }} | ||
{{ else }} | ||
{{ $line = printf "#%s" (strings.TrimPrefix $filter $line) }} | ||
{{ end }} | ||
{{ else if (strings.HasSuffix $prevLine $continuationStr) }} | ||
{{ $prefix = printf "%s<span data-prompt=\"%s\"></span>" $prefix $continuationPrompt }} | ||
{{ else }} | ||
{{ $prefix = printf "%s<span data-prompt=\"%s\"></span>" $prefix $prompt }} | ||
{{ end }} | ||
{{ $prevLine = $line }} | ||
{{ if (and (eq $shell "sql") (strings.HasSuffix $line $continuationStr)) }} | ||
{{ $line = strings.TrimSuffix $continuationStr $line }} | ||
{{ end }} | ||
{{ $refined = printf "%s\n%s" $refined $line }} | ||
{{ end }} | ||
|
||
{{ $refined := trim $refined "\n" }} | ||
|
||
{{ $output := (transform.Highlight $refined $shell | safeHTML) }} | ||
|
||
|
||
|
||
{{ $insert := printf "<span class=\"command-line-prompt\">%s</span><span class=\"line\">" $prefix }} | ||
|
||
{{ $output := (replace $output ("<span class=\"line\">" | safeHTML) $insert 1 | safeHTML) }} | ||
|
||
{{ if eq $shell "sql"}} | ||
{{ $output = (replace $output "<span class=\"c1\">--" "<span class=\"c1\">" | safeHTML) }} | ||
{{ else }} | ||
{{ $output = (replace $output "<span class=\"c1\">#" "<span class=\"c1\">" | safeHTML) }} | ||
{{ $output = (replace $output "<span class=\"c\">#" "<span class=\"c\">" | safeHTML) }} | ||
{{ end }} | ||
|
||
{{ $output }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters