-
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
Auto-detect command lines if 'data-filter' attribute present #1358
base: master
Are you sure you want to change the base?
Conversation
…empty. This change essentially performs the same operation as the existing code which processes the 'data-output' atrribute values, but in an automatic fashion. When the 'data-filter' attribute is found in the <pre> element with a non-empty value, visit each line of the <code> content. If the line starts with the value found in the 'data-prompt' attribute, treat it as a command and wrap the text in <span class="command-line-command">. Otherwise, treat the line as command output and strip off any data-user, data-host, or data-prompt attributes, just like the code which performs filter based on line numbers and ranges.
Pinging @chriswells0 as he is the author of the command-line plugin. |
if (line.slice(0, promptText.length) == promptText) { | ||
// We have a command -- strip off the prompt from the source text and wrap in <span> | ||
content[i] = '<span class="command-line-command">' + line.slice(promptText.length + 1) + | ||
'</span>'; |
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.
If I understand this correctly, it means users who don't use the data-filter
attribute won't benefit from the styled <span>
. Am I right? Couldn't this behaviour be added in every cases?
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 did not want to cause any possibly breaking change, hence the clear separation. I am more than willing to rework it if desired.
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 think that would be better to have a predictible behaviour when the span is always present, indeed. But yes we need to make sure nothing breaks.
…empty. This change essentially performs the same operation as the existing code which processes the 'data-output' atrribute values, but in an automatic fashion. When the 'data-filter' attribute is found in the <pre> element with a non-empty value, visit each line of the <code> content. If the line starts with the value found in the 'data-prompt' attribute, treat it as a command and wrap the text in <span class="command-line-command">. Otherwise, treat the line as command output and strip off any data-user, data-host, or data-prompt attributes, just like the code which performs filter based on line numbers and ranges.
I like the concept for this functionality. I wonder if a more descriptive name could be used for the I have an open PR #856 from 2 years ago that automatically treats lines beginning with |
Hi @chriswells0! This sounds like a good idea. If you start working again on #856, feel free to @ me so I can review it. |
My apologies for the delay--been swamped at work during the week. I just updated #856 with my old changes modified to use @bradhowes, I realize this will require changes for your PR, so I was hoping to hear your thoughts before implementing the changes in mine. I just didn't expect to have more time soon, so I changed it while I could. I do believe the new approach will make it easier to accomplish what you're doing, though. Search for |
@chriswells0 That sounds good to me. Thanks! I'm fine with closing this as a dupe of your work then. |
@bradhowes, I didn't mean it was a dupe. It's the reverse, which I think is a useful feature. My approach specifies the prefix for output lines, so you could use |
@bradhowes, I merged #856, so you'll have to merge or rebase the |
I'm still into this if we can get the conflicts merged. |
Sorry, I had a busy work week and just now had a minute to return to this. @bradhowes, like I said, I can see the benefit of having both options, so it's up to you if you want to merge it. I appreciate the contribution. @mAAdhaTTah, in the meantime, you can also look at the |
This change essentially performs the same operation as the existing code which processes the 'data-output' atrribute values, but in an automatic fashion.
When the 'data-filter' attribute is found in the <pre> element with a non-empty value, visit each line of the <code> content. If the line starts with the value found in the 'data-prompt' attribute, treat it as a command and wrap the text in <span class="command-line-command">. Otherwise, treat the line as command output and strip off any 'data-user', 'data-host', or 'data-prompt' attributes, just like the code which performs filter based on line numbers and ranges.