-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Command Line highlighting #831
Conversation
I really like your plugin. I think it would be a very useful addition to Prism. I have just a few remarks:
|
Thanks for the feedback. I wanted to respond sooner, but I had a busy week leading up to getting my wisdom teeth removed on Thursday.
|
I meant as a separate commit, but a separate PR would also be great. If you create a separate whitespace PR it probably would be accepted immediately, because such a PR doesn't require any review. But this is just my opinion and not a requirement at all. I am also not a project owner so feel free to ignore my comments...
Sorry that was my mistake. It is correct to add it as a plugin and a language.
We could also rename |
I'd suggest an alias rather than renaming I've reverted the changes to Please let me know if I should make further changes. |
First of all I'd like to stress, that I am not a project owner of Prism, so you don't have to follow any of my suggestions 😄 . I just like your plugin and I wrote the Bash language plugin. If you add a language to the list in The name of the plugin is also a bit confusing. How about something like It would be nice if the plugin could also simulate the appearance of a Windows Powershell and maybe other command line interfaces. You could simply add an additional attribute |
One other thing: A PR should be about only one issue or feature. I think the plugin could be accepted right away.But if you bundle it up with lots of other more controversial changes that affect |
That's OK. You're clearly more familiar with it than I am, and I appreciate the input. You also sound like someone who might actually use this plugin, so your feedback is even more relevant.
This PR was meant to only add the language and plugin for styling shells. I'm not sure if you're suggesting the language should be removed until that discussion is complete or if you're referring specifically to the change that allows highlighting of
I think
I'm admittedly out of touch with Windows, so I didn't think about it at all. I thought creating the prompt via CSS would make it flexible enough, but it's a great idea to embed the entire prompt in the markup for the examples you gave. I'd even be on board with removing
The |
Ok.
The show-language plugin is quite smart. The only thing you have to do is add the following line to the bottom of // shell is an alias for bash
Prism.languages.shell = Prism.languages.bash; Everything else should work automatically. You don't even have to change the file <pre><code class="language-shell">ls -al</code></pre> The show-language plugin works with a simple reference just as well as with your new language.
I really like the
I like
I agree.
I would argue that |
<footer data-src="templates/footer.html" data-type="text/html"></footer> | ||
|
||
<script src="prism.js"></script> | ||
<script src="plugins/shell/prism-shell.js"></script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You also have to include your language here:
<script src="components/prism-shell.js"></script>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you saying the language or alias should be defined in components/prism-shell.js
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you saying the language or alias should be defined in components/prism-shell.js?
No I just meant that however we eventually decide to solve the language question, you have to include that language here for it to work.
I'm still pondering what to do about the language and the plugin name. Renaming the plugin will require a lot of changes, so I want to be sure before doing that. |
Give me your thoughts on this, please: As I stated before, I wanted to be able to distinguish shell scripts and sessions when shown on the same web page. Specifically, I didn't want the Show Language plugin to display Bash for both. Adding an alias for I'm not sure how I'd prefer my code snippets to be labeled in a case where there are shell scripts and shell sessions on the same page, but maybe it should stick with the name of the language being highlighted and remove the new language completely. Of course, I (or others) could always add an alias in my own JS if I want Show Language to display a different value on my site. |
I would love to use your plugin on my website, but I don't use the This doesn't mean that adding the The best approach for your issue with <pre class="shell" data-user="chris" data-host="remotehost" data-output="2">
<code class="language-bash" data-language-alias="My Favorite Shell">pwd
/usr/home/chris/bin</code></pre> <pre><code class="language-python" data-language-alias="Python 2.7.1.1">....</code></pre> <pre><code class="language-python" data-language-alias="Python 3.1.4">....</code></pre> <pre><code class="language-python" data-language-alias="PyPy">....</code></pre> Try to see it from the reviewers perspective. Every PR that gets accepted is immediately published on the website. Thousands of people use Prism. So the reviewers have to make absolutely sure that your changes don't adversely affect other stuff. If your PR changes things all over the place, it takes more work to review. If your PR is a self-contained plugin that touches nothing else, the review takes 5 minutes. Also once people start using your plugin, you have a better argument for the |
I've made the suggested changes and updated the documentation page to include an example using the I do believe an alias attribute would be a great addition to the show-language plugin, so I'll make that change and submit a separate PR. This is my first GitHub PR and I'm new to Prism, so thanks for the guidance as well as the feedback. |
-rwxr-xr-x 1 chris chris 642 Jan 17 14:42 deploy</code></pre> | ||
|
||
<h2>Windows PowerShell With Output</h2> | ||
<pre class="command-line" data-prompt="PS C:\Users\Chris>"><code class="language-powershell">dir |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
data-output="2-19"
is missing here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't believe I did that. I noticed it when I pasted the code from that file to another, but forgot to put the fix back into my git branch. It's there now.
It looks good to me 👍 . There are currently 7 commits in this PR and they include all the changes you made so far. Since the PR will eventually end up in the Prism git-log it is considered nice to squash everything down into a single commit and give it a nice descriptive commit message.
The project owner usually gets notified automatically by email. They seem to be a bit busy at the moment so you have to be a bit patient. You can address them directly by using tags in your message. As far as I know @LeaVerou is the original author of Prism and @Golmote is very active and has admin rights for the project.
You're welcome. Thanks for the great plugin and your contribution to Prism. |
b18d2e1
to
8378906
Compare
It's rebased and committed. Should look a lot cleaner now. |
If I may, I have one more question: when making an update to someone else's plugin, would it be a better practice to submit the PR to that plugin maintainer's fork and let them upstream the changes or submit the PR to the main project? For example, I submitted a PR to add support for a |
Based on my observations, I think the current practice is to just submit the PR here, and just ping the main author/maintainer of the plugin for suggestions and review in it. |
Thanks! |
Hi there, sorry I’m late to this. |
Hi @LeaVerou,
That is a good point. A language definition would definitely be possible. The following points are some of the advantages of the plugin in my opinion:
But a Prism.languages['command-line'] = {
'bash-command': {
pattern: /(^\[\w+@\w+\s+\]\s+[$#]).*/m,
lookbehind: true,
inside: Prism.languages.bash
},
'unix-prompt': /^\[\w+@\w+\s+\]\s+[$#]/
} |
In addition to the benefits listed by @zeitgeist87, the plugin also allows you to have some lines display the prompt while other lines are output (no prompt) without manually adding the prompt to every line where it should appear. |
Instead of using an var node = prompt.children[j - 1];
node.removeAttribute('data-user');
node.removeAttribute('data-host');
node.removeAttribute('data-prompt'); With some small rearrangements of the CSS code we can avoid the |
The |
Sorry my comment was unclear. My sample code should replace the line number 66 in
No not at all. Here is how I would modify the CSS: .command-line-prompt > span:before {
color: #999;
content: ' ';
display: block;
padding-right: 0.8em;
}
.command-line-prompt > span[data-user]:before, .command-line-prompt > span[data-host]:before {
content: "[" attr(data-user) "@" attr(data-host) "] $";
}
.command-line-prompt > span[data-user="root"]:before {
content: "[" attr(data-user) "@" attr(data-host) "] #";
}
.command-line-prompt > span[data-prompt]:before {
content: attr(data-prompt);
} On the other hand the |
I think this PR is ready to be merged. You don't have to implement my suggestion about the |
Sorry, it's been a while since I looked at this code. I thought you were suggesting removal of the |
Add support for Command Line highlighting
Thanks for merging this! I was in the process of removing the I was updating the Prism code on my site today, so I went back to grab the latest after you merged my 2 PRs. I notice that it fails to fetch the minified version of the JS for this plugin. I didn't include a minified version because I expected it to be created as part of the build process. Should I minify it myself and submit a PR to add it? |
Thanks for pointing that out.
We use
I've already commited a minified version, so there is no need for a PR. It would be nice if you could include minified versions in future PRs though. |
Hi all! Thanks @chriswells0 for contributing and @zeitgeist87 for reviewing! A few remarks:
You can use
I’m a bit uneasy with that. I don’t see such a need. There are many language definitions with code, let’s not clutter the plugin listing with things that, semantically, are not plugins. @zeitgeist87 had a good suggestion about how to turn this into just a language definition. |
Thanks I'll keep that in mind. I didn't know Github had a strip-whitespace-changes feature.
I was referring to a now obsolete version of the PR with that statement. The original PR included a new language
Sorry if I merged this too early. In my mind this is more like a line marker than a full blown language. The commands are marked with a prompt. But it would be quite easy to convert it into a language-definition. @LeaVerou shall I remove the plugin for now? |
Historically, how do you distinguish between a language and plugin? I'd expect the language to refer to the syntax/highlighting and plugins to add meta-functionality. If this is converted to a language, how would that impact the ability to use any language you want with it? |
You would have to explicitly add support for any language you want to use. That being said, a language-definition would have other advantages:
|
I don't want to waste your time here, but would you mind giving an example? Rough pseudo-code is fine. I'm trying to imagine how that would work from the user's perspective with one or more code blocks on a given page/site and a variety of potential languages.
This seems unnatural to me. The prompt is merely the setting you're in. Imagine if anyone who wanted line numbers had to number them manually when they're not actually part of the code.
I like the thought of that. I considered the possibility of false positives but hadn't addressed it yet. As a plugin, we could do this with a |
It would look something like this (not tested): Prism.languages['command-line'] = {
/*
* Bash support
*/
'bash-command': {
pattern: /(^\[\w+@\w+\s+\]\s+[$#]).*/m,
lookbehind: true,
inside: Prism.languages.bash
},
'unix-prompt': /^\[\w+@\w+\s+\]\s+[$#]/,
/*
* Powershell support
*/
'powershell-command': {
pattern: /(^PS .*?>).*/m,
lookbehind: true,
inside: Prism.languages.powershell
},
'powershell-prompt': /^PS .*?>/,
/*
* Support for other languages
*/
} You just explicitly match the prompts in your source code and use the matched language for the
I agree that its merely the setting the command is executed in. I was trying to say, that it would look a bit more like a real terminal window, since in a terminal everything is monospace text of the same size, including the prompt.
Not that I am aware of. |
The end user would use it like this: <pre class="language-command-line"><code>[andreas@terok]$ date
Mit Dez 30 21:11:42 CET 2015</code></pre> |
So the language code would loop through the Additionally, if we want to allow special highlighting/styling of the prompt, there could be a We'd be limiting the supported languages to those that are explicitly defined in this meta-language, but we could start with a pretty good set (Bash, PHP, Python, JavaScript, PowerShell, Batch) and expand it on request. That could be a barrier to use, though. As someone who expected to use this plugin, which approach would you prefer as a user? I'd try the meta-language approach with an open mind if you guys believe it's an improvement, but I'm still leaning toward the plugin for my own use because I don't want to hard-code shell prompts on every line. I'd likely add the |
Adds the ability to style shell examples as shown in this article:
https://chriswells.io/blog/view/style-shell-commands-with-css
Please let me know if I missed any files that I should have created or edited.