-
Notifications
You must be signed in to change notification settings - Fork 15
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
feat(code-block): support multiple single-line cmd copy #736
Conversation
🦋 Changeset detectedLatest commit: 60e9636 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
📦 Canary Packages PublishedLatest commit: 60e9636 Published 3 packages@hashicorp/react-code-block@6.2.0-canary-20221004215115
@hashicorp/react-marketo-form@0.1.1-canary-20221004215115
@hashicorp/react-subnav@9.5.0-canary-20221004215115
|
@@ -5,7 +5,7 @@ componentName: 'CodeBlock' | |||
A formatted code block for displaying lovely lines of code. | |||
|
|||
<LiveComponent> | |||
{`<CodeBlock language="shell-session" code={\`<span class="token command"><span class="token shell-symbol important">$</span> <span class="token bash language-bash"><span class="token builtin class-name">echo</span> <span class="token string">"hello world!"</span></span></span>\`} />`} | |||
{`<CodeBlock language="shell-session" code={\`<span class="token command"><span class="token shell-symbol important">$</span> <span class="token bash language-bash"><span class="token builtin class-name">echo</span> <span class="token string">"hello world!"</span></span></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.
There are some auto-formatting changes here, this is one of them.
theme="dark" | ||
code={`<span class="token keyword">const</span> foo <span class="token operator">=</span> <span class="token string">'bar'</span>\n<span class="token keyword">function</span> <span class="token function">hello</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n{/* */} <span class="token keyword control-flow">return</span> <span class="token known-class-name class-name">Math</span><span class="token punctuation">.</span><span class="token method function property-access">random</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">></span> <span class="token number">0.5</span> <span class="token operator">?</span> <span class="token string">'Hello'</span> <span class="token operator">:</span> <span class="token string">'Bonjour'</span>\n<span class="token punctuation">}</span>`} | ||
code={`<span class="token keyword">const</span> foo <span class="token operator">=</span> <span class="token string">'bar'</span>\n<span class="token keyword">function</span> <span class="token function">hello</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword control-flow">return</span> <span class="token known-class-name class-name">Math</span><span class="token punctuation">.</span><span class="token method function property-access">random</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">></span> <span class="token number">0.5</span> <span class="token operator">?</span> <span class="token string">'Hello'</span> <span class="token operator">:</span> <span class="token string">'Bonjour'</span>\n<span class="token punctuation">}</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.
Removed some weird {/* */}
which I think had shown up accidentally.
options={{ showClipboard: true }} | ||
code={`<span class="token shell-symbol important">$</span> echo "hello world"\nhello world`} | ||
/> | ||
|
||
The following multi-line command will be copied in similar way. Note that when using multi-line commands, subsequent lines such as output or additional commands should be placed in a separate code block, as they will not be copied correctly if they are placed directly after a multi-line command. |
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.
Added some examples for multi-line and multiple-single-line code snippets.
| Multi-line commands | ✅ | The multi-line command will be copied, without the leading `$`. Do not include lines after the multi-line command, such as output or additional commands, as they will not be processed correctly. | [🔗](https://learn.hashicorp.com/vault/secrets-management/sm-static-secrets#q-how-do-i-save-multiple-values-at-once) | | ||
| Commands with output | ✅ | The command will be copied without the leading `$` or the output. | [🔗](https://learn.hashicorp.com/vault/secrets-management/sm-static-secrets#additional-discussion) | | ||
| Non-shell Snippets | ✅ | The entire snippet will be copied. | [🔗](https://learn.hashicorp.com/nomad/getting-started/jobs#modifying-a-job) | | ||
| Single-line commands across multiple lines | ✅ | Commands will be copied without their leading `$ `. Lines that do not start in `$ ` will be omitted from the copied snippet. | ⏳ (none yet, relatively new feature) | |
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.
Updated this table, we now support many single-line commands in a single shell-session
snippet 👍
/* Prevent shell-symbols from being selected, for better select-copy-paste */ | ||
&:global(.language-shell-session) { | ||
& :global(.token.shell-symbol) { | ||
user-select: none; |
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.
CSS fix for the "select-copy-paste" use case. This applies to all code-blocks with $
characters (when correctly identified as .shell-symbol
, which of course requires highlighting).
* (ruby module of same name, seems to have better docs) | ||
* | ||
* Related task: | ||
* https://app.asana.com/0/1100423001970639/1199504357822173/f |
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.
Would love to explore better copying behaviour at some point in the future... but for now, was definitely reaching for a more immediate solution to ensure our "copy these install commands" works on download pages. See hashicorp/dev-portal#1149.
@brkalow This update to Have proven this out in hashicorp/dev-portal#1149. Let me know what you think 🙇♂️ |
@BrandonRomano Tagging ya here in cause you have extra review bandwidth |
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.
Nice improvements to the swingset page! I did some testing and all seems to be working. Left a suggestion on removing a console log
Co-authored-by: Bryce Kalow <bkalow@hashicorp.com>
🎟️ Asana Task
🔍 Preview Link
Support copy-button copying of shell-session snippets with multiple single-line commands.
Support select-copy-paste copying of shell-session snippets by setting
user-select: none
CSS on.shell-symbol
tokens.PR Checklist 🚀
Items in this checklist may not may not apply to your PR, but please consider each item carefully.