From 62cdf3f0cc4209f53c440d17d35be0deac4dd7d8 Mon Sep 17 00:00:00 2001 From: Attila Gulyas Date: Sat, 10 Aug 2024 08:58:28 -0400 Subject: [PATCH 1/2] Update nix-language.md Proposing to move the "_Indented strings_" section after "_String interpolation_" because I think it fits better there logically. Also added a note that string interpolation works in indented strings as well. --- source/tutorials/nix-language.md | 94 +++++++++++++++++--------------- 1 file changed, 49 insertions(+), 45 deletions(-) diff --git a/source/tutorials/nix-language.md b/source/tutorials/nix-language.md index 2b1ae57c1..297b55951 100644 --- a/source/tutorials/nix-language.md +++ b/source/tutorials/nix-language.md @@ -848,6 +848,55 @@ in +(indented-strings)= +### Indented strings + +Also known as “multi-line strings”. + +The Nix language offers convenience syntax for character strings which span multiple lines that have common indentation. + +Indented strings are denoted by *double single quotes* (`'' ''`). + +Example: + +```{code-block} nix +:class: expression +'' +multi +line +string +'' +``` + +```{code-block} +:class: value +"multi\nline\nstring\n" +``` + +Equal amounts of prepended white space are trimmed from the result. + +Example: + +```{code-block} nix +:class: expression +'' + one + two + three +'' +``` + +```{code-block} +:class: value +"one\n two\n three\n" +``` + +:::{note} +Indented strings also support [string interpolation](string-interpolation). See the section on Nix's [`string`](https://nix.dev/manual/nix/stable/language/values#type-string) type in the [Nix manual](https://nix.dev/manual/nix/stable/). +::: + + + (file-system-paths)= ### File system paths @@ -975,51 +1024,6 @@ While you will encounter many such examples, we recommend to [avoid lookup paths [nixpkgs]: https://github.com/NixOS/nixpkgs [manual-primitives]: https://nix.dev/manual/nix/stable/language/values.html#primitives -(indented-strings)= -### Indented strings - -Also known as “multi-line strings”. - -The Nix language offers convenience syntax for character strings which span multiple lines that have common indentation. - -Indented strings are denoted by *double single quotes* (`'' ''`). - -Example: - -```{code-block} nix -:class: expression -'' -multi -line -string -'' -``` - -```{code-block} -:class: value -"multi\nline\nstring\n" -``` - -Equal amounts of prepended white space are trimmed from the result. - -Example: - -```{code-block} nix -:class: expression -'' - one - two - three -'' -``` - -```{code-block} -:class: value -"one\n two\n three\n" -``` - - - (functions)= ## Functions From c31a8e17ab019db063602e676bba0ca6b0bea06e Mon Sep 17 00:00:00 2001 From: Valentin Gagarin Date: Mon, 6 Jan 2025 18:50:21 +0100 Subject: [PATCH 2/2] Apply suggestions from code review --- source/tutorials/nix-language.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/source/tutorials/nix-language.md b/source/tutorials/nix-language.md index 297b55951..36d86358c 100644 --- a/source/tutorials/nix-language.md +++ b/source/tutorials/nix-language.md @@ -892,11 +892,10 @@ Example: ``` :::{note} -Indented strings also support [string interpolation](string-interpolation). See the section on Nix's [`string`](https://nix.dev/manual/nix/stable/language/values#type-string) type in the [Nix manual](https://nix.dev/manual/nix/stable/). +Indented strings also support [string interpolation](string-interpolation). +For details check the [documentation on string literals in the Nix language](https://nix.dev/manual/nix/2.24/language/syntax#string-literal). ::: - - (file-system-paths)= ### File system paths