or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Syncing
xxxxxxxxxx
Quoting
What's a better paradigm for quoting in nushell?
This was written based on development version 0.69.2 of nushell Oct 14, 2022.
Current
Double quotes
Double quotes are used as you would think normal quotes should be used except for one thing. That one thing is escapes can be recognized and interpreted with double quotes.
Example:
That would be interpreted with
Red
foreground Hello andPurple aka Magenta
foreground Nushell becuase:\e
means insert andescape
character[31m
means use whatever is defined asred
foreground in your terminal[35m
means use whatever is defined as purple, sometimes called magenta, foreground in your terminal.[0m
means reset all ansi escape sequences.There are other escapes that are defined by nushell found in parser.rs around line 2426 in the
unescape_string
function.Recognized nushell escapes:
Double quotes work within string interpolation as well.
Single qotes
The single quote character should work identicaly to the double quote except that escape characters will not be recognized and interpreted.
Single quotes work within string interpolation as well.
Backtick quotes
Backtick quotes are something I'm still fuzzy on. Originally I thought they were supposed to be used as our string literal representation of quotes. Maybe that's what it is now. I'm not sure to tell.
Here are some ways we see/use backtick quotes.
bare words
that support spaces. As an example JT just landed a PR that allows backtick quotes to autocd. So, in Windows, if you're atC:\
you could type`Program Files`
and it would change to that directory.String literal
Maybe it's the backtick quote?
String interpolation
String interpolation uses either double quotes or single quotes with a preceeding dollar sign. However, when using double quotes, you have to be aware that escapes will be recognized and interpreted. (I(darren) really don't like that people have to be aware of this functionality with double quotes.)
Example:
There are a couple things to be aware of in the above example.
$
sign.$name
is in the example.Executing String Interpolated strings
Sometimes you need to build a path to execute external commands.
Example:
The caret
^
before the string interpolation symbol$
allows that external command to be exectued.Nested Quotes
Sometimes you need to nest quotes. I think this could use some work because sometimes I start with single quotes on the outside and have to reverse course to use double quotes on the outside. I'm not sure if backtick quotes can participate here.
Example:
The key to always remember is that double quotes recognize and interpret escapes so if you have any
\
characters in your string, they will be interpreted as excapes. The following is an example of a question we get frequently on Discord.It doesn't work because it sees
\P
and\s
as escapes that are not recognized.Future Ideas
These are some future ideas meant to make string quoting more intuitive. Feel free to jump in and add ideas.
"""
ala python for string literals. I was corrected that triple double quotes mean multiline strings in python and string literal.\n
above could be triggered by a string prefix such asr"a\nb"
, which is a syntactical features that again Python has, and also Scala, and maybe others? And nushell already has precedent for using string prefixes to configure the behavior of the string construct (i.e.$"this string will do interpolation in parens"
) (from dan davison on Discord)