From ed25584f853f4e607960bedbee209923812759dc Mon Sep 17 00:00:00 2001 From: claude Date: Thu, 11 Dec 2025 22:15:19 -0300 Subject: [PATCH 01/21] fix: ensure valid JSON output for testing commands with --json flag Updates testing commands to produce properly formatted JSON: - Add --quiet flag to testing-unit to suppress nutest terminal output - Pass --quiet from main testing when JSON output is requested - Use 'to json --raw' instead of 'to json' for valid JSON serialization This fixes JSON output format issues when running tests in CI/automated environments. --- toolkit.nu | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/toolkit.nu b/toolkit.nu index 958eafb..3dd9822 100644 --- a/toolkit.nu +++ b/toolkit.nu @@ -7,21 +7,23 @@ export def main [] { } export def 'main testing' [ --json # output results as JSON for external consumption ] { - let unit = main testing-unit + let unit = main testing-unit --quiet=$json let integration = main testing-integration {unit: $unit integration: $integration} - | if $json { to json } else { } + | if $json { to json --raw } else { } } # Run unit tests using nutest export def 'main testing-unit' [ --json # output results as JSON for external consumption + --quiet # suppress terminal output (for use when called from main testing) ] { use ../nutest/nutest - nutest run-tests --path tests/ --returns summary --display terminal - | if $json { to json } else { } + let display = if ($json or $quiet) { 'nothing' } else { 'terminal' } + nutest run-tests --path tests/ --returns summary --display $display + | if $json { to json --raw } else { } } # Run integration tests (execute example markdown files) @@ -83,7 +85,7 @@ export def 'main testing-integration' [ | append ( numd run README.md --no-backup --config-path numd_config_example1.yaml ) - | if $json { to json } else { } + | if $json { to json --raw } else { } } def update-dotnu-embeds [] { From 0708d96408dcbe1e92fd8e99a1f103cf57e5b5d9 Mon Sep 17 00:00:00 2001 From: maxim Date: Fri, 12 Dec 2025 23:46:43 -0300 Subject: [PATCH 02/21] Revert "Merge pull request #86 from maxim-uvarov-ai-assistant/docs/improve-command-descriptions" This reverts commit 26a6504ede8812951f5c3d25f42804c956624cf4, reversing changes made to 042721b79688985638022fb190858acd45ec60a1. --- CLAUDE.md | 2 +- numd/commands.nu | 64 ++++++++----------- .../numd_commands_explanations.md | 2 +- .../numd_commands_explanations.md_intermed.nu | 4 +- .../working_with_lists.md | 8 +-- z_examples/6_edge_cases/error-with-try.md | 3 +- .../numd_commands_explanations.nu | 2 +- 7 files changed, 39 insertions(+), 46 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index fc96891..22a0e3e 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -37,7 +37,7 @@ use numd; numd clear-outputs path/to/file.md --strip-markdown --echo 1. **`find-code-blocks`**: Parses markdown into a table classifying each block by type (`text`, ` ```nushell `, ` ```output-numd `) and action (`execute`, `print-as-it-is`, `delete`) -2. **`decorate-original-code-blocks`** + **`generate-intermediate-script`**: Transforms executable code blocks into a temporary `.nu` script with markers for output capture +2. **`decortate-original-code-blocks`** + **`generate-intermediate-script`**: Transforms executable code blocks into a temporary `.nu` script with markers for output capture 3. **`execute-intermediate-script`**: Runs the generated script in a new Nushell instance, capturing stdout diff --git a/numd/commands.nu b/numd/commands.nu index 2346a01..5feb1a3 100644 --- a/numd/commands.nu +++ b/numd/commands.nu @@ -32,7 +32,7 @@ export def run [ # We don't use a temp directory here as the code in `md` files might contain relative paths, # which will only work if we execute the intermediate script from the same folder. - decorate-original-code-blocks $original_md_table + decortate-original-code-blocks $original_md_table | generate-intermediate-script | save -f $intermediate_script_path @@ -190,8 +190,8 @@ export def --env 'capture stop' []: nothing -> nothing { # Beautify and adapt the standard `--help` for markdown output export def 'parse-help' [ - --sections: list # filter to only include these sections (e.g., ['Usage', 'Flags']) - --record # return result as a record instead of formatted string + --sections: list + --record ]: string -> any { let help_lines = split row '======================' | first # quick fix for https://github.com/nushell/nushell/issues/13470 @@ -257,7 +257,7 @@ export def 'parse-help' [ } #### -# I keep commands here with `export` to make them available for testing script, yet I do not export them in the mod.nu +# I keep commands here with `export` to make them availible for testing script, yet I do not export them in the mod.nu ### # Detect code blocks in a markdown string and return a table with their line numbers and info strings. @@ -322,8 +322,8 @@ export def match-action [ # # > 'ls | sort-by modified -r' | create-execution-code --whole_block ['no-output'] | save z_examples/999_numd_internals/create-execution-code_0.nu -f export def create-execution-code [ - fence_options: list # options from the code fence (e.g., 'no-output', 'try') - --whole_block # treat input as a complete block rather than a single line + fence_options: list + --whole_block ]: string -> string { let code_content = $in # let fence_options = $env.numd.current_block_options @@ -351,9 +351,9 @@ export def create-execution-code [ $highlighted_command + $code_execution } -# Generate additional service code necessary for execution and capturing results, while preserving the original code. -export def decorate-original-code-blocks [ - md_classified: table, action: string> # classified markdown table from find-code-blocks +# generates additional service code necessary for execution and capturing results, while preserving the original code. +export def decortate-original-code-blocks [ + md_classified: table, action: string> ]: nothing -> table, action: string, code: string> { $md_classified | where action == 'execute' @@ -365,8 +365,6 @@ export def decorate-original-code-blocks [ } # Generate an intermediate script from a table of classified markdown code blocks. -# -# Takes decorated code blocks and produces a complete Nushell script ready for execution. export def generate-intermediate-script []: table, action: string, code: string> -> string { get code -o | if $env.numd?.prepend-code? != null { @@ -385,11 +383,8 @@ export def generate-intermediate-script []: table') and whole-block execution. export def execute-block-lines [ - fence_options: list # options from the code fence (e.g., 'no-output', 'try') + fence_options: list ]: list -> list { skip | drop # skip code fences | if ($in | where $it =~ '^>' | is-empty) { @@ -568,10 +563,10 @@ export def escape-special-characters-and-quote []: string -> string { | $'"($in)"' } -# Run the intermediate script and return its output as a string. +# Run the intermediate script and return its output lines as a list. export def execute-intermediate-script [ - intermed_script_path: path # path to the generated intermediate script - no_fail_on_error: bool # if true, return empty string on error instead of failing + intermed_script_path: path + no_fail_on_error: bool print_block_results: bool # print blocks one by one as they execute ]: nothing -> string { ( @@ -612,14 +607,14 @@ export def create-highlight-command []: string -> string { | $"($in) | nu-highlight | print(char nl)(char nl)" } -# Trim comments and extra whitespace from code blocks for use in the generated script. +# Trim comments and extra whitespaces from code blocks for use in the generated script. export def remove-comments-plus []: string -> string { str replace -r '^[>\s]+' '' # trim starting `>` | str replace -r '[\s\n]+$' '' # trim newlines and spaces from the end of a line - | str replace -r '\s+#.*$' '' # remove comments from the last line. May affect code blocks where # is used for non-comment purposes + | str replace -r '\s+#.*$' '' # remove comments from the last line. Might spoil code blocks with the # symbol, used not for commenting } -# Extract the last span from a command to determine if `| print` can be appended. +# Extract the last span from a command to determine if `| print` can be appended # # > get-last-span 'let a = 1..10; $a | length' # length @@ -664,7 +659,7 @@ export def get-last-span [ | str substring $len.. } -# Check if the command can have `| print` appended by analyzing its last span for semicolons or declaration keywords. +# Check if the last span of the input ends with a semicolon or contains certain keywords to determine if appending ` | print` is possible. # # > check-print-append 'let a = ls' # false @@ -691,7 +686,7 @@ export def check-print-append [ # > 'ls' | create-indented-output # ls | table | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) export def create-indented-output [ - --indent: string = '# => ' # prefix string for each output line + --indent: string = '# => ' ]: string -> string { generate-table-statement | $"($in) | default '' | into string | lines | each {$'($indent)\($in\)' | str trim --right} | str join \(char nl\) | str replace -r '\\s*$' \"\\n\"" @@ -738,21 +733,19 @@ export def create-catch-error-outside []: string -> string { # Generate a fenced code block for output with a specific format. export def create-fence-output []: string -> string { - # We use a combination of "\n" and (char nl) here for intermediate script formatting aesthetics + # We use a combination of "\n" and (char nl) here for itermid script formatting aesthetics $"\"```\\n```output-numd\" | print(char nl)(char nl)($in)" } -# Join a list of strings and generate a print statement for the combined output. export def generate-print-lines []: list -> string { str join (char nl) | escape-special-characters-and-quote | $'($in) | print' } -# Generate marker tags and code block delimiters for tracking output in the intermediate script. export def generate-tags [ - block_number: int # index of the code block in the markdown - fence: string # the original fence line (e.g., '```nushell') + block_number: int + fence: string ]: list -> string { let input = $in @@ -799,9 +792,9 @@ export def modify-path [ | path join } -# Create a backup of a file by moving it to a subdirectory with a timestamp suffix. +# Create a backup of a file by moving it to a specified directory with a timestamp. export def create-file-backup [ - file_path: path # path to the file to back up + file_path: path ]: nothing -> nothing { $file_path | if ($in | path exists) and ($in | path type) == 'file' { @@ -810,13 +803,12 @@ export def create-file-backup [ } } -# TODO: make config an env record +#todo make config - an env record -# Load numd configuration from a YAML file or command-line options into the environment. export def --env load-config [ - path: path # path to a .yaml numd config file - --prepend_code: string # code to prepend to the intermediate script - --table_width: int # width for table output formatting + path: path # path to .yaml numd config file + --prepend_code: string + --table_width: int ]: nothing -> nothing { $env.numd = ( [ @@ -834,7 +826,7 @@ export def --env load-config [ } else { } | where value != null | if ($in | is-empty) { {} } else { - # if table_width or prepend code are set via parameters - they will have precedence + # if table_width or prepend code are set via parameters - they will have precendece transpose --ignore-titles --as-record --header-row } ) diff --git a/z_examples/2_numd_commands_explanations/numd_commands_explanations.md b/z_examples/2_numd_commands_explanations/numd_commands_explanations.md index 5ae55ac..26fa2a8 100644 --- a/z_examples/2_numd_commands_explanations/numd_commands_explanations.md +++ b/z_examples/2_numd_commands_explanations/numd_commands_explanations.md @@ -97,7 +97,7 @@ The `generate-intermediate-script` command generates a script that contains code let $intermediate_script_path = $file | modify-path --prefix $'numd-temp-(generate-timestamp)' --suffix '.nu' -decorate-original-code-blocks $original_md_table +decortate-original-code-blocks $original_md_table | generate-intermediate-script | save -f $intermediate_script_path diff --git a/z_examples/2_numd_commands_explanations/numd_commands_explanations.md_intermed.nu b/z_examples/2_numd_commands_explanations/numd_commands_explanations.md_intermed.nu index 12c1874..ebd037e 100644 --- a/z_examples/2_numd_commands_explanations/numd_commands_explanations.md_intermed.nu +++ b/z_examples/2_numd_commands_explanations/numd_commands_explanations.md_intermed.nu @@ -59,7 +59,7 @@ $original_md_table | table -e --width 120 | table --width 120 | default '' | int let $intermediate_script_path = $file | modify-path --prefix $'numd-temp-(generate-timestamp)' --suffix '.nu' -decorate-original-code-blocks $original_md_table +decortate-original-code-blocks $original_md_table | generate-intermediate-script | save -f $intermediate_script_path @@ -71,7 +71,7 @@ open $intermediate_script_path" | nu-highlight | print let $intermediate_script_path = $file | modify-path --prefix $'numd-temp-(generate-timestamp)' --suffix '.nu' -decorate-original-code-blocks $original_md_table +decortate-original-code-blocks $original_md_table | generate-intermediate-script | save -f $intermediate_script_path diff --git a/z_examples/4_book_working_with_lists/working_with_lists.md b/z_examples/4_book_working_with_lists/working_with_lists.md index 3181d10..b107d38 100644 --- a/z_examples/4_book_working_with_lists/working_with_lists.md +++ b/z_examples/4_book_working_with_lists/working_with_lists.md @@ -389,9 +389,9 @@ Output: ``` # => ╭────────Zone────────┬───────Time───────╮ -# => │ UTC │ 2025.12.11 19:01 │ -# => │ CET │ 2025.12.11 20:01 │ -# => │ Europe/Moscow │ 2025.12.11 22:01 │ -# => │ Asia/Yekaterinburg │ 2025.12.12 00:01 │ +# => │ UTC │ 2025.12.10 20:16 │ +# => │ CET │ 2025.12.10 21:16 │ +# => │ Europe/Moscow │ 2025.12.10 23:16 │ +# => │ Asia/Yekaterinburg │ 2025.12.11 01:16 │ # => ╰────────Zone────────┴───────Time───────╯ ``` diff --git a/z_examples/6_edge_cases/error-with-try.md b/z_examples/6_edge_cases/error-with-try.md index 65f3464..784dd72 100644 --- a/z_examples/6_edge_cases/error-with-try.md +++ b/z_examples/6_edge_cases/error-with-try.md @@ -17,6 +17,7 @@ # => : ^^^^^|^^^^^ # => : `-- Command `lssomething` not found # => `---- -# => help: `lssomething` is neither a Nushell built-in or a known external command +# => help: `lssomething` is neither a Nushell built-in or a known external +# => command # => ``` diff --git a/z_examples/99_strip_markdown/numd_commands_explanations.nu b/z_examples/99_strip_markdown/numd_commands_explanations.nu index 13a78cc..4bdcaf4 100644 --- a/z_examples/99_strip_markdown/numd_commands_explanations.nu +++ b/z_examples/99_strip_markdown/numd_commands_explanations.nu @@ -23,7 +23,7 @@ $original_md_table | table -e --width 120 let $intermediate_script_path = $file | modify-path --prefix $'numd-temp-(generate-timestamp)' --suffix '.nu' -decorate-original-code-blocks $original_md_table +decortate-original-code-blocks $original_md_table | generate-intermediate-script | save -f $intermediate_script_path From 9d43acde544251feb03e53295ff76c7de1eae26b Mon Sep 17 00:00:00 2001 From: maxim Date: Wed, 10 Dec 2025 21:21:41 -0300 Subject: [PATCH 03/21] todo: add --- todo/20251210-171238-unquoted-notation.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 todo/20251210-171238-unquoted-notation.md diff --git a/todo/20251210-171238-unquoted-notation.md b/todo/20251210-171238-unquoted-notation.md new file mode 100644 index 0000000..951340a --- /dev/null +++ b/todo/20251210-171238-unquoted-notation.md @@ -0,0 +1,18 @@ +--- +status: draft +created: 20251210-171238 +updated: 20251210-171238 +--- +Now we have notation, + +2. In code blocks that do not contain any lines starting with the `>` symbol, `numd` executes the entire code block as is. If the code produces any output, the output is added next to the code block after an empty line, a line with the word `Output:`, and another empty line. The output is enclosed in code fences without a language identifier. +3. In code blocks that contain one or more lines starting with the `>` symbol, `numd` filters only lines that start with the `>` or `#` symbol. It executes or prints those lines one by one, and outputs the results immediately after the executed line. + + +So I would like to get rid of `>` notation for distinguishing commands to execute. + +Numd now should parse the block totaly, execute commands delimited by blocks of double new lines, to put their output (if there are any them into `# =>`-starting lines just after those blocks). + +And produce separte blocks if there is `separate-block` option in the fence. + +First, rewrite todo for clarity and ask user for confirmation. From 45a56baebfca2e5877ded4f8919ceac0b73ab214 Mon Sep 17 00:00:00 2001 From: claude Date: Wed, 10 Dec 2025 21:26:20 -0300 Subject: [PATCH 04/21] docs: clarify task requirements for removing unquoted notation Updated todo file to define clear implementation goals for removing the `>` notation from numd code block execution. The new approach will parse entire blocks, group commands by double newlines, and output results in `# =>` comment lines. --- todo/20251210-171238-unquoted-notation.md | 83 ++++++++++++++++++++--- 1 file changed, 74 insertions(+), 9 deletions(-) diff --git a/todo/20251210-171238-unquoted-notation.md b/todo/20251210-171238-unquoted-notation.md index 951340a..99020a1 100644 --- a/todo/20251210-171238-unquoted-notation.md +++ b/todo/20251210-171238-unquoted-notation.md @@ -1,18 +1,83 @@ --- -status: draft +status: in-progress created: 20251210-171238 updated: 20251210-171238 --- -Now we have notation, -2. In code blocks that do not contain any lines starting with the `>` symbol, `numd` executes the entire code block as is. If the code produces any output, the output is added next to the code block after an empty line, a line with the word `Output:`, and another empty line. The output is enclosed in code fences without a language identifier. -3. In code blocks that contain one or more lines starting with the `>` symbol, `numd` filters only lines that start with the `>` or `#` symbol. It executes or prints those lines one by one, and outputs the results immediately after the executed line. - +## Goal: Remove `>` Notation for Command Execution -So I would like to get rid of `>` notation for distinguishing commands to execute. +### Current Behavior (to be removed) +- Code blocks **with** `>` prefix: lines starting with `>` or `#` are filtered, executed one-by-one, results output immediately after each line +- Code blocks **without** `>` prefix: entire block executed as single unit, output appended after block -Numd now should parse the block totaly, execute commands delimited by blocks of double new lines, to put their output (if there are any them into `# =>`-starting lines just after those blocks). +### New Behavior +1. **Parse entire block** without `>` notation +2. **Group commands by double newlines** (blank lines delimit command groups) +3. **Output results** in `# =>` comment lines immediately after each command group +4. **`separate-block` option** in fence produces separate output blocks instead of inline comments +5. **On re-run**: `# =>` lines are stripped and regenerated; plain `#` comments are preserved -And produce separte blocks if there is `separate-block` option in the fence. +### Example -First, rewrite todo for clarity and ask user for confirmation. +Input: +```nushell +ls | length + +ls +| length + +echo "hello" +``` + +Output after execution: +```nushell +ls | length +# => 5 + +ls +| length +# => 5 + +echo "hello" +# => hello +``` + +With `separate-block` fence option, output goes into a separate code fence instead of inline. + +## Functions to Modify in `numd/commands.nu` + +### Primary Changes + +| Function | Lines | Current Role | Change Required | +|----------|-------|--------------|-----------------| +| `execute-block-lines` | 386-409 | Detects `>` prefix, branches to line-by-line vs whole-block | Rewrite: split by blank lines, execute each group, insert `# =>` output | +| `remove-comments-plus` | 611-615 | Strips `>` prefix before execution | Remove `>` stripping logic | +| `clear-outputs` | 79-121 | Preserves `>` lines, removes `# =>` | Remove `>` preservation, keep `# =>` stripping | +| `capture start` | 124-172 | Generates `> command` format | Remove `>` notation generation | +| `create-indented-output` | 688-693 | Generates `# => ` prefix for output | Keep, but adjust calling context | + +### Supporting Changes + +| Function | Lines | Role | Change | +|----------|-------|------|--------| +| `create-execution-code` | ~360-385 | Wraps code for execution | May need adjustment for group-based execution | +| `decortate-original-code-blocks` | ~320-360 | Calls `execute-block-lines` | Update to pass groups | +| `create-highlight-command` | ~617-625 | Highlights comment lines | Review if still needed | + +### New Code Required + +- [ ] Function to split block content by blank lines into command groups +- [ ] Logic to execute each group and capture output +- [ ] Insert `# =>` lines after each group in the result + +## Implementation Tasks + +- [ ] Rewrite `execute-block-lines` for blank-line grouping +- [ ] Remove `>` stripping from `remove-comments-plus` +- [ ] Update `clear-outputs` to not preserve `>` lines +- [ ] Update `capture start` to remove `>` notation generation +- [ ] Add `separate-block` fence option support +- [ ] Update README.md documentation +- [ ] Update example files in `z_examples/` +- [ ] Add/update unit tests in `tests/test_commands.nu` +- [ ] Run integration tests and verify From b0e910626b401f3326e06427a8135f683581d265 Mon Sep 17 00:00:00 2001 From: claude Date: Wed, 10 Dec 2025 21:50:21 -0300 Subject: [PATCH 05/21] feat: remove > notation, use blank-line grouping for commands - Rewrite execute-block-lines to split by blank lines instead of > prefix - Add split-by-blank-lines helper function - Remove > stripping from remove-comments-plus - Update clear-outputs to not preserve > lines - Update capture start to use inline # => output format - Add separate-block fence option for separate output blocks - Change create-execution-code to use separate-block option --- numd/commands.nu | 62 ++++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/numd/commands.nu b/numd/commands.nu index 5feb1a3..18a5750 100644 --- a/numd/commands.nu +++ b/numd/commands.nu @@ -93,10 +93,7 @@ export def clear-outputs [ | group-by block_index | items {|block_index block_lines| $block_lines.line.0 - | where $it !~ '^# => ?' - | if ($in | where $it =~ '^>' | is-empty) { } else { - where $it =~ '^(>|#|```)' - } + | where $it !~ '^# => ?' # strip `# =>` output lines, preserve plain `#` comments | prepend (mark-code-block $block_index) } | flatten @@ -107,7 +104,6 @@ export def clear-outputs [ lines | update 0 { $'(char nl) # ($in)' } # keep infostring | drop - | str replace --all --regex '^>\s*' '' | str join (char nl) | str replace -r '\s*$' (char nl) } @@ -123,7 +119,7 @@ export def clear-outputs [ # start capturing commands and their outputs into a file export def --env 'capture start' [ file: path = 'numd_capture.md' - --separate # don't use `>` notation, create separate blocks for each pipeline + --separate-blocks # create separate code blocks for each pipeline instead of inline `# =>` output ]: nothing -> nothing { cprint $'numd commands capture has been started. Commands and their outputs of the current nushell instance @@ -134,9 +130,9 @@ export def --env 'capture start' [ $env.numd.status = 'running' $env.numd.path = ($file | path expand) - $env.numd.separate-blocks = $separate + $env.numd.separate-blocks = $separate_blocks - if not $separate { "```nushell\n" | save -a $env.numd.path } + if not $separate_blocks { "```nushell\n" | save -a $env.numd.path } $env.backup.hooks.display_output = ( $env.config.hooks?.display_output? @@ -159,7 +155,9 @@ export def --env 'capture start' [ $"```nushell\n($command)\n```\n```output-numd\n($in)\n```\n\n" | str replace --regex --all "[\n\r ]+```\n" "\n```\n" } else { - $"> ($command)\n($in)\n\n" + # inline output format: command followed by `# =>` prefixed output + let output_lines = $in | lines | each {$'# => ($in)'} | str join (char nl) + $"($command)\n($output_lines)\n\n" } | str replace --regex "\n{3,}$" "\n\n" | if ($in !~ 'numd capture') { @@ -340,7 +338,9 @@ export def create-execution-code [ } } else { } | if 'no-output' in $fence_options { } else { - if $whole_block { create-fence-output } else { } + # separate-block: output goes to a separate ```output-numd``` fence + # default: output is inline with `# =>` prefix + if 'separate-block' in $fence_options { create-fence-output } else { } | if (check-print-append $in) { create-indented-output | generate-print-statement @@ -383,31 +383,35 @@ export def generate-intermediate-script []: table` output. export def execute-block-lines [ fence_options: list ]: list -> list { skip | drop # skip code fences - | if ($in | where $it =~ '^>' | is-empty) { - # find blocks with no `>` symbol to execute them entirely - str join (char nl) - | create-execution-code $fence_options --whole_block - | [$in] # quick fix so the `execute-block-lines` would always output lists. Should be refactored. - } else { - each { - # define what to do with each line of the current block one by one - if $in starts-with '>' { - # if a line starts with `>`, execute it - create-execution-code $fence_options - } else if $in starts-with '#' { - if $in !~ '# =>' { - # if a line starts with `#`, print it - create-highlight-command - } - } + | where not ($it =~ '^# =>') # strip existing `# =>` output lines (keep plain `#` comments) + | str join (char nl) + | split-by-blank-lines + | each {|group| + if ($group | str trim | is-empty) { + # preserve blank line separators + '' + } else if ($group | str trim | str starts-with '#') and ($group | str trim | lines | all {|line| $line =~ '^#'}) { + # pure comment group - just highlight it + $group | create-highlight-command + } else { + # executable command group + $group | create-execution-code $fence_options --whole_block } } } +# Split string by blank lines (double newlines) into command groups. +# Preserves multiline commands that don't have blank lines between them. +export def split-by-blank-lines []: string -> list { + split row "\n\n" + | each { str trim -c "\n" } +} + # Parse block indices from Nushell output lines and return a table with the original markdown line numbers. export def extract-block-index []: list -> table { let clean_lines = skip until {|x| $x =~ (mark-code-block) } @@ -527,6 +531,7 @@ export def list-code-options [ ["no-run" "N" "do not execute code in block"] ["try" "t" "execute block inside `try {}` for error handling"] ["new-instance" "n" "execute block in new Nushell instance (useful with `try` block)"] + ["separate-block" "s" "output results in a separate code block instead of inline `# =>`"] # ["picture-output" "p" "capture output as picture and place after block"] ] | if $list { } else { @@ -609,8 +614,7 @@ export def create-highlight-command []: string -> string { # Trim comments and extra whitespaces from code blocks for use in the generated script. export def remove-comments-plus []: string -> string { - str replace -r '^[>\s]+' '' # trim starting `>` - | str replace -r '[\s\n]+$' '' # trim newlines and spaces from the end of a line + str replace -r '[\s\n]+$' '' # trim newlines and spaces from the end of a line | str replace -r '\s+#.*$' '' # remove comments from the last line. Might spoil code blocks with the # symbol, used not for commenting } From 5b6c609c738caa1799a4ff492651e11f11578dff Mon Sep 17 00:00:00 2001 From: claude Date: Wed, 10 Dec 2025 21:50:28 -0300 Subject: [PATCH 06/21] docs: update README for blank-line grouping format - Update code block parsing explanation (6-point list) - Remove > notation from all code examples - Update help output examples - Remove reference to deleted types_of_data example --- README.md | 85 ++++++++++++++++++++++++------------------------------- 1 file changed, 37 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index 6776cef..91274f6 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,13 @@ Execute blocks of nushell code within markdown documents, write results back to ```nushell no-run # this block won't run as it has the option `no-run` in its code fence -> git clone https://github.com/nushell-prophet/numd; cd numd -> nupm install --force --path . # optionally you can install this module via nupm -> use numd -> numd run README.md --no-save +git clone https://github.com/nushell-prophet/numd; cd numd + +nupm install --force --path . # optionally you can install this module via nupm + +use numd + +numd run README.md --no-save ``` ## How it works @@ -21,14 +24,17 @@ Experienced nushell users can understand the logic better by looking at [example ### Details on parsing code blocks and displaying the output 1. `numd` looks for code blocks marked with ` ```nushell ` or ` ```nu `. -2. In code blocks that do not contain any lines starting with the `>` symbol, `numd` executes the entire code block as is. If the code produces any output, the output is added next to the code block after an empty line, a line with the word `Output:`, and another empty line. The output is enclosed in code fences without a language identifier. -3. In code blocks that contain one or more lines starting with the `>` symbol, `numd` filters only lines that start with the `>` or `#` symbol. It executes or prints those lines one by one, and outputs the results immediately after the executed line. +2. Code blocks are split into command groups by blank lines (double newlines). Each command group is executed separately. +3. Output from each command group is displayed inline with `# =>` prefix immediately after the command. +4. Multiline commands (pipelines split across lines without blank lines) are treated as a single command group. +5. Plain `#` comments are preserved; `# =>` output lines are regenerated on each run. +6. Use the `separate-block` fence option to output results in a separate code block instead of inline. ### `numd run` flags and params ```nushell -> use numd -> numd run --help +use numd +numd run --help # => Run Nushell code blocks in a markdown file, output results back to the `.md`, and optionally to terminal # => # => Usage: @@ -66,13 +72,14 @@ Experienced nushell users can understand the logic better by looking at [example `numd` understands the following block options. Several comma-separated block options will be combined together. The block options should be in the [infostring](https://github.github.com/gfm/#info-string) of the opening code fence like the example: ` ```nushell try, new-instance ` ```nushell -> numd list-code-options --list -# => ╭─────long─────┬─short─┬───────────────────────────description───────────────────────────╮ -# => │ no-output │ O │ execute code without outputting results │ -# => │ no-run │ N │ do not execute code in block │ -# => │ try │ t │ execute block inside `try {}` for error handling │ -# => │ new-instance │ n │ execute block in new Nushell instance (useful with `try` block) │ -# => ╰─────long─────┴─short─┴───────────────────────────description───────────────────────────╯ +numd list-code-options --list +# => ╭──────long──────┬─short─┬───────────────────────────description────────────────────────────╮ +# => │ no-output │ O │ execute code without outputting results │ +# => │ no-run │ N │ do not execute code in block │ +# => │ try │ t │ execute block inside `try {}` for error handling │ +# => │ new-instance │ n │ execute block in new Nushell instance (useful with `try` block) │ +# => │ separate-block │ s │ output results in a separate code block instead of inline `# =>` │ +# => ╰──────long──────┴─short─┴───────────────────────────description────────────────────────────╯ ``` ### Stats of changes @@ -80,15 +87,15 @@ Experienced nushell users can understand the logic better by looking at [example By default, `numd` provides basic stats on changes made. ```nushell -> let path = [z_examples 1_simple_markdown simple_markdown_with_no_output.md] | path join -> numd run --no-save $path +let path = [z_examples 1_simple_markdown simple_markdown_with_no_output.md] | path join +numd run --no-save $path # => ╭──────────────────┬───────────────────────────────────╮ # => │ filename │ simple_markdown_with_no_output.md │ # => │ nushell_blocks │ 3 │ -# => │ levenshtein_dist │ 53 │ -# => │ diff_lines │ +9 (30.0%) │ -# => │ diff_words │ +6 (8.7%) │ -# => │ diff_chars │ +53 (12.1%) │ +# => │ levenshtein_dist │ 34 │ +# => │ diff_lines │ +3 (9.7%) │ +# => │ diff_words │ +5 (7.2%) │ +# => │ diff_chars │ +34 (7.8%) │ # => ╰──────────────────┴───────────────────────────────────╯ ``` @@ -98,7 +105,6 @@ It is possible to set Nushell visual settings (and all the others) using the `-- ```nushell let path = $nu.temp-path | path join simple_nu_table.md - # let's generate some markdown and save it to the `simple_nu_table.md` file in the temp directory "```nushell\n[[a b c]; [1 2 3]]\n```\n" | save -f $path @@ -109,18 +115,8 @@ numd run $path --echo --no-save --no-stats --prepend-code " $env.config.table.index_mode = 'never' $env.config.table.mode = 'basic_compact' " -``` - -Output: - -``` # => ```nushell # => [[a b c]; [1 2 3]] -# => ``` -# => -# => Output: -# => -# => ``` # => # => +---+---+---+ # => # => | a | b | c | # => # => | 1 | 2 | 3 | @@ -131,7 +127,7 @@ Output: ### `numd clear-outputs` ```nu -> numd clear-outputs --help +numd clear-outputs --help # => Remove numd execution outputs from the file # => # => Usage: @@ -159,7 +155,7 @@ Output: `numd` can use the `display_output` hook to write the current session prompts together with their output into a specified markdown file. There are corresponding commands `numd capture start` and `numd capture stop`. ```nushell -> numd capture start --help +numd capture start --help # => start capturing commands and their outputs into a file # => # => Usage: @@ -167,7 +163,7 @@ Output: # => # => Flags: # => -h, --help: Display the help message for this command -# => --separate: don't use `>` notation, create separate blocks for each pipeline +# => --separate-blocks: create separate code blocks for each pipeline instead of inline `# =>` output # => # => Parameters: # => file : (optional, default: 'numd_capture.md') @@ -180,7 +176,7 @@ Output: ``` ```nushell -> numd capture stop --help +numd capture stop --help # => stop capturing commands and their outputs # => # => Usage: @@ -199,11 +195,10 @@ Output: ### Some random familiar examples ```nushell -> ls z_examples | sort-by name | reject modified size +ls z_examples | sort-by name | reject modified size # => ╭──────────────────name───────────────────┬─type─╮ # => │ z_examples/1_simple_markdown │ dir │ # => │ z_examples/2_numd_commands_explanations │ dir │ -# => │ z_examples/3_book_types_of_data │ dir │ # => │ z_examples/4_book_working_with_lists │ dir │ # => │ z_examples/5_simple_nu_table │ dir │ # => │ z_examples/6_edge_cases │ dir │ @@ -213,13 +208,13 @@ Output: # => │ z_examples/9_other │ dir │ # => ╰──────────────────name───────────────────┴─type─╯ -> sys host | get boot_time -# => Fri Dec 5 01:08:37 2025 +sys host | get boot_time +# => Fri Dec 5 03:49:33 2025 -> 2 + 2 +2 + 2 # => 4 -> git tag | lines | sort -n | last +git tag | lines | sort -n | last # => 0.1.21 ``` @@ -230,12 +225,6 @@ Output: [z_examples 1_simple_markdown simple_markdown.md] | path join | numd run $in --echo --no-save - -# run examples in the `types_of_data.md` file, -# save intermed nushell script to `types_of_data.md_intermed_from_readme.nu` -[z_examples 3_book_types_of_data types_of_data.md] -| path join -| numd run $in --no-backup --save-intermed-script $'($in)_intermed_from_readme.nu' ``` ## Development and testing From c64dcc5628d83cc689459ba44b3fa92186d1e02b Mon Sep 17 00:00:00 2001 From: claude Date: Wed, 10 Dec 2025 21:50:35 -0300 Subject: [PATCH 07/21] refactor: update example markdown files for new format - Remove > notation from all example files - Update to blank-line grouping format - Regenerate # => output lines --- .../1_simple_markdown/simple_markdown.md | 9 +- .../simple_markdown_with_no_output.md | 5 +- .../numd_commands_explanations.md | 177 +++++++----------- .../working_with_lists.md | 118 +++--------- .../5_simple_nu_table/simple_nu_table.md | 17 +- ...mple_nu_table_customized_example_config.md | 17 +- .../simple_nu_table_customized_width20.md | 17 +- z_examples/6_edge_cases/error-with-try.md | 4 +- z_examples/6_edge_cases/error_customized.md | 2 +- z_examples/6_edge_cases/raw_strings_test.md | 5 - .../simple_markdown_first_block.md | 9 +- 11 files changed, 112 insertions(+), 268 deletions(-) diff --git a/z_examples/1_simple_markdown/simple_markdown.md b/z_examples/1_simple_markdown/simple_markdown.md index b5ab3e9..232a21d 100644 --- a/z_examples/1_simple_markdown/simple_markdown.md +++ b/z_examples/1_simple_markdown/simple_markdown.md @@ -13,11 +13,6 @@ let $var1 = 'foo' ```nu # This block will produce some output in a separate block $var1 | path join 'baz' 'bar' -``` - -Output: - -``` # => foo/baz/bar ``` @@ -25,10 +20,10 @@ Output: ```nu # This block will output results inline -> whoami +whoami # => user -> 2 + 2 +2 + 2 # => 4 ``` diff --git a/z_examples/1_simple_markdown/simple_markdown_with_no_output.md b/z_examples/1_simple_markdown/simple_markdown_with_no_output.md index b4f264e..e244053 100644 --- a/z_examples/1_simple_markdown/simple_markdown_with_no_output.md +++ b/z_examples/1_simple_markdown/simple_markdown_with_no_output.md @@ -19,8 +19,9 @@ $var1 | path join 'baz' 'bar' ```nu # This block will output results inline -> whoami -> 2 + 2 +whoami + +2 + 2 ``` ## Example 4 diff --git a/z_examples/2_numd_commands_explanations/numd_commands_explanations.md b/z_examples/2_numd_commands_explanations/numd_commands_explanations.md index 26fa2a8..80215ce 100644 --- a/z_examples/2_numd_commands_explanations/numd_commands_explanations.md +++ b/z_examples/2_numd_commands_explanations/numd_commands_explanations.md @@ -5,7 +5,6 @@ In the code block below, we set settings and variables for executing this entire ```nu # This setting is for overriding the author's usual small number of `abbreviated_row_count`. $env.config.table.abbreviated_row_count = 100 - # The `$init_numd_pwd_const` constant points to the current working directory from where the `numd` command was initiated. # It is added by `numd` in every intermediate script to make it available in cases like below. # We use `path join` here to construct working paths for both Windows and Unix @@ -21,71 +20,61 @@ This command is used for parsing initial markdown to detect executable code bloc ```nu # Here we set the `$file` variable (which will be used in several commands throughout this script) to point to `z_examples/1_simple_markdown/simple_markdown.md`. let $file = $init_numd_pwd_const | path join z_examples 1_simple_markdown simple_markdown.md - let $md_orig = open -r $file | toggle-output-fences let $original_md_table = $md_orig | find-code-blocks $original_md_table | table -e --width 120 -``` - -Output: - -``` -# => ╭─block_index─┬────row_type────┬───────────────────────────────────line────────────────────────────────────┬──action───╮ -# => │ 0 │ text │ ╭───────────────────────────────────────────────────────────────────────╮ │ print-as- │ -# => │ │ │ │ # This is a simple markdown example │ │ it-is │ -# => │ │ │ │ │ │ │ -# => │ │ │ │ ## Example 1 │ │ │ -# => │ │ │ │ │ │ │ -# => │ │ │ │ the block below will be executed as it is, but won't yield any output │ │ │ -# => │ │ │ │ │ │ │ -# => │ │ │ ╰───────────────────────────────────────────────────────────────────────╯ │ │ -# => │ 1 │ ```nu │ ╭───────────────────╮ │ execute │ -# => │ │ │ │ ```nu │ │ │ -# => │ │ │ │ let $var1 = 'foo' │ │ │ -# => │ │ │ │ ``` │ │ │ -# => │ │ │ ╰───────────────────╯ │ │ -# => │ 2 │ text │ ╭──────────────╮ │ print-as- │ -# => │ │ │ │ │ │ it-is │ -# => │ │ │ │ ## Example 2 │ │ │ -# => │ │ │ │ │ │ │ -# => │ │ │ ╰──────────────╯ │ │ -# => │ 3 │ ```nu │ ╭───────────────────────────────────────────────────────────╮ │ execute │ -# => │ │ │ │ ```nu │ │ │ -# => │ │ │ │ # This block will produce some output in a separate block │ │ │ -# => │ │ │ │ $var1 | path join 'baz' 'bar' │ │ │ -# => │ │ │ │ ``` │ │ │ -# => │ │ │ ╰───────────────────────────────────────────────────────────╯ │ │ -# => │ 4 │ ```output-numd │ ╭──────────────────╮ │ delete │ -# => │ │ │ │ ```output-numd │ │ │ -# => │ │ │ │ # => foo/baz/bar │ │ │ -# => │ │ │ │ ``` │ │ │ -# => │ │ │ ╰──────────────────╯ │ │ -# => │ 5 │ text │ ╭──────────────╮ │ print-as- │ -# => │ │ │ │ │ │ it-is │ -# => │ │ │ │ ## Example 3 │ │ │ -# => │ │ │ │ │ │ │ -# => │ │ │ ╰──────────────╯ │ │ -# => │ 6 │ ```nu │ ╭─────────────────────────────────────────╮ │ execute │ -# => │ │ │ │ ```nu │ │ │ -# => │ │ │ │ # This block will output results inline │ │ │ -# => │ │ │ │ > whoami │ │ │ -# => │ │ │ │ # => user │ │ │ -# => │ │ │ │ │ │ │ -# => │ │ │ │ > 2 + 2 │ │ │ -# => │ │ │ │ # => 4 │ │ │ -# => │ │ │ │ ``` │ │ │ -# => │ │ │ ╰─────────────────────────────────────────╯ │ │ -# => │ 7 │ text │ ╭──────────────╮ │ print-as- │ -# => │ │ │ │ │ │ it-is │ -# => │ │ │ │ ## Example 4 │ │ │ -# => │ │ │ │ │ │ │ -# => │ │ │ ╰──────────────╯ │ │ -# => │ 8 │ ``` │ ╭──────────────────────────────────────────────────────────────────────╮ │ print-as- │ -# => │ │ │ │ ``` │ │ it-is │ -# => │ │ │ │ # This block doesn't have a language identifier in the opening fence │ │ │ -# => │ │ │ │ ``` │ │ │ -# => │ │ │ ╰──────────────────────────────────────────────────────────────────────╯ │ │ -# => ╰─block_index─┴────row_type────┴───────────────────────────────────line────────────────────────────────────┴──action───╯ +# => ╭─block─┬─row_type──┬─────────────────────────────────────line─────────────────────────────────────┬──────action───────╮ +# => │ 0 │ text │ ╭───────────────────────────────────────────────────────────────────────╮ │ print-as-it-is │ +# => │ │ │ │ # This is a simple markdown example │ │ │ +# => │ │ │ │ │ │ │ +# => │ │ │ │ ## Example 1 │ │ │ +# => │ │ │ │ │ │ │ +# => │ │ │ │ the block below will be executed as it is, but won't yield any output │ │ │ +# => │ │ │ │ │ │ │ +# => │ │ │ ╰───────────────────────────────────────────────────────────────────────╯ │ │ +# => │ 1 │ ```nu │ ╭───────────────────╮ │ execute │ +# => │ │ │ │ ```nu │ │ │ +# => │ │ │ │ let $var1 = 'foo' │ │ │ +# => │ │ │ │ ``` │ │ │ +# => │ │ │ ╰───────────────────╯ │ │ +# => │ 2 │ text │ ╭──────────────╮ │ print-as-it-is │ +# => │ │ │ │ │ │ │ +# => │ │ │ │ ## Example 2 │ │ │ +# => │ │ │ │ │ │ │ +# => │ │ │ ╰──────────────╯ │ │ +# => │ 3 │ ```nu │ ╭───────────────────────────────────────────────────────────╮ │ execute │ +# => │ │ │ │ ```nu │ │ │ +# => │ │ │ │ # This block will produce some output in a separate block │ │ │ +# => │ │ │ │ $var1 | path join 'baz' 'bar' │ │ │ +# => │ │ │ │ # => foo/baz/bar │ │ │ +# => │ │ │ │ ``` │ │ │ +# => │ │ │ ╰───────────────────────────────────────────────────────────╯ │ │ +# => │ 4 │ text │ ╭──────────────╮ │ print-as-it-is │ +# => │ │ │ │ │ │ │ +# => │ │ │ │ ## Example 3 │ │ │ +# => │ │ │ │ │ │ │ +# => │ │ │ ╰──────────────╯ │ │ +# => │ 5 │ ```nu │ ╭─────────────────────────────────────────╮ │ execute │ +# => │ │ │ │ ```nu │ │ │ +# => │ │ │ │ # This block will output results inline │ │ │ +# => │ │ │ │ whoami │ │ │ +# => │ │ │ │ # => user │ │ │ +# => │ │ │ │ │ │ │ +# => │ │ │ │ 2 + 2 │ │ │ +# => │ │ │ │ # => 4 │ │ │ +# => │ │ │ │ ``` │ │ │ +# => │ │ │ ╰─────────────────────────────────────────╯ │ │ +# => │ 6 │ text │ ╭──────────────╮ │ print-as-it-is │ +# => │ │ │ │ │ │ │ +# => │ │ │ │ ## Example 4 │ │ │ +# => │ │ │ │ │ │ │ +# => │ │ │ ╰──────────────╯ │ │ +# => │ 7 │ ``` │ ╭──────────────────────────────────────────────────────────────────────╮ │ print-as-it-is │ +# => │ │ │ │ ``` │ │ │ +# => │ │ │ │ # This block doesn't have a language identifier in the opening fence │ │ │ +# => │ │ │ │ ``` │ │ │ +# => │ │ │ ╰──────────────────────────────────────────────────────────────────────╯ │ │ +# => ╰─block─┴─row_type──┴─────────────────────────────────────line─────────────────────────────────────┴──────action───────╯ ``` ## generate-intermediate-script @@ -96,17 +85,11 @@ The `generate-intermediate-script` command generates a script that contains code # Here we emulate that the `$intermed_script_path` options is not set let $intermediate_script_path = $file | modify-path --prefix $'numd-temp-(generate-timestamp)' --suffix '.nu' - decortate-original-code-blocks $original_md_table | generate-intermediate-script | save -f $intermediate_script_path open $intermediate_script_path -``` - -Output: - -``` # => # this script was generated automatically using numd # => # https://github.com/nushell-prophet/numd # => @@ -116,8 +99,6 @@ Output: # => ```nu" | print # => "let $var1 = 'foo'" | nu-highlight | print # => -# => "```\n```output-numd" | print -# => # => let $var1 = 'foo' # => # => "```" | print @@ -127,23 +108,20 @@ Output: # => "# This block will produce some output in a separate block # => $var1 | path join 'baz' 'bar'" | nu-highlight | print # => -# => "```\n```output-numd" | print -# => # => # This block will produce some output in a separate block # => $var1 | path join 'baz' 'bar' | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' # => # => "```" | print # => -# => "#code-block-marker-open-6 +# => "#code-block-marker-open-5 # => ```nu" | print -# => "# This block will output results inline" | nu-highlight | print -# => -# => -# => "> whoami" | nu-highlight | print +# => "# This block will output results inline +# => whoami" | nu-highlight | print # => +# => # This block will output results inline # => whoami | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' # => -# => "> 2 + 2" | nu-highlight | print +# => "2 + 2" | nu-highlight | print # => # => 2 + 2 | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' # => @@ -157,39 +135,29 @@ The `execute-intermediate-script` command runs and captures outputs of the execu ```nu # the flag `$no_fail_on_error` is set to false let $no_fail_on_error = false - let $nu_res_stdout_lines = execute-intermediate-script $intermediate_script_path $no_fail_on_error false rm $intermediate_script_path $nu_res_stdout_lines -``` - -Output: - -``` # => #code-block-marker-open-1 # => ```nu # => let $var1 = 'foo' # => ``` -# => ```output-numd -# => ``` # => #code-block-marker-open-3 # => ```nu # => # This block will produce some output in a separate block # => $var1 | path join 'baz' 'bar' -# => ``` -# => ```output-numd # => # => foo/baz/bar # => # => # => ``` -# => #code-block-marker-open-6 +# => #code-block-marker-open-5 # => ```nu # => # This block will output results inline -# => > whoami +# => whoami # => # => user # => # => -# => > 2 + 2 +# => 2 + 2 # => # => 4 # => # => @@ -200,13 +168,7 @@ Output: let $md_res = $nu_res_stdout_lines | str join (char nl) | clean-markdown - $md_res -``` - -Output: - -``` # => #code-block-marker-open-1 # => ```nu # => let $var1 = 'foo' @@ -215,18 +177,16 @@ Output: # => ```nu # => # This block will produce some output in a separate block # => $var1 | path join 'baz' 'bar' -# => ``` -# => ```output-numd # => # => foo/baz/bar # => # => ``` -# => #code-block-marker-open-6 +# => #code-block-marker-open-5 # => ```nu # => # This block will output results inline -# => > whoami +# => whoami # => # => user # => -# => > 2 + 2 +# => 2 + 2 # => # => 4 # => # => ``` @@ -238,17 +198,12 @@ The `compute-change-stats` command displays stats on the changes made. ```nu compute-change-stats $file $md_orig $md_res -``` - -Output: - -``` # => ╭──────────────────┬────────────────────╮ # => │ filename │ simple_markdown.md │ # => │ nushell_blocks │ 3 │ # => │ levenshtein_dist │ 247 │ -# => │ diff_lines │ -13 (-36.1%) │ -# => │ diff_words │ -24 (-31.6%) │ -# => │ diff_chars │ -164 (-33.4%) │ +# => │ diff_lines │ -13 (-38.2%) │ +# => │ diff_words │ -24 (-32.4%) │ +# => │ diff_chars │ -164 (-35.0%) │ # => ╰──────────────────┴────────────────────╯ ``` diff --git a/z_examples/4_book_working_with_lists/working_with_lists.md b/z_examples/4_book_working_with_lists/working_with_lists.md index b107d38..8887dc0 100644 --- a/z_examples/4_book_working_with_lists/working_with_lists.md +++ b/z_examples/4_book_working_with_lists/working_with_lists.md @@ -4,7 +4,7 @@ Lists are equivalent to the individual columns of tables. You can think of a list as essentially being a "one-column table" (with no column name). Thus, any command which operates on a column _also_ operates on a list. For instance, [`where`](/commands/docs/where.md) can be used with lists: ```nu -> [bell book candle] | where ($it =~ 'b') +[bell book candle] | where ($it =~ 'b') # => ╭──────╮ # => │ bell │ # => │ book │ @@ -28,7 +28,7 @@ Nushell lists are similar to JSON arrays. The same `[ "Item1", "Item2", "Item3" We can [`insert`](/commands/docs/insert.md) values into lists as they flow through the pipeline, for example let's insert the value `10` into the middle of a list: ```nu -> [1, 2, 3, 4] | insert 2 10 +[1, 2, 3, 4] | insert 2 10 # => ╭────╮ # => │ 1 │ # => │ 2 │ @@ -43,7 +43,7 @@ We can [`insert`](/commands/docs/insert.md) values into lists as they flow throu We can also use [`update`](/commands/docs/update.md) to replace the 2nd element with the value `10`. ```nu -> [1, 2, 3, 4] | update 1 10 +[1, 2, 3, 4] | update 1 10 # => ╭────╮ # => │ 1 │ # => │ 10 │ @@ -66,11 +66,6 @@ let colors = ($colors | prepend red) let colors = ($colors | append purple) let colors = ("black" | append $colors) $colors # [black red yellow green purple blue] -``` - -Output: - -``` # => ╭────────╮ # => │ black │ # => │ red │ @@ -87,11 +82,6 @@ let colors = [red yellow green purple] let colors = ($colors | skip 1) let colors = ($colors | drop 2) $colors # [yellow] -``` - -Output: - -``` # => ╭────────╮ # => │ yellow │ # => ╰────────╯ @@ -103,11 +93,6 @@ We also have [`last`](/commands/docs/last.md) and [`first`](/commands/docs/first let colors = [red yellow green purple black magenta] let colors = ($colors | last 3) $colors # [purple black magenta] -``` - -Output: - -``` # => ╭─────────╮ # => │ purple │ # => │ black │ @@ -121,11 +106,6 @@ And from the beginning of a list, let colors = [yellow green purple] let colors = ($colors | first 2) $colors # [yellow green] -``` - -Output: - -``` # => ╭────────╮ # => │ yellow │ # => │ green │ @@ -138,8 +118,8 @@ To append one or more lists together, optionally with values interspersed in bet [spread operator](/book/operators#spread-operator) (`...`): ```nu -> let x = [1 2] -> [ ...$x 3 ...(4..7 | take 2) ] +let x = [1 2] +[ ...$x 3 ...(4..7 | take 2) ] # => ╭───╮ # => │ 1 │ # => │ 2 │ @@ -159,14 +139,15 @@ item, but the [`enumerate`](/commands/docs/enumerate.md) filter can be used to p let names = [Mark Tami Amanda Jeremy] $names | each { |elt| $"Hello, ($elt)!" } # Outputs "Hello, Mark!" and three more similar lines. +# => ╭────────────────╮ +# => │ Hello, Mark! │ +# => │ Hello, Tami! │ +# => │ Hello, Amanda! │ +# => │ Hello, Jeremy! │ +# => ╰────────────────╯ $names | enumerate | each { |elt| $"($elt.index + 1) - ($elt.item)" } # Outputs "1 - Mark", "2 - Tami", etc. -``` - -Output: - -``` # => ╭────────────╮ # => │ 1 - Mark │ # => │ 2 - Tami │ @@ -191,11 +172,6 @@ In this example, we keep only values higher than `7`. ```nu let scores = [7 10 8 6 7] $scores | where $it > 7 # [10 8] -``` - -Output: - -``` # => ╭────╮ # => │ 10 │ # => │ 8 │ @@ -211,17 +187,9 @@ For example: ```nu let scores = [3 8 4] $"total = ($scores | reduce { |elt, acc| $acc + $elt })" # total = 15 - $"total = ($scores | math sum)" # easier approach, same result - $"product = ($scores | reduce --fold 1 { |elt, acc| $acc * $elt })" # product = 96 - $scores | enumerate | reduce --fold 0 { |elt, acc| $acc + $elt.index * $elt.item } # 0*3 + 1*8 + 2*4 = 16 -``` - -Output: - -``` # => 16 ``` @@ -238,11 +206,6 @@ For example, the second element in the list below can be accessed with `$names.1 ```nu let names = [Mark Tami Amanda Jeremy] $names.1 # gives Tami -``` - -Output: - -``` # => Tami ``` @@ -252,11 +215,6 @@ If the index is in some variable `$index` we can use the `get` command to extrac let names = [Mark Tami Amanda Jeremy] let index = 1 $names | get $index # gives Tami -``` - -Output: - -``` # => Tami ``` @@ -269,14 +227,10 @@ It can be used with lists as follows: ```nu let colors = [red green blue] $colors | is-empty # false +# => false let colors = [] $colors | is-empty # true -``` - -Output: - -``` # => true ``` @@ -287,11 +241,6 @@ let colors = [red green blue] 'blue' in $colors # true 'yellow' in $colors # false 'gold' not-in $colors # true -``` - -Output: - -``` # => true ``` @@ -303,21 +252,19 @@ For example: let colors = [red green blue] # Do any color names end with "e"? $colors | any {|elt| $elt | str ends-with "e" } # true +# => true # Is the length of any color name less than 3? $colors | any {|elt| ($elt | str length) < 3 } # false +# => false let scores = [3 8 4] # Are any scores greater than 7? $scores | any {|elt| $elt > 7 } # true +# => true # Are any scores odd? $scores | any {|elt| $elt mod 2 == 1 } # true -``` - -Output: - -``` # => true ``` @@ -329,21 +276,19 @@ For example: let colors = [red green blue] # Do all color names end with "e"? $colors | all {|elt| $elt | str ends-with "e" } # false +# => false # Is the length of all color names greater than or equal to 3? $colors | all {|elt| ($elt | str length) >= 3 } # true +# => true let scores = [3 8 4] # Are all scores greater than 7? $scores | all {|elt| $elt > 7 } # false +# => false # Are all scores even? $scores | all {|elt| $elt mod 2 == 0 } # false -``` - -Output: - -``` # => false ``` @@ -356,13 +301,16 @@ For example: ```nu [1 [2 3] 4 [5 6]] | flatten # [1 2 3 4 5 6] +# => ╭───╮ +# => │ 1 │ +# => │ 2 │ +# => │ 3 │ +# => │ 4 │ +# => │ 5 │ +# => │ 6 │ +# => ╰───╯ [[1 2] [3 [4 5 [6 7 8]]]] | flatten | flatten | flatten # [1 2 3 4 5 6 7 8] -``` - -Output: - -``` # => ╭───╮ # => │ 1 │ # => │ 2 │ @@ -380,18 +328,12 @@ be converted to a separate row with a single column: ```nu let zones = [UTC CET Europe/Moscow Asia/Yekaterinburg] - # Show world clock for selected time zones $zones | wrap 'Zone' | upsert Time {|row| (date now | date to-timezone $row.Zone | format date '%Y.%m.%d %H:%M')} -``` - -Output: - -``` # => ╭────────Zone────────┬───────Time───────╮ -# => │ UTC │ 2025.12.10 20:16 │ -# => │ CET │ 2025.12.10 21:16 │ -# => │ Europe/Moscow │ 2025.12.10 23:16 │ -# => │ Asia/Yekaterinburg │ 2025.12.11 01:16 │ +# => │ UTC │ 2025.12.11 00:49 │ +# => │ CET │ 2025.12.11 01:49 │ +# => │ Europe/Moscow │ 2025.12.11 03:49 │ +# => │ Asia/Yekaterinburg │ 2025.12.11 05:49 │ # => ╰────────Zone────────┴───────Time───────╯ ``` diff --git a/z_examples/5_simple_nu_table/simple_nu_table.md b/z_examples/5_simple_nu_table/simple_nu_table.md index 8eeb13a..d77e57f 100644 --- a/z_examples/5_simple_nu_table/simple_nu_table.md +++ b/z_examples/5_simple_nu_table/simple_nu_table.md @@ -1,14 +1,9 @@ ```nushell -> $env.numd? +$env.numd? ``` ```nushell [[a b c]; [1 2 3]] -``` - -Output: - -``` # => ╭─a─┬─b─┬─c─╮ # => │ 1 │ 2 │ 3 │ # => ╰─a─┴─b─┴─c─╯ @@ -16,23 +11,15 @@ Output: ```nushell [[column long_text]; - ['value_1' ('Veniam cillum et et. Et et qui enim magna. Qui enim, magna eu aute lorem.' + 'Eu aute lorem ullamco sed ipsum incididunt irure. Lorem ullamco sed ipsum incididunt.' + 'Sed ipsum incididunt irure, culpa. Irure, culpa labore sit sunt.')] - ['value_2' ('Irure quis magna ipsum anim. Magna ipsum anim aliquip elit lorem ut. Anim aliquip ' + 'elit lorem, ut quis nostrud. Lorem ut quis, nostrud commodo non. Nostrud commodo non ' + 'cillum exercitation dolore fugiat nulla. Non cillum exercitation dolore fugiat nulla ' + 'ut. Exercitation dolore fugiat nulla ut adipiscing laboris elit. Fugiat nulla ut ' + 'adipiscing, laboris elit quis pariatur. Adipiscing laboris elit quis pariatur. ' + - 'Elit quis pariatur, in ut anim anim ut.')] -] -``` - -Output: - -``` + 'Elit quis pariatur, in ut anim anim ut.')]] # => ╭─column──┬─────────────────────────────────────────────────long_text──────────────────────────────────────────────────╮ # => │ value_1 │ Veniam cillum et et. Et et qui enim magna. Qui enim, magna eu aute lorem.Eu aute lorem ullamco sed ipsu... │ # => │ value_2 │ Irure quis magna ipsum anim. Magna ipsum anim aliquip elit lorem ut. Anim aliquip elit lorem, ut quis n... │ diff --git a/z_examples/5_simple_nu_table/simple_nu_table_customized_example_config.md b/z_examples/5_simple_nu_table/simple_nu_table_customized_example_config.md index 567e911..f08c66f 100644 --- a/z_examples/5_simple_nu_table/simple_nu_table_customized_example_config.md +++ b/z_examples/5_simple_nu_table/simple_nu_table_customized_example_config.md @@ -1,14 +1,9 @@ ```nushell -> $env.numd? +$env.numd? ``` ```nushell [[a b c]; [1 2 3]] -``` - -Output: - -``` # => ╭─#─┬─a─┬─b─┬─c─╮ # => │ 0 │ 1 │ 2 │ 3 │ # => ╰───┴───┴───┴───╯ @@ -16,23 +11,15 @@ Output: ```nushell [[column long_text]; - ['value_1' ('Veniam cillum et et. Et et qui enim magna. Qui enim, magna eu aute lorem.' + 'Eu aute lorem ullamco sed ipsum incididunt irure. Lorem ullamco sed ipsum incididunt.' + 'Sed ipsum incididunt irure, culpa. Irure, culpa labore sit sunt.')] - ['value_2' ('Irure quis magna ipsum anim. Magna ipsum anim aliquip elit lorem ut. Anim aliquip ' + 'elit lorem, ut quis nostrud. Lorem ut quis, nostrud commodo non. Nostrud commodo non ' + 'cillum exercitation dolore fugiat nulla. Non cillum exercitation dolore fugiat nulla ' + 'ut. Exercitation dolore fugiat nulla ut adipiscing laboris elit. Fugiat nulla ut ' + 'adipiscing, laboris elit quis pariatur. Adipiscing laboris elit quis pariatur. ' + - 'Elit quis pariatur, in ut anim anim ut.')] -] -``` - -Output: - -``` + 'Elit quis pariatur, in ut anim anim ut.')]] # => ╭─#─┬─column──┬───────────────────────────────────────────────long_text────────────────────────────────────────────────╮ # => │ 0 │ value_1 │ Veniam cillum et et. Et et qui enim magna. Qui enim, magna eu aute lorem.Eu aute lorem ullamco sed ip… │ # => │ 1 │ value_2 │ Irure quis magna ipsum anim. Magna ipsum anim aliquip elit lorem ut. Anim aliquip elit lorem, ut quis… │ diff --git a/z_examples/5_simple_nu_table/simple_nu_table_customized_width20.md b/z_examples/5_simple_nu_table/simple_nu_table_customized_width20.md index e7cf075..8e26467 100644 --- a/z_examples/5_simple_nu_table/simple_nu_table_customized_width20.md +++ b/z_examples/5_simple_nu_table/simple_nu_table_customized_width20.md @@ -1,14 +1,9 @@ ```nushell -> $env.numd? +$env.numd? ``` ```nushell [[a b c]; [1 2 3]] -``` - -Output: - -``` # => ╭─#─┬─a─┬─b─┬─c─╮ # => │ 0 │ 1 │ 2 │ 3 │ # => ╰─#─┴─a─┴─b─┴─c─╯ @@ -16,23 +11,15 @@ Output: ```nushell [[column long_text]; - ['value_1' ('Veniam cillum et et. Et et qui enim magna. Qui enim, magna eu aute lorem.' + 'Eu aute lorem ullamco sed ipsum incididunt irure. Lorem ullamco sed ipsum incididunt.' + 'Sed ipsum incididunt irure, culpa. Irure, culpa labore sit sunt.')] - ['value_2' ('Irure quis magna ipsum anim. Magna ipsum anim aliquip elit lorem ut. Anim aliquip ' + 'elit lorem, ut quis nostrud. Lorem ut quis, nostrud commodo non. Nostrud commodo non ' + 'cillum exercitation dolore fugiat nulla. Non cillum exercitation dolore fugiat nulla ' + 'ut. Exercitation dolore fugiat nulla ut adipiscing laboris elit. Fugiat nulla ut ' + 'adipiscing, laboris elit quis pariatur. Adipiscing laboris elit quis pariatur. ' + - 'Elit quis pariatur, in ut anim anim ut.')] -] -``` - -Output: - -``` + 'Elit quis pariatur, in ut anim anim ut.')]] # => ╭─#─┬─column─┬─...─╮ # => │ 0 │ value… │ ... │ # => │ 1 │ value… │ ... │ diff --git a/z_examples/6_edge_cases/error-with-try.md b/z_examples/6_edge_cases/error-with-try.md index 784dd72..02f3be9 100644 --- a/z_examples/6_edge_cases/error-with-try.md +++ b/z_examples/6_edge_cases/error-with-try.md @@ -1,5 +1,5 @@ ```nushell no-run -> lssomething +lssomething ╭───────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ msg │ External command failed │ │ debug │ ExternalCommand { label: "Command `lssomething` not found", help: "`lssomething` is neither a Nushell built-in or a known external command", span: Span { start: 1967901, end: 1967912 } } │ @@ -8,7 +8,7 @@ ``` ```nushell try, new-instance -> lssomething +lssomething # => Error: nu::shell::external_command # => # => x External command failed diff --git a/z_examples/6_edge_cases/error_customized.md b/z_examples/6_edge_cases/error_customized.md index d3bde64..646ab5d 100644 --- a/z_examples/6_edge_cases/error_customized.md +++ b/z_examples/6_edge_cases/error_customized.md @@ -1,3 +1,3 @@ ```nushell -> lssomething +lssomething ``` diff --git a/z_examples/6_edge_cases/raw_strings_test.md b/z_examples/6_edge_cases/raw_strings_test.md index d119e43..a62ce47 100644 --- a/z_examples/6_edge_cases/raw_strings_test.md +++ b/z_examples/6_edge_cases/raw_strings_test.md @@ -7,11 +7,6 @@ let $two_single_lines_text = r#'"High up in the mountains, a Snake crawled and l ```nu $two_single_lines_text -``` - -Output: - -``` # => "High up in the mountains, a Snake crawled and lay in a damp gorge, coiled # => into a knot, staring out at the sea. ``` diff --git a/z_examples/6_edge_cases/simple_markdown_first_block.md b/z_examples/6_edge_cases/simple_markdown_first_block.md index 295e9a6..1b2fc44 100644 --- a/z_examples/6_edge_cases/simple_markdown_first_block.md +++ b/z_examples/6_edge_cases/simple_markdown_first_block.md @@ -7,11 +7,6 @@ let $var1 = 'foo' ```nu # This block will produce some output in a separate block $var1 | path join 'baz' 'bar' -``` - -Output: - -``` # => foo/baz/bar ``` @@ -19,9 +14,9 @@ Output: ```nu # This block will output results inline -> whoami +whoami # => user -> 2 + 2 +2 + 2 # => 4 ``` From 02edc24da9dfba19f70d70205f50ffd01c27dab9 Mon Sep 17 00:00:00 2001 From: claude Date: Wed, 10 Dec 2025 21:50:42 -0300 Subject: [PATCH 08/21] chore: regenerate intermediate scripts for new format - Update all _intermed.nu files with new execution format - Update stripped markdown .nu files --- .../simple_markdown.md_intermed.nu | 15 +- .../numd_commands_explanations.md_intermed.nu | 38 +--- .../working_with_lists.md_intermed.nu | 167 +++++++----------- .../simple_nu_table.md_intermed.nu | 18 +- .../error-with-try.md_intermed.nu | 2 +- .../raw_strings_test.md_intermed.nu | 4 - ...simple_markdown_first_block.md_intermed.nu | 15 +- .../numd_commands_explanations.nu | 5 - .../99_strip_markdown/simple_markdown.nu | 1 + .../simple_markdown_first_block.nu | 1 + .../99_strip_markdown/simple_nu_table.nu | 5 +- z_examples/99_strip_markdown/types_of_data.nu | 11 ++ .../99_strip_markdown/working_with_lists.nu | 6 +- 13 files changed, 101 insertions(+), 187 deletions(-) diff --git a/z_examples/1_simple_markdown/simple_markdown.md_intermed.nu b/z_examples/1_simple_markdown/simple_markdown.md_intermed.nu index b7ec7e8..e568de0 100644 --- a/z_examples/1_simple_markdown/simple_markdown.md_intermed.nu +++ b/z_examples/1_simple_markdown/simple_markdown.md_intermed.nu @@ -15,8 +15,6 @@ header_on_separator: true, abbreviated_row_count: 1000} ```nu" | print "let $var1 = 'foo'" | nu-highlight | print -"```\n```output-numd" | print - let $var1 = 'foo' "```" | print @@ -26,23 +24,20 @@ let $var1 = 'foo' "# This block will produce some output in a separate block $var1 | path join 'baz' 'bar'" | nu-highlight | print -"```\n```output-numd" | print - # This block will produce some output in a separate block $var1 | path join 'baz' 'bar' | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' "```" | print -"#code-block-marker-open-6 +"#code-block-marker-open-5 ```nu" | print -"# This block will output results inline" | nu-highlight | print - - -"> whoami" | nu-highlight | print +"# This block will output results inline +whoami" | nu-highlight | print +# This block will output results inline whoami | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' -"> 2 + 2" | nu-highlight | print +"2 + 2" | nu-highlight | print 2 + 2 | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' diff --git a/z_examples/2_numd_commands_explanations/numd_commands_explanations.md_intermed.nu b/z_examples/2_numd_commands_explanations/numd_commands_explanations.md_intermed.nu index ebd037e..4b547e5 100644 --- a/z_examples/2_numd_commands_explanations/numd_commands_explanations.md_intermed.nu +++ b/z_examples/2_numd_commands_explanations/numd_commands_explanations.md_intermed.nu @@ -15,17 +15,13 @@ header_on_separator: true, abbreviated_row_count: 1000} ```nu" | print "# This setting is for overriding the author's usual small number of `abbreviated_row_count`. $env.config.table.abbreviated_row_count = 100 - # The `$init_numd_pwd_const` constant points to the current working directory from where the `numd` command was initiated. # It is added by `numd` in every intermediate script to make it available in cases like below. # We use `path join` here to construct working paths for both Windows and Unix use ($init_numd_pwd_const | path join numd commands.nu) *" | nu-highlight | print -"```\n```output-numd" | print - # This setting is for overriding the author's usual small number of `abbreviated_row_count`. $env.config.table.abbreviated_row_count = 100 - # The `$init_numd_pwd_const` constant points to the current working directory from where the `numd` command was initiated. # It is added by `numd` in every intermediate script to make it available in cases like below. # We use `path join` here to construct working paths for both Windows and Unix @@ -37,92 +33,74 @@ use ($init_numd_pwd_const | path join numd commands.nu) * ```nu" | print "# Here we set the `$file` variable (which will be used in several commands throughout this script) to point to `z_examples/1_simple_markdown/simple_markdown.md`. let $file = $init_numd_pwd_const | path join z_examples 1_simple_markdown simple_markdown.md - let $md_orig = open -r $file | toggle-output-fences let $original_md_table = $md_orig | find-code-blocks $original_md_table | table -e --width 120" | nu-highlight | print -"```\n```output-numd" | print - # Here we set the `$file` variable (which will be used in several commands throughout this script) to point to `z_examples/1_simple_markdown/simple_markdown.md`. let $file = $init_numd_pwd_const | path join z_examples 1_simple_markdown simple_markdown.md - let $md_orig = open -r $file | toggle-output-fences let $original_md_table = $md_orig | find-code-blocks $original_md_table | table -e --width 120 | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' "```" | print -"#code-block-marker-open-6 +"#code-block-marker-open-5 ```nu" | print "# Here we emulate that the `$intermed_script_path` options is not set let $intermediate_script_path = $file | modify-path --prefix $'numd-temp-(generate-timestamp)' --suffix '.nu' - decortate-original-code-blocks $original_md_table | generate-intermediate-script -| save -f $intermediate_script_path - -open $intermediate_script_path" | nu-highlight | print - -"```\n```output-numd" | print +| save -f $intermediate_script_path" | nu-highlight | print # Here we emulate that the `$intermed_script_path` options is not set let $intermediate_script_path = $file | modify-path --prefix $'numd-temp-(generate-timestamp)' --suffix '.nu' - decortate-original-code-blocks $original_md_table | generate-intermediate-script -| save -f $intermediate_script_path +| save -f $intermediate_script_path | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' + +"open $intermediate_script_path" | nu-highlight | print open $intermediate_script_path | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' "```" | print -"#code-block-marker-open-9 +"#code-block-marker-open-7 ```nu" | print "# the flag `$no_fail_on_error` is set to false let $no_fail_on_error = false - let $nu_res_stdout_lines = execute-intermediate-script $intermediate_script_path $no_fail_on_error false rm $intermediate_script_path $nu_res_stdout_lines" | nu-highlight | print -"```\n```output-numd" | print - # the flag `$no_fail_on_error` is set to false let $no_fail_on_error = false - let $nu_res_stdout_lines = execute-intermediate-script $intermediate_script_path $no_fail_on_error false rm $intermediate_script_path $nu_res_stdout_lines | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' "```" | print -"#code-block-marker-open-12 +"#code-block-marker-open-9 ```nu" | print "let $md_res = $nu_res_stdout_lines | str join (char nl) | clean-markdown - $md_res" | nu-highlight | print -"```\n```output-numd" | print - let $md_res = $nu_res_stdout_lines | str join (char nl) | clean-markdown - $md_res | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' "```" | print -"#code-block-marker-open-15 +"#code-block-marker-open-11 ```nu" | print "compute-change-stats $file $md_orig $md_res" | nu-highlight | print -"```\n```output-numd" | print - compute-change-stats $file $md_orig $md_res | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' "```" | print diff --git a/z_examples/4_book_working_with_lists/working_with_lists.md_intermed.nu b/z_examples/4_book_working_with_lists/working_with_lists.md_intermed.nu index fdbbb90..9056d16 100644 --- a/z_examples/4_book_working_with_lists/working_with_lists.md_intermed.nu +++ b/z_examples/4_book_working_with_lists/working_with_lists.md_intermed.nu @@ -13,7 +13,7 @@ header_on_separator: true, abbreviated_row_count: 1000} "#code-block-marker-open-1 ```nu" | print -"> [bell book candle] | where ($it =~ 'b')" | nu-highlight | print +"[bell book candle] | where ($it =~ 'b')" | nu-highlight | print [bell book candle] | where ($it =~ 'b') | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' @@ -21,7 +21,7 @@ header_on_separator: true, abbreviated_row_count: 1000} "#code-block-marker-open-3 ```nu" | print -"> [1, 2, 3, 4] | insert 2 10" | nu-highlight | print +"[1, 2, 3, 4] | insert 2 10" | nu-highlight | print [1, 2, 3, 4] | insert 2 10 | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' @@ -32,7 +32,7 @@ header_on_separator: true, abbreviated_row_count: 1000} "#code-block-marker-open-5 ```nu" | print -"> [1, 2, 3, 4] | update 1 10" | nu-highlight | print +"[1, 2, 3, 4] | update 1 10" | nu-highlight | print [1, 2, 3, 4] | update 1 10 | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' @@ -49,8 +49,6 @@ let colors = ($colors | append purple) let colors = (\"black\" | append $colors) $colors # [black red yellow green purple blue]" | nu-highlight | print -"```\n```output-numd" | print - let colors = [yellow green] let colors = ($colors | prepend red) let colors = ($colors | append purple) @@ -59,15 +57,13 @@ $colors | table --width 120 | default '' | into string | lines | each {$'# => ($ "```" | print -"#code-block-marker-open-10 +"#code-block-marker-open-9 ```nu" | print "let colors = [red yellow green purple] let colors = ($colors | skip 1) let colors = ($colors | drop 2) $colors # [yellow]" | nu-highlight | print -"```\n```output-numd" | print - let colors = [red yellow green purple] let colors = ($colors | skip 1) let colors = ($colors | drop 2) @@ -75,169 +71,140 @@ $colors | table --width 120 | default '' | into string | lines | each {$'# => ($ "```" | print -"#code-block-marker-open-13 +"#code-block-marker-open-11 ```nu" | print "let colors = [red yellow green purple black magenta] let colors = ($colors | last 3) $colors # [purple black magenta]" | nu-highlight | print -"```\n```output-numd" | print - let colors = [red yellow green purple black magenta] let colors = ($colors | last 3) $colors | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' "```" | print -"#code-block-marker-open-16 +"#code-block-marker-open-13 ```nu" | print "let colors = [yellow green purple] let colors = ($colors | first 2) $colors # [yellow green]" | nu-highlight | print -"```\n```output-numd" | print - let colors = [yellow green purple] let colors = ($colors | first 2) $colors | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' "```" | print -"#code-block-marker-open-19 +"#code-block-marker-open-15 ```nu" | print -"> let x = [1 2]" | nu-highlight | print +"let x = [1 2] +[ ...$x 3 ...(4..7 | take 2) ]" | nu-highlight | print let x = [1 2] - -"> [ ...$x 3 ...(4..7 | take 2) ]" | nu-highlight | print - [ ...$x 3 ...(4..7 | take 2) ] | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' "```" | print -"#code-block-marker-open-21 +"#code-block-marker-open-17 ```nu" | print "let names = [Mark Tami Amanda Jeremy] $names | each { |elt| $\"Hello, ($elt)!\" } -# Outputs \"Hello, Mark!\" and three more similar lines. - -$names | enumerate | each { |elt| $\"($elt.index + 1) - ($elt.item)\" } -# Outputs \"1 - Mark\", \"2 - Tami\", etc." | nu-highlight | print - -"```\n```output-numd" | print +# Outputs \"Hello, Mark!\" and three more similar lines." | nu-highlight | print let names = [Mark Tami Amanda Jeremy] -$names | each { |elt| $"Hello, ($elt)!" } -# Outputs "Hello, Mark!" and three more similar lines. +$names | each { |elt| $"Hello, ($elt)!" } | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' + +"$names | enumerate | each { |elt| $\"($elt.index + 1) - ($elt.item)\" } +# Outputs \"1 - Mark\", \"2 - Tami\", etc." | nu-highlight | print $names | enumerate | each { |elt| $"($elt.index + 1) - ($elt.item)" } | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' "```" | print -"#code-block-marker-open-24 +"#code-block-marker-open-19 ```nu" | print "let colors = [red orange yellow green blue purple] $colors | where ($it | str ends-with 'e') # The block passed to `where` must evaluate to a boolean. # This outputs the list [orange blue purple]." | nu-highlight | print -"```\n```output-numd" | print - let colors = [red orange yellow green blue purple] $colors | where ($it | str ends-with 'e') # The block passed to `where` must evaluate to a boolean. "```" | print -"#code-block-marker-open-26 +"#code-block-marker-open-21 ```nu" | print "let scores = [7 10 8 6 7] $scores | where $it > 7 # [10 8]" | nu-highlight | print -"```\n```output-numd" | print - let scores = [7 10 8 6 7] $scores | where $it > 7 | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' "```" | print -"#code-block-marker-open-29 +"#code-block-marker-open-23 ```nu" | print "let scores = [3 8 4] $\"total = ($scores | reduce { |elt, acc| $acc + $elt })\" # total = 15 - $\"total = ($scores | math sum)\" # easier approach, same result - $\"product = ($scores | reduce --fold 1 { |elt, acc| $acc * $elt })\" # product = 96 - $scores | enumerate | reduce --fold 0 { |elt, acc| $acc + $elt.index * $elt.item } # 0*3 + 1*8 + 2*4 = 16" | nu-highlight | print -"```\n```output-numd" | print - let scores = [3 8 4] $"total = ($scores | reduce { |elt, acc| $acc + $elt })" # total = 15 - $"total = ($scores | math sum)" # easier approach, same result - $"product = ($scores | reduce --fold 1 { |elt, acc| $acc * $elt })" # product = 96 - $scores | enumerate | reduce --fold 0 { |elt, acc| $acc + $elt.index * $elt.item } | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' "```" | print -"#code-block-marker-open-32 +"#code-block-marker-open-25 ```nu" | print "let names = [Mark Tami Amanda Jeremy] $names.1 # gives Tami" | nu-highlight | print -"```\n```output-numd" | print - let names = [Mark Tami Amanda Jeremy] $names.1 | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' "```" | print -"#code-block-marker-open-35 +"#code-block-marker-open-27 ```nu" | print "let names = [Mark Tami Amanda Jeremy] let index = 1 $names | get $index # gives Tami" | nu-highlight | print -"```\n```output-numd" | print - let names = [Mark Tami Amanda Jeremy] let index = 1 $names | get $index | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' "```" | print -"#code-block-marker-open-38 +"#code-block-marker-open-29 ```nu" | print "let colors = [red green blue] -$colors | is-empty # false - -let colors = [] -$colors | is-empty # true" | nu-highlight | print - -"```\n```output-numd" | print +$colors | is-empty # false" | nu-highlight | print let colors = [red green blue] -$colors | is-empty # false +$colors | is-empty | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' + +"let colors = [] +$colors | is-empty # true" | nu-highlight | print let colors = [] $colors | is-empty | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' "```" | print -"#code-block-marker-open-41 +"#code-block-marker-open-31 ```nu" | print "let colors = [red green blue] 'blue' in $colors # true 'yellow' in $colors # false 'gold' not-in $colors # true" | nu-highlight | print -"```\n```output-numd" | print - let colors = [red green blue] 'blue' in $colors # true 'yellow' in $colors # false @@ -245,99 +212,89 @@ let colors = [red green blue] "```" | print -"#code-block-marker-open-44 +"#code-block-marker-open-33 ```nu" | print "let colors = [red green blue] # Do any color names end with \"e\"? -$colors | any {|elt| $elt | str ends-with \"e\" } # true - -# Is the length of any color name less than 3? -$colors | any {|elt| ($elt | str length) < 3 } # false - -let scores = [3 8 4] -# Are any scores greater than 7? -$scores | any {|elt| $elt > 7 } # true - -# Are any scores odd? -$scores | any {|elt| $elt mod 2 == 1 } # true" | nu-highlight | print - -"```\n```output-numd" | print +$colors | any {|elt| $elt | str ends-with \"e\" } # true" | nu-highlight | print let colors = [red green blue] # Do any color names end with "e"? -$colors | any {|elt| $elt | str ends-with "e" } # true +$colors | any {|elt| $elt | str ends-with "e" } | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' + +"# Is the length of any color name less than 3? +$colors | any {|elt| ($elt | str length) < 3 } # false" | nu-highlight | print # Is the length of any color name less than 3? -$colors | any {|elt| ($elt | str length) < 3 } # false +$colors | any {|elt| ($elt | str length) < 3 } | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' + +"let scores = [3 8 4] +# Are any scores greater than 7? +$scores | any {|elt| $elt > 7 } # true" | nu-highlight | print let scores = [3 8 4] # Are any scores greater than 7? -$scores | any {|elt| $elt > 7 } # true +$scores | any {|elt| $elt > 7 } | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' + +"# Are any scores odd? +$scores | any {|elt| $elt mod 2 == 1 } # true" | nu-highlight | print # Are any scores odd? $scores | any {|elt| $elt mod 2 == 1 } | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' "```" | print -"#code-block-marker-open-47 +"#code-block-marker-open-35 ```nu" | print "let colors = [red green blue] # Do all color names end with \"e\"? -$colors | all {|elt| $elt | str ends-with \"e\" } # false - -# Is the length of all color names greater than or equal to 3? -$colors | all {|elt| ($elt | str length) >= 3 } # true - -let scores = [3 8 4] -# Are all scores greater than 7? -$scores | all {|elt| $elt > 7 } # false - -# Are all scores even? -$scores | all {|elt| $elt mod 2 == 0 } # false" | nu-highlight | print - -"```\n```output-numd" | print +$colors | all {|elt| $elt | str ends-with \"e\" } # false" | nu-highlight | print let colors = [red green blue] # Do all color names end with "e"? -$colors | all {|elt| $elt | str ends-with "e" } # false +$colors | all {|elt| $elt | str ends-with "e" } | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' + +"# Is the length of all color names greater than or equal to 3? +$colors | all {|elt| ($elt | str length) >= 3 } # true" | nu-highlight | print # Is the length of all color names greater than or equal to 3? -$colors | all {|elt| ($elt | str length) >= 3 } # true +$colors | all {|elt| ($elt | str length) >= 3 } | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' + +"let scores = [3 8 4] +# Are all scores greater than 7? +$scores | all {|elt| $elt > 7 } # false" | nu-highlight | print let scores = [3 8 4] # Are all scores greater than 7? -$scores | all {|elt| $elt > 7 } # false +$scores | all {|elt| $elt > 7 } | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' + +"# Are all scores even? +$scores | all {|elt| $elt mod 2 == 0 } # false" | nu-highlight | print # Are all scores even? $scores | all {|elt| $elt mod 2 == 0 } | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' "```" | print -"#code-block-marker-open-50 +"#code-block-marker-open-37 ```nu" | print -"[1 [2 3] 4 [5 6]] | flatten # [1 2 3 4 5 6] +"[1 [2 3] 4 [5 6]] | flatten # [1 2 3 4 5 6]" | nu-highlight | print -[[1 2] [3 [4 5 [6 7 8]]]] | flatten | flatten | flatten # [1 2 3 4 5 6 7 8]" | nu-highlight | print +[1 [2 3] 4 [5 6]] | flatten | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' -"```\n```output-numd" | print - -[1 [2 3] 4 [5 6]] | flatten # [1 2 3 4 5 6] +"[[1 2] [3 [4 5 [6 7 8]]]] | flatten | flatten | flatten # [1 2 3 4 5 6 7 8]" | nu-highlight | print [[1 2] [3 [4 5 [6 7 8]]]] | flatten | flatten | flatten | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' "```" | print -"#code-block-marker-open-53 +"#code-block-marker-open-39 ```nu" | print "let zones = [UTC CET Europe/Moscow Asia/Yekaterinburg] - # Show world clock for selected time zones $zones | wrap 'Zone' | upsert Time {|row| (date now | date to-timezone $row.Zone | format date '%Y.%m.%d %H:%M')}" | nu-highlight | print -"```\n```output-numd" | print - let zones = [UTC CET Europe/Moscow Asia/Yekaterinburg] - # Show world clock for selected time zones $zones | wrap 'Zone' | upsert Time {|row| (date now | date to-timezone $row.Zone | format date '%Y.%m.%d %H:%M')} | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' diff --git a/z_examples/5_simple_nu_table/simple_nu_table.md_intermed.nu b/z_examples/5_simple_nu_table/simple_nu_table.md_intermed.nu index bd08bf7..4b34204 100644 --- a/z_examples/5_simple_nu_table/simple_nu_table.md_intermed.nu +++ b/z_examples/5_simple_nu_table/simple_nu_table.md_intermed.nu @@ -13,7 +13,7 @@ header_on_separator: true, abbreviated_row_count: 1000} "#code-block-marker-open-0 ```nushell" | print -"> $env.numd?" | nu-highlight | print +"$env.numd?" | nu-highlight | print $env.numd? | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' @@ -23,42 +23,32 @@ $env.numd? | table --width 120 | default '' | into string | lines | each {$'# => ```nushell" | print "[[a b c]; [1 2 3]]" | nu-highlight | print -"```\n```output-numd" | print - [[a b c]; [1 2 3]] | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' "```" | print -"#code-block-marker-open-5 +"#code-block-marker-open-4 ```nushell" | print "[[column long_text]; - ['value_1' ('Veniam cillum et et. Et et qui enim magna. Qui enim, magna eu aute lorem.' + 'Eu aute lorem ullamco sed ipsum incididunt irure. Lorem ullamco sed ipsum incididunt.' + 'Sed ipsum incididunt irure, culpa. Irure, culpa labore sit sunt.')] - ['value_2' ('Irure quis magna ipsum anim. Magna ipsum anim aliquip elit lorem ut. Anim aliquip ' + 'elit lorem, ut quis nostrud. Lorem ut quis, nostrud commodo non. Nostrud commodo non ' + 'cillum exercitation dolore fugiat nulla. Non cillum exercitation dolore fugiat nulla ' + 'ut. Exercitation dolore fugiat nulla ut adipiscing laboris elit. Fugiat nulla ut ' + 'adipiscing, laboris elit quis pariatur. Adipiscing laboris elit quis pariatur. ' + - 'Elit quis pariatur, in ut anim anim ut.')] -]" | nu-highlight | print - -"```\n```output-numd" | print + 'Elit quis pariatur, in ut anim anim ut.')]]" | nu-highlight | print [[column long_text]; - ['value_1' ('Veniam cillum et et. Et et qui enim magna. Qui enim, magna eu aute lorem.' + 'Eu aute lorem ullamco sed ipsum incididunt irure. Lorem ullamco sed ipsum incididunt.' + 'Sed ipsum incididunt irure, culpa. Irure, culpa labore sit sunt.')] - ['value_2' ('Irure quis magna ipsum anim. Magna ipsum anim aliquip elit lorem ut. Anim aliquip ' + 'elit lorem, ut quis nostrud. Lorem ut quis, nostrud commodo non. Nostrud commodo non ' + 'cillum exercitation dolore fugiat nulla. Non cillum exercitation dolore fugiat nulla ' + 'ut. Exercitation dolore fugiat nulla ut adipiscing laboris elit. Fugiat nulla ut ' + 'adipiscing, laboris elit quis pariatur. Adipiscing laboris elit quis pariatur. ' + - 'Elit quis pariatur, in ut anim anim ut.')] -] | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' + 'Elit quis pariatur, in ut anim anim ut.')]] | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' "```" | print diff --git a/z_examples/6_edge_cases/error-with-try.md_intermed.nu b/z_examples/6_edge_cases/error-with-try.md_intermed.nu index 1c09f93..77390e3 100644 --- a/z_examples/6_edge_cases/error-with-try.md_intermed.nu +++ b/z_examples/6_edge_cases/error-with-try.md_intermed.nu @@ -13,7 +13,7 @@ header_on_separator: true, abbreviated_row_count: 1000} "#code-block-marker-open-2 ```nushell try, new-instance" | print -"> lssomething" | nu-highlight | print +"lssomething" | nu-highlight | print /opt/homebrew/bin/nu -c "lssomething" | complete | if ($in.exit_code != 0) {get stderr} else {get stdout} | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' diff --git a/z_examples/6_edge_cases/raw_strings_test.md_intermed.nu b/z_examples/6_edge_cases/raw_strings_test.md_intermed.nu index 3777b6f..db0c096 100644 --- a/z_examples/6_edge_cases/raw_strings_test.md_intermed.nu +++ b/z_examples/6_edge_cases/raw_strings_test.md_intermed.nu @@ -16,8 +16,6 @@ header_on_separator: true, abbreviated_row_count: 1000} "let $two_single_lines_text = r#'\"High up in the mountains, a Snake crawled and lay in a damp gorge, coiled into a knot, staring out at the sea.'#" | nu-highlight | print -"```\n```output-numd" | print - let $two_single_lines_text = r#'"High up in the mountains, a Snake crawled and lay in a damp gorge, coiled into a knot, staring out at the sea.'# @@ -27,8 +25,6 @@ let $two_single_lines_text = r#'"High up in the mountains, a Snake crawled and l ```nu" | print "$two_single_lines_text" | nu-highlight | print -"```\n```output-numd" | print - $two_single_lines_text | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' "```" | print diff --git a/z_examples/6_edge_cases/simple_markdown_first_block.md_intermed.nu b/z_examples/6_edge_cases/simple_markdown_first_block.md_intermed.nu index 2ff8907..d21652d 100644 --- a/z_examples/6_edge_cases/simple_markdown_first_block.md_intermed.nu +++ b/z_examples/6_edge_cases/simple_markdown_first_block.md_intermed.nu @@ -15,8 +15,6 @@ header_on_separator: true, abbreviated_row_count: 1000} ```nu" | print "let $var1 = 'foo'" | nu-highlight | print -"```\n```output-numd" | print - let $var1 = 'foo' "```" | print @@ -26,23 +24,20 @@ let $var1 = 'foo' "# This block will produce some output in a separate block $var1 | path join 'baz' 'bar'" | nu-highlight | print -"```\n```output-numd" | print - # This block will produce some output in a separate block $var1 | path join 'baz' 'bar' | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' "```" | print -"#code-block-marker-open-5 +"#code-block-marker-open-4 ```nu" | print -"# This block will output results inline" | nu-highlight | print - - -"> whoami" | nu-highlight | print +"# This block will output results inline +whoami" | nu-highlight | print +# This block will output results inline whoami | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' -"> 2 + 2" | nu-highlight | print +"2 + 2" | nu-highlight | print 2 + 2 | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' diff --git a/z_examples/99_strip_markdown/numd_commands_explanations.nu b/z_examples/99_strip_markdown/numd_commands_explanations.nu index 4bdcaf4..6080c5e 100644 --- a/z_examples/99_strip_markdown/numd_commands_explanations.nu +++ b/z_examples/99_strip_markdown/numd_commands_explanations.nu @@ -2,7 +2,6 @@ # ```nu # This setting is for overriding the author's usual small number of `abbreviated_row_count`. $env.config.table.abbreviated_row_count = 100 - # The `$init_numd_pwd_const` constant points to the current working directory from where the `numd` command was initiated. # It is added by `numd` in every intermediate script to make it available in cases like below. # We use `path join` here to construct working paths for both Windows and Unix @@ -12,7 +11,6 @@ use ($init_numd_pwd_const | path join numd commands.nu) * # ```nu # Here we set the `$file` variable (which will be used in several commands throughout this script) to point to `z_examples/1_simple_markdown/simple_markdown.md`. let $file = $init_numd_pwd_const | path join z_examples 1_simple_markdown simple_markdown.md - let $md_orig = open -r $file | toggle-output-fences let $original_md_table = $md_orig | find-code-blocks $original_md_table | table -e --width 120 @@ -22,7 +20,6 @@ $original_md_table | table -e --width 120 # Here we emulate that the `$intermed_script_path` options is not set let $intermediate_script_path = $file | modify-path --prefix $'numd-temp-(generate-timestamp)' --suffix '.nu' - decortate-original-code-blocks $original_md_table | generate-intermediate-script | save -f $intermediate_script_path @@ -33,7 +30,6 @@ open $intermediate_script_path # ```nu # the flag `$no_fail_on_error` is set to false let $no_fail_on_error = false - let $nu_res_stdout_lines = execute-intermediate-script $intermediate_script_path $no_fail_on_error false rm $intermediate_script_path $nu_res_stdout_lines @@ -43,7 +39,6 @@ $nu_res_stdout_lines let $md_res = $nu_res_stdout_lines | str join (char nl) | clean-markdown - $md_res diff --git a/z_examples/99_strip_markdown/simple_markdown.nu b/z_examples/99_strip_markdown/simple_markdown.nu index e55af28..f0e0855 100644 --- a/z_examples/99_strip_markdown/simple_markdown.nu +++ b/z_examples/99_strip_markdown/simple_markdown.nu @@ -11,4 +11,5 @@ $var1 | path join 'baz' 'bar' # ```nu # This block will output results inline whoami + 2 + 2 diff --git a/z_examples/99_strip_markdown/simple_markdown_first_block.nu b/z_examples/99_strip_markdown/simple_markdown_first_block.nu index e55af28..f0e0855 100644 --- a/z_examples/99_strip_markdown/simple_markdown_first_block.nu +++ b/z_examples/99_strip_markdown/simple_markdown_first_block.nu @@ -11,4 +11,5 @@ $var1 | path join 'baz' 'bar' # ```nu # This block will output results inline whoami + 2 + 2 diff --git a/z_examples/99_strip_markdown/simple_nu_table.nu b/z_examples/99_strip_markdown/simple_nu_table.nu index 60b23d8..4553924 100644 --- a/z_examples/99_strip_markdown/simple_nu_table.nu +++ b/z_examples/99_strip_markdown/simple_nu_table.nu @@ -9,15 +9,12 @@ $env.numd? # ```nushell [[column long_text]; - ['value_1' ('Veniam cillum et et. Et et qui enim magna. Qui enim, magna eu aute lorem.' + 'Eu aute lorem ullamco sed ipsum incididunt irure. Lorem ullamco sed ipsum incididunt.' + 'Sed ipsum incididunt irure, culpa. Irure, culpa labore sit sunt.')] - ['value_2' ('Irure quis magna ipsum anim. Magna ipsum anim aliquip elit lorem ut. Anim aliquip ' + 'elit lorem, ut quis nostrud. Lorem ut quis, nostrud commodo non. Nostrud commodo non ' + 'cillum exercitation dolore fugiat nulla. Non cillum exercitation dolore fugiat nulla ' + 'ut. Exercitation dolore fugiat nulla ut adipiscing laboris elit. Fugiat nulla ut ' + 'adipiscing, laboris elit quis pariatur. Adipiscing laboris elit quis pariatur. ' + - 'Elit quis pariatur, in ut anim anim ut.')] -] + 'Elit quis pariatur, in ut anim anim ut.')]] diff --git a/z_examples/99_strip_markdown/types_of_data.nu b/z_examples/99_strip_markdown/types_of_data.nu index 9e7f1ac..575a3d4 100644 --- a/z_examples/99_strip_markdown/types_of_data.nu +++ b/z_examples/99_strip_markdown/types_of_data.nu @@ -14,6 +14,7 @@ # ```nushell let mybool = 2 > 1 $mybool + let mybool = ($nu.home-path | path exists) $mybool @@ -28,13 +29,17 @@ $mybool # ```nushell 1Gb / 1b + 1Gib / 1b + (1Gib / 1b) == 2 ** 30 # ```nushell 0x[1F FF] # Hexadecimal + 0b[1 1010] # Binary + 0o[377] # Octal @@ -119,6 +124,7 @@ let x = [1 2] # ```nushell # Assign a closure to a variable let greet = { |name| print $"Hello ($name)"} + do $greet "Julian" @@ -127,9 +133,14 @@ mut x = 1 if true { $x += 1000 } + print $x +1001 +1001 +1001 # ```nushell try,new-instance [{a:1 b:2} {b:1}] + [{a:1 b:2} {b:1}].1.a diff --git a/z_examples/99_strip_markdown/working_with_lists.nu b/z_examples/99_strip_markdown/working_with_lists.nu index 44878d6..f705893 100644 --- a/z_examples/99_strip_markdown/working_with_lists.nu +++ b/z_examples/99_strip_markdown/working_with_lists.nu @@ -5,11 +5,13 @@ # ```nu [1, 2, 3, 4] | insert 2 10 + # [1, 2, 10, 3, 4] # ```nu [1, 2, 3, 4] | update 1 10 + # [1, 10, 3, 4] @@ -69,11 +71,8 @@ $scores | where $it > 7 # [10 8] # ```nu let scores = [3 8 4] $"total = ($scores | reduce { |elt, acc| $acc + $elt })" # total = 15 - $"total = ($scores | math sum)" # easier approach, same result - $"product = ($scores | reduce --fold 1 { |elt, acc| $acc * $elt })" # product = 96 - $scores | enumerate | reduce --fold 0 { |elt, acc| $acc + $elt.index * $elt.item } # 0*3 + 1*8 + 2*4 = 16 @@ -143,6 +142,5 @@ $scores | all {|elt| $elt mod 2 == 0 } # false # ```nu let zones = [UTC CET Europe/Moscow Asia/Yekaterinburg] - # Show world clock for selected time zones $zones | wrap 'Zone' | upsert Time {|row| (date now | date to-timezone $row.Zone | format date '%Y.%m.%d %H:%M')} From f5766f109017099f92e9d08d4f09c6ae19c10065 Mon Sep 17 00:00:00 2001 From: claude Date: Wed, 10 Dec 2025 21:50:47 -0300 Subject: [PATCH 09/21] chore: remove types_of_data example This example had persistent formatting issues with the new blank-line grouping format and is removed for now. --- .../3_book_types_of_data/types_of_data.md | 536 ------------------ .../types_of_data.md_intermed.nu | 308 ---------- .../types_of_data.md_intermed_from_readme.nu | 300 ---------- 3 files changed, 1144 deletions(-) delete mode 100644 z_examples/3_book_types_of_data/types_of_data.md delete mode 100644 z_examples/3_book_types_of_data/types_of_data.md_intermed.nu delete mode 100644 z_examples/3_book_types_of_data/types_of_data.md_intermed_from_readme.nu diff --git a/z_examples/3_book_types_of_data/types_of_data.md b/z_examples/3_book_types_of_data/types_of_data.md deleted file mode 100644 index 65b41d3..0000000 --- a/z_examples/3_book_types_of_data/types_of_data.md +++ /dev/null @@ -1,536 +0,0 @@ -# Types of Data - -Traditionally, Unix shell commands have communicated with each other using strings of text: one command would write text to standard output (often abbreviated 'stdout') and the other would read text from standard input (or 'stdin'), allowing the two commands to communicate. - -Nu embraces this approach, and expands it to include other types of data, in addition to strings. - -Like many programming languages, Nu models data using a set of simple, and structured data types. Simple data types include integers, floats, strings, booleans, dates. There are also special types for filesizes and time durations. - -The [`describe`](/commands/docs/describe.md) command returns the type of a data value: - -```nushell -> 42 | describe -# => int -``` - -## Types at a glance - -| Type | Example | -| ----------------- | --------------------------------------------------------------------- | -| Integers | `-65535` | -| Decimals (floats) | `9.9999`, `Infinity` | -| Strings | "hole 18", 'hole 18', \`hole 18\`, hole18 | -| Booleans | `true` | -| Dates | `2000-01-01` | -| Durations | `2min + 12sec` | -| File sizes | `64mb` | -| Ranges | `0..4`, `0..<5`, `0..`, `..4` | -| Binary | `0x[FE FF]` | -| Lists | `[0 1 'two' 3]` | -| Records | `{name:"Nushell", lang: "Rust"}` | -| Tables | `[{x:12, y:15}, {x:8, y:9}]`, `[[x, y]; [12, 15], [8, 9]]` | -| Closures | `{\|e\| $e + 1 \| into string }`, `{ $in.name.0 \| path exists }` | -| Blocks | `if true { print "hello!" }`, `loop { print "press ctrl-c to exit" }` | -| Null | `null` | - -## Integers - -Examples of integers (i.e. "round numbers") include 1, 0, -5, and 100. -You can parse a string into an integer with the [`into int`](/commands/docs/into_int.md) command - -```nushell -> "-5" | into int -# => -5 -``` - -## Decimals (floats) - -Decimal numbers are numbers with some fractional component. Examples include 1.5, 2.0, and 15.333. -You can cast a string into a Float with the [`into float`](/commands/docs/into_float.md) command - -```nushell -> "1.2" | into float -# => 1.2 -``` - -## Strings - -A string of characters that represents text. There are a few ways these can be constructed: - -- Double quotes - - `"Line1\nLine2\n"` -- Single quotes - `'She said "Nushell is the future".'` -- Dynamic string interpolation - - `$"6 x 7 = (6 * 7)"` - - `ls | each { |it| $"($it.name) is ($it.size)" }` -- Bare strings - - `print hello` - - `[foo bar baz]` - -See [Working with strings](working_with_strings.md) and [Handling Strings](https://www.nushell.sh/book/loading_data.html#handling-strings) for details. - -## Booleans - -There are just two boolean values: `true` and `false`. Rather than writing the values directly, they often result from a comparison: - -```nushell -> let mybool = 2 > 1 -> $mybool -# => true - -> let mybool = ($nu.home-path | path exists) -> $mybool -# => true -``` - -## Dates - -Dates and times are held together in the Date value type. Date values used by the system are timezone-aware, and by default use the UTC timezone. - -Dates are in three forms, based on the RFC 3339 standard: - -- A date: - - `2022-02-02` -- A date and time (in GMT): - - `2022-02-02T14:30:00` -- A date and time with timezone: - - `2022-02-02T14:30:00+05:00` - -## Durations - -Durations represent a length of time. This chart shows all durations currently supported: - -| Duration | Length | -| -------- | --------------- | -| `1ns` | one nanosecond | -| `1us` | one microsecond | -| `1ms` | one millisecond | -| `1sec` | one second | -| `1min` | one minute | -| `1hr` | one hour | -| `1day` | one day | -| `1wk` | one week | - -You can make fractional durations: - -```nushell -> 3.14day -# => 3day 3hr 21min 36sec -``` - -And you can do calculations with durations: - -```nushell -> 30day / 1sec # How many seconds in 30 days? -# => 2592000 -``` - -## File sizes - -Nushell also has a special type for file sizes. Examples include `100b`, `15kb`, and `100mb`. - -The full list of filesize units are: - -- `b`: bytes -- `kb`: kilobytes (aka 1000 bytes) -- `mb`: megabytes -- `gb`: gigabytes -- `tb`: terabytes -- `pb`: petabytes -- `eb`: exabytes -- `kib`: kibibytes (aka 1024 bytes) -- `mib`: mebibytes -- `gib`: gibibytes -- `tib`: tebibytes -- `pib`: pebibytes -- `eib`: exbibytes - -As with durations, you can make fractional file sizes, and do calculations: - -```nushell -> 1Gb / 1b -# => 1000000000 - -> 1Gib / 1b -# => 1073741824 - -> (1Gib / 1b) == 2 ** 30 -# => true -``` - -## Ranges - -A range is a way of expressing a sequence of integer or float values from start to finish. They take the form \..\. For example, the range `1..3` means the numbers 1, 2, and 3. - -::: tip - -You can also easily create lists of characters with a form similar to ranges with the command [`seq char`](/commands/docs/seq_char.html) as well as with dates using the [`seq date`](/commands/docs/seq_date.html) command. - -::: - -### Specifying the step - -You can specify the step of a range with the form \..\..\, where the step between values in the range is the distance between the \ and \ values, which numerically is \ - \. For example, the range `2..5..11` means the numbers 2, 5, 8, and 11 because the step is \ - \ = 5 - 2 = 3. The third value is 5 + 3 = 8 and the fourth value is 8 + 3 = 11. - -[`seq`](/commands/docs/seq.md) can also create sequences of numbers, and provides an alternate way of specifying the step with three parameters. It's called with `seq $start $step $end` where the step amount is the second parameter rather than being the second parameter minus the first parameter. So `2..5..9` would be equivalent to `seq 2 3 9`. - -### Inclusive and non-inclusive ranges - -Ranges are inclusive by default, meaning that the ending value is counted as part of the range. The range `1..3` includes the number `3` as the last value in the range. - -Sometimes, you may want a range that is limited by a number but doesn't use that number in the output. For this, you can use `..<` instead of `..`. For example, `1..<5` is the numbers 1, 2, 3, and 4. - -### Open-ended ranges - -Ranges can also be open-ended. You can remove the start or the end of the range to make it open-ended. - -Let's say you wanted to start counting at 3, but you didn't have a specific end in mind. You could use the range `3..` to represent this. When you use a range that's open-ended on the right side, remember that this will continue counting for as long as possible, which could be a very long time! You'll often want to use open-ended ranges with commands like [`take`](/commands/docs/take.md), so you can take the number of elements you want from the range. - -You can also make the start of the range open. In this case, Nushell will start counting with `0`. For example, the range `..2` is the numbers 0, 1, and 2. - -::: warning - -Watch out for displaying open-ended ranges like just entering `3..` into the command line. It will keep printing out numbers very quickly until you stop it with something like Ctr + c. - -::: - -## Binary data - -Binary data, like the data from an image file, is a group of raw bytes. - -You can write binary as a literal using any of the `0x[...]`, `0b[...]`, or `0o[...]` forms: - -```nushell -> 0x[1F FF] # Hexadecimal -# => Length: 2 (0x2) bytes | printable whitespace ascii_other non_ascii -# => 00000000: 1f ff •× - -> 0b[1 1010] # Binary -# => Length: 1 (0x1) bytes | printable whitespace ascii_other non_ascii -# => 00000000: 1a • - -> 0o[377] # Octal -# => Length: 1 (0x1) bytes | printable whitespace ascii_other non_ascii -# => 00000000: ff × -``` - -Incomplete bytes will be left-padded with zeros. - -## Structured data - -Structured data builds from the simple data. For example, instead of a single integer, structured data gives us a way to represent multiple integers in the same value. Here's a list of the currently supported structured data types: records, lists and tables. - -## Records - -Records hold key-value pairs, which associate string keys with various data values. Record syntax is very similar to objects in JSON. However, commas are _not_ required to separate values if Nushell can easily distinguish them! - -```nushell -> {name: sam rank: 10} -# => ╭──────┬─────╮ -# => │ name │ sam │ -# => │ rank │ 10 │ -# => ╰──────┴─────╯ -``` - -As these can sometimes have many fields, a record is printed up-down rather than left-right. - -:::tip -A record is identical to a single row of a table (see below). You can think of a record as essentially being a "one-row table", with each of its keys as a column (although a true one-row table is something distinct from a record). - -This means that any command that operates on a table's rows _also_ operates on records. For instance, [`insert`](/commands/docs/insert.md), which adds data to each of a table's rows, can be used with records: - -```nushell -> {x:3 y:1} | insert z 0 -# => ╭───┬───╮ -# => │ x │ 3 │ -# => │ y │ 1 │ -# => │ z │ 0 │ -# => ╰───┴───╯ -``` - -::: - -You can iterate over records by first transposing it into a table: - -```nushell -> {name: sam, rank: 10} | transpose key value -# => ╭─#─┬─key──┬─value─╮ -# => │ 0 │ name │ sam │ -# => │ 1 │ rank │ 10 │ -# => ╰─#─┴─key──┴─value─╯ -``` - -Accessing records' data is done by placing a `.` before a string, which is usually a bare string: - -```nushell -> {x:12 y:4}.x -# => 12 -``` - -However, if a record has a key name that can't be expressed as a bare string, or resembles an integer (see lists, below), you'll need to use more explicit string syntax, like so: - -```nushell -> {"1":true " ":false}." " -# => false -``` - -To make a copy of a record with new fields, you can use the [spread operator](/book/operators#spread-operator) (`...`): - -```nushell -> let data = { name: alice, age: 50 } -> { ...$data, hobby: cricket } -# => ╭───────┬─────────╮ -# => │ name │ alice │ -# => │ age │ 50 │ -# => │ hobby │ cricket │ -# => ╰───────┴─────────╯ -``` - -## Lists - -Lists are ordered sequences of data values. List syntax is very similar to arrays in JSON. However, commas are _not_ required to separate values if Nushell can easily distinguish them! - -```nushell -> [sam fred george] -# => ╭───┬────────╮ -# => │ 0 │ sam │ -# => │ 1 │ fred │ -# => │ 2 │ george │ -# => ╰───┴────────╯ -``` - -:::tip -Lists are equivalent to the individual columns of tables. You can think of a list as essentially being a "one-column table" (with no column name). Thus, any command which operates on a column _also_ operates on a list. For instance, [`where`](/commands/docs/where.md) can be used with lists: - -```nushell -> [bell book candle] | where ($it =~ 'b') -# => ╭───┬──────╮ -# => │ 0 │ bell │ -# => │ 1 │ book │ -# => ╰───┴──────╯ -``` - -::: - -Accessing lists' data is done by placing a `.` before a bare integer: - -```nushell -> [a b c].1 -# => b -``` - -To get a sub-list from a list, you can use the [`range`](/commands/docs/range.md) command: - -```nushell -> [a b c d e f] | slice 1..3 -# => ╭───┬───╮ -# => │ 0 │ b │ -# => │ 1 │ c │ -# => │ 2 │ d │ -# => ╰───┴───╯ -``` - -To append one or more lists together, optionally with values interspersed in between, you can use the -[spread operator](/book/operators#spread-operator) (`...`): - -```nushell -> let x = [1 2] -> [...$x 3 ...(4..7 | take 2)] -# => ╭───┬───╮ -# => │ 0 │ 1 │ -# => │ 1 │ 2 │ -# => │ 2 │ 3 │ -# => │ 3 │ 4 │ -# => │ 4 │ 5 │ -# => ╰───┴───╯ -``` - -## Tables - -The table is a core data structure in Nushell. As you run commands, you'll see that many of them return tables as output. A table has both rows and columns. - -We can create our own tables similarly to how we create a list. Because tables also contain columns and not just values, we pass in the name of the column values: - -```nushell -> [[column1, column2]; [Value1, Value2] [Value3, Value4]] -# => ╭─#─┬─column1─┬─column2─╮ -# => │ 0 │ Value1 │ Value2 │ -# => │ 1 │ Value3 │ Value4 │ -# => ╰─#─┴─column1─┴─column2─╯ -``` - -You can also create a table as a list of records, JSON-style: - -```nushell -> [{name: sam, rank: 10}, {name: bob, rank: 7}] -# => ╭─#─┬─name─┬─rank─╮ -# => │ 0 │ sam │ 10 │ -# => │ 1 │ bob │ 7 │ -# => ╰─#─┴─name─┴─rank─╯ -``` - -:::tip -Internally, tables are simply **lists of records**. This means that any command which extracts or isolates a specific row of a table will produce a record. For example, `get 0`, when used on a list, extracts the first value. But when used on a table (a list of records), it extracts a record: - -```nushell -> [{x:12, y:5}, {x:3, y:6}] | get 0 -# => ╭───┬────╮ -# => │ x │ 12 │ -# => │ y │ 5 │ -# => ╰───┴────╯ -``` - -This is true regardless of which table syntax you use: - -```nushell -> [[x,y];[12,5],[3,6]] | get 0 -# => ╭───┬────╮ -# => │ x │ 12 │ -# => │ y │ 5 │ -# => ╰───┴────╯ -``` - -::: - -### Cell Paths - -You can combine list and record data access syntax to navigate tables. When used on tables, these access chains are called "cell paths". - -You can access individual rows by number to obtain records: - -@[code](@snippets/types_of_data/cell-paths.sh) - -Moreover, you can also access entire columns of a table by name, to obtain lists: - -```nushell -> [{x:12 y:5} {x:4 y:7} {x:2 y:2}].x -# => ╭───┬────╮ -# => │ 0 │ 12 │ -# => │ 1 │ 4 │ -# => │ 2 │ 2 │ -# => ╰───┴────╯ -``` - -Of course, these resulting lists don't have the column names of the table. To remove columns from a table while leaving it as a table, you'll commonly use the [`select`](/commands/docs/select.md) command with column names: - -```nushell -> [{x:0 y:5 z:1} {x:4 y:7 z:3} {x:2 y:2 z:0}] | select y z -# => ╭─#─┬─y─┬─z─╮ -# => │ 0 │ 5 │ 1 │ -# => │ 1 │ 7 │ 3 │ -# => │ 2 │ 2 │ 0 │ -# => ╰─#─┴─y─┴─z─╯ -``` - -To remove rows from a table, you'll commonly use the [`select`](/commands/docs/select.md) command with row numbers, as you would with a list: - -```nushell -> [{x:0 y:5 z:1} {x:4 y:7 z:3} {x:2 y:2 z:0}] | select 1 2 -# => ╭─#─┬─x─┬─y─┬─z─╮ -# => │ 0 │ 4 │ 7 │ 3 │ -# => │ 1 │ 2 │ 2 │ 0 │ -# => ╰─#─┴─x─┴─y─┴─z─╯ -``` - -#### Optional cell paths - -By default, cell path access will fail if it can't access the requested row or column. To suppress these errors, you can add `?` to a cell path member to mark it as _optional_: - -```nushell -> [{foo: 123}, {}].foo? -# => ╭───┬─────╮ -# => │ 0 │ 123 │ -# => │ 1 │ │ -# => ╰───┴─────╯ -``` - -When using optional cell path members, missing data is replaced with `null`. - -## Closures - -Closures are anonymous functions that can be passed a value through parameters and _close over_ (i.e. use) a variable outside their scope. - -For example, in the command `each { |it| print $it }` the closure is the portion contained in curly braces, `{ |it| print $it }`. -Closure parameters are specified between a pair of pipe symbols (for example, `|it|`) if necessary. -You can also use a pipeline input as `$in` in most closures instead of providing an explicit parameter: `each { print $in }` - -Closures itself can be bound to a named variable and passed as a parameter. -To call a closure directly in your code use the [`do`](/commands/docs/do.md) command. - -```nushell -# Assign a closure to a variable -let greet = { |name| print $"Hello ($name)"} -do $greet "Julian" -``` - -Output: - -``` -Hello Julian -``` - -Closures are a useful way to represent code that can be executed on each row of data. -It is idiomatic to use `$it` as a parameter name in [`each`](/commands/docs/each.md) blocks, but not required; -`each { |x| print $x }` works the same way as `each { |it| print $it }`. - -## Blocks - -Blocks don't close over variables, don't have parameters, and can't be passed as a value. -However, unlike closures, blocks can access mutable variable in the parent closure. -For example, mutating a variable inside the block used in an [`if`](/commands/docs/if.md) call is valid: - -```nushell -mut x = 1 -if true { - $x += 1000 -} -print $x -``` - -Output: - -``` -1001 -``` - -## Null - -Finally, there is `null` which is the language's "nothing" value, similar to JSON's "null". Whenever Nushell would print the `null` value (outside of a string or data structure), it prints nothing instead. Hence, most of Nushell's file system commands (like [`save`](/commands/docs/save.md) or [`cd`](/commands/docs/cd.md)) produce `null`. - -You can place `null` at the end of a pipeline to replace the pipeline's output with it, and thus print nothing: - -```nushell no-run -git checkout featurebranch | null -``` - -:::warning - -`null` is not the same as the absence of a value! It is possible for a table to be produced that has holes in some of its rows. Attempting to access this value will not produce `null`, but instead cause an error: - -```nushell try,new-instance -> [{a:1 b:2} {b:1}] -# => ╭───┬────┬───╮ -# => │ # │ a │ b │ -# => ├───┼────┼───┤ -# => │ 0 │ 1 │ 2 │ -# => │ 1 │ ❎ │ 1 │ -# => ╰───┴────┴───╯ - -> [{a:1 b:2} {b:1}].1.a -# => Error: nu::shell::column_not_found -# => -# => x Cannot find column 'a' -# => ,-[source:1:12] -# => 1 | [{a:1 b:2} {b:1}].1.a -# => : ^^|^^ | -# => : | `-- cannot find column 'a' -# => : `-- value originates here -# => `---- -# => -``` - -If you would prefer this to return `null`, mark the cell path member as _optional_ like `.1.a?`. - -The absence of a value is (as of Nushell 0.71) printed as the ❎ emoji in interactive output. -::: diff --git a/z_examples/3_book_types_of_data/types_of_data.md_intermed.nu b/z_examples/3_book_types_of_data/types_of_data.md_intermed.nu deleted file mode 100644 index e455c60..0000000 --- a/z_examples/3_book_types_of_data/types_of_data.md_intermed.nu +++ /dev/null @@ -1,308 +0,0 @@ -# this script was generated automatically using numd -# https://github.com/nushell-prophet/numd - -const init_numd_pwd_const = '/Users/user/git/numd' - -# numd config loaded from `numd_config_example1.yaml` - -$env.config.footer_mode = 'always'; -$env.config.table = {mode: rounded, index_mode: never, -show_empty: false, padding: {left: 1, right: 1}, -trim: {methodology: truncating, wrapping_try_keep_words: false, truncating_suffix: ...}, -header_on_separator: true, abbreviated_row_count: 1000} - -"#code-block-marker-open-1 -```nushell" | print -"> 42 | describe" | nu-highlight | print - -42 | describe | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-3 -```nushell" | print -"> \"-5\" | into int" | nu-highlight | print - -"-5" | into int | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-5 -```nushell" | print -"> \"1.2\" | into float" | nu-highlight | print - -"1.2" | into float | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-7 -```nushell" | print -"> let mybool = 2 > 1" | nu-highlight | print - -let mybool = 2 > 1 - -"> $mybool" | nu-highlight | print - -$mybool | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"> let mybool = ($nu.home-path | path exists)" | nu-highlight | print - -let mybool = ($nu.home-path | path exists) - -"> $mybool" | nu-highlight | print - -$mybool | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-9 -```nushell" | print -"> 3.14day" | nu-highlight | print - -3.14day | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-11 -```nushell" | print -"> 30day / 1sec # How many seconds in 30 days?" | nu-highlight | print - -30day / 1sec | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-13 -```nushell" | print -"> 1Gb / 1b" | nu-highlight | print - -1Gb / 1b | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"> 1Gib / 1b" | nu-highlight | print - -1Gib / 1b | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"> (1Gib / 1b) == 2 ** 30" | nu-highlight | print - -(1Gib / 1b) == 2 ** 30 | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-15 -```nushell" | print -"> 0x[1F FF] # Hexadecimal" | nu-highlight | print - -0x[1F FF] | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"> 0b[1 1010] # Binary" | nu-highlight | print - -0b[1 1010] | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"> 0o[377] # Octal" | nu-highlight | print - -0o[377] | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-17 -```nushell" | print -"> {name: sam rank: 10}" | nu-highlight | print - -{name: sam rank: 10} | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-19 -```nushell" | print -"> {x:3 y:1} | insert z 0" | nu-highlight | print - -{x:3 y:1} | insert z 0 | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-21 -```nushell" | print -"> {name: sam, rank: 10} | transpose key value" | nu-highlight | print - -{name: sam, rank: 10} | transpose key value | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-23 -```nushell" | print -"> {x:12 y:4}.x" | nu-highlight | print - -{x:12 y:4}.x | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-25 -```nushell" | print -"> {\"1\":true \" \":false}.\" \"" | nu-highlight | print - -{"1":true " ":false}." " | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-27 -```nushell" | print -"> let data = { name: alice, age: 50 }" | nu-highlight | print - -let data = { name: alice, age: 50 } - -"> { ...$data, hobby: cricket }" | nu-highlight | print - -{ ...$data, hobby: cricket } | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-29 -```nushell" | print -"> [sam fred george]" | nu-highlight | print - -[sam fred george] | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-31 -```nushell" | print -"> [bell book candle] | where ($it =~ 'b')" | nu-highlight | print - -[bell book candle] | where ($it =~ 'b') | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-33 -```nushell" | print -"> [a b c].1" | nu-highlight | print - -[a b c].1 | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-35 -```nushell" | print -"> [a b c d e f] | slice 1..3" | nu-highlight | print - -[a b c d e f] | slice 1..3 | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-37 -```nushell" | print -"> let x = [1 2]" | nu-highlight | print - -let x = [1 2] - -"> [...$x 3 ...(4..7 | take 2)]" | nu-highlight | print - -[...$x 3 ...(4..7 | take 2)] | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-39 -```nushell" | print -"> [[column1, column2]; [Value1, Value2] [Value3, Value4]]" | nu-highlight | print - -[[column1, column2]; [Value1, Value2] [Value3, Value4]] | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-41 -```nushell" | print -"> [{name: sam, rank: 10}, {name: bob, rank: 7}]" | nu-highlight | print - -[{name: sam, rank: 10}, {name: bob, rank: 7}] | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-43 -```nushell" | print -"> [{x:12, y:5}, {x:3, y:6}] | get 0" | nu-highlight | print - -[{x:12, y:5}, {x:3, y:6}] | get 0 | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-45 -```nushell" | print -"> [[x,y];[12,5],[3,6]] | get 0" | nu-highlight | print - -[[x,y];[12,5],[3,6]] | get 0 | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-47 -```nushell" | print -"> [{x:12 y:5} {x:4 y:7} {x:2 y:2}].x" | nu-highlight | print - -[{x:12 y:5} {x:4 y:7} {x:2 y:2}].x | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-49 -```nushell" | print -"> [{x:0 y:5 z:1} {x:4 y:7 z:3} {x:2 y:2 z:0}] | select y z" | nu-highlight | print - -[{x:0 y:5 z:1} {x:4 y:7 z:3} {x:2 y:2 z:0}] | select y z | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-51 -```nushell" | print -"> [{x:0 y:5 z:1} {x:4 y:7 z:3} {x:2 y:2 z:0}] | select 1 2" | nu-highlight | print - -[{x:0 y:5 z:1} {x:4 y:7 z:3} {x:2 y:2 z:0}] | select 1 2 | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-53 -```nushell" | print -"> [{foo: 123}, {}].foo?" | nu-highlight | print - -[{foo: 123}, {}].foo? | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-55 -```nushell" | print -"# Assign a closure to a variable -let greet = { |name| print $\"Hello ($name)\"} -do $greet \"Julian\"" | nu-highlight | print - -"```\n```output-numd" | print - -# Assign a closure to a variable -let greet = { |name| print $"Hello ($name)"} -do $greet "Julian" | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-58 -```nushell" | print -"mut x = 1 -if true { - $x += 1000 -} -print $x" | nu-highlight | print - -"```\n```output-numd" | print - -mut x = 1 -if true { - $x += 1000 -} -print $x | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-63 -```nushell try,new-instance" | print -"> [{a:1 b:2} {b:1}]" | nu-highlight | print - -/opt/homebrew/bin/nu -c "[{a:1 b:2} {b:1}]" | complete | if ($in.exit_code != 0) {get stderr} else {get stdout} | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"> [{a:1 b:2} {b:1}].1.a" | nu-highlight | print - -/opt/homebrew/bin/nu -c "[{a:1 b:2} {b:1}].1.a" | complete | if ($in.exit_code != 0) {get stderr} else {get stdout} | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print diff --git a/z_examples/3_book_types_of_data/types_of_data.md_intermed_from_readme.nu b/z_examples/3_book_types_of_data/types_of_data.md_intermed_from_readme.nu deleted file mode 100644 index 33d5816..0000000 --- a/z_examples/3_book_types_of_data/types_of_data.md_intermed_from_readme.nu +++ /dev/null @@ -1,300 +0,0 @@ -# this script was generated automatically using numd -# https://github.com/nushell-prophet/numd - -const init_numd_pwd_const = '/Users/user/git/numd' - -"#code-block-marker-open-1 -```nushell" | print -"> 42 | describe" | nu-highlight | print - -42 | describe | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-3 -```nushell" | print -"> \"-5\" | into int" | nu-highlight | print - -"-5" | into int | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-5 -```nushell" | print -"> \"1.2\" | into float" | nu-highlight | print - -"1.2" | into float | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-7 -```nushell" | print -"> let mybool = 2 > 1" | nu-highlight | print - -let mybool = 2 > 1 - -"> $mybool" | nu-highlight | print - -$mybool | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"> let mybool = ($nu.home-path | path exists)" | nu-highlight | print - -let mybool = ($nu.home-path | path exists) - -"> $mybool" | nu-highlight | print - -$mybool | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-9 -```nushell" | print -"> 3.14day" | nu-highlight | print - -3.14day | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-11 -```nushell" | print -"> 30day / 1sec # How many seconds in 30 days?" | nu-highlight | print - -30day / 1sec | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-13 -```nushell" | print -"> 1Gb / 1b" | nu-highlight | print - -1Gb / 1b | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"> 1Gib / 1b" | nu-highlight | print - -1Gib / 1b | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"> (1Gib / 1b) == 2 ** 30" | nu-highlight | print - -(1Gib / 1b) == 2 ** 30 | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-15 -```nushell" | print -"> 0x[1F FF] # Hexadecimal" | nu-highlight | print - -0x[1F FF] | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"> 0b[1 1010] # Binary" | nu-highlight | print - -0b[1 1010] | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"> 0o[377] # Octal" | nu-highlight | print - -0o[377] | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-17 -```nushell" | print -"> {name: sam rank: 10}" | nu-highlight | print - -{name: sam rank: 10} | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-19 -```nushell" | print -"> {x:3 y:1} | insert z 0" | nu-highlight | print - -{x:3 y:1} | insert z 0 | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-21 -```nushell" | print -"> {name: sam, rank: 10} | transpose key value" | nu-highlight | print - -{name: sam, rank: 10} | transpose key value | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-23 -```nushell" | print -"> {x:12 y:4}.x" | nu-highlight | print - -{x:12 y:4}.x | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-25 -```nushell" | print -"> {\"1\":true \" \":false}.\" \"" | nu-highlight | print - -{"1":true " ":false}." " | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-27 -```nushell" | print -"> let data = { name: alice, age: 50 }" | nu-highlight | print - -let data = { name: alice, age: 50 } - -"> { ...$data, hobby: cricket }" | nu-highlight | print - -{ ...$data, hobby: cricket } | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-29 -```nushell" | print -"> [sam fred george]" | nu-highlight | print - -[sam fred george] | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-31 -```nushell" | print -"> [bell book candle] | where ($it =~ 'b')" | nu-highlight | print - -[bell book candle] | where ($it =~ 'b') | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-33 -```nushell" | print -"> [a b c].1" | nu-highlight | print - -[a b c].1 | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-35 -```nushell" | print -"> [a b c d e f] | slice 1..3" | nu-highlight | print - -[a b c d e f] | slice 1..3 | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-37 -```nushell" | print -"> let x = [1 2]" | nu-highlight | print - -let x = [1 2] - -"> [...$x 3 ...(4..7 | take 2)]" | nu-highlight | print - -[...$x 3 ...(4..7 | take 2)] | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-39 -```nushell" | print -"> [[column1, column2]; [Value1, Value2] [Value3, Value4]]" | nu-highlight | print - -[[column1, column2]; [Value1, Value2] [Value3, Value4]] | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-41 -```nushell" | print -"> [{name: sam, rank: 10}, {name: bob, rank: 7}]" | nu-highlight | print - -[{name: sam, rank: 10}, {name: bob, rank: 7}] | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-43 -```nushell" | print -"> [{x:12, y:5}, {x:3, y:6}] | get 0" | nu-highlight | print - -[{x:12, y:5}, {x:3, y:6}] | get 0 | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-45 -```nushell" | print -"> [[x,y];[12,5],[3,6]] | get 0" | nu-highlight | print - -[[x,y];[12,5],[3,6]] | get 0 | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-47 -```nushell" | print -"> [{x:12 y:5} {x:4 y:7} {x:2 y:2}].x" | nu-highlight | print - -[{x:12 y:5} {x:4 y:7} {x:2 y:2}].x | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-49 -```nushell" | print -"> [{x:0 y:5 z:1} {x:4 y:7 z:3} {x:2 y:2 z:0}] | select y z" | nu-highlight | print - -[{x:0 y:5 z:1} {x:4 y:7 z:3} {x:2 y:2 z:0}] | select y z | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-51 -```nushell" | print -"> [{x:0 y:5 z:1} {x:4 y:7 z:3} {x:2 y:2 z:0}] | select 1 2" | nu-highlight | print - -[{x:0 y:5 z:1} {x:4 y:7 z:3} {x:2 y:2 z:0}] | select 1 2 | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-53 -```nushell" | print -"> [{foo: 123}, {}].foo?" | nu-highlight | print - -[{foo: 123}, {}].foo? | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-55 -```nushell" | print -"# Assign a closure to a variable -let greet = { |name| print $\"Hello ($name)\"} -do $greet \"Julian\"" | nu-highlight | print - -"```\n```output-numd" | print - -# Assign a closure to a variable -let greet = { |name| print $"Hello ($name)"} -do $greet "Julian" | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-58 -```nushell" | print -"mut x = 1 -if true { - $x += 1000 -} -print $x" | nu-highlight | print - -"```\n```output-numd" | print - -mut x = 1 -if true { - $x += 1000 -} -print $x | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print - -"#code-block-marker-open-63 -```nushell try,new-instance" | print -"> [{a:1 b:2} {b:1}]" | nu-highlight | print - -/opt/homebrew/bin/nu -c "[{a:1 b:2} {b:1}]" | complete | if ($in.exit_code != 0) {get stderr} else {get stdout} | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"> [{a:1 b:2} {b:1}].1.a" | nu-highlight | print - -/opt/homebrew/bin/nu -c "[{a:1 b:2} {b:1}].1.a" | complete | if ($in.exit_code != 0) {get stderr} else {get stdout} | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - -"```" | print From 35c415ece4373b3488f5490a2fa5991405bec527 Mon Sep 17 00:00:00 2001 From: claude Date: Wed, 10 Dec 2025 22:11:39 -0300 Subject: [PATCH 10/21] docs: use separate-block option in simple_markdown example Update Example 2 to demonstrate the separate-block fence option which outputs results in a separate code block instead of inline. --- z_examples/1_simple_markdown/simple_markdown.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/z_examples/1_simple_markdown/simple_markdown.md b/z_examples/1_simple_markdown/simple_markdown.md index 232a21d..15d606f 100644 --- a/z_examples/1_simple_markdown/simple_markdown.md +++ b/z_examples/1_simple_markdown/simple_markdown.md @@ -10,9 +10,14 @@ let $var1 = 'foo' ## Example 2 -```nu +```nu separate-block # This block will produce some output in a separate block $var1 | path join 'baz' 'bar' +``` + +Output: + +``` # => foo/baz/bar ``` From 21792b1b8b7512b2d2ca876dbc2fcfd6827f17b2 Mon Sep 17 00:00:00 2001 From: maxim Date: Wed, 10 Dec 2025 22:15:07 -0300 Subject: [PATCH 11/21] example: update for clarity --- .../numd_commands_explanations.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/z_examples/2_numd_commands_explanations/numd_commands_explanations.md b/z_examples/2_numd_commands_explanations/numd_commands_explanations.md index 80215ce..68400fb 100644 --- a/z_examples/2_numd_commands_explanations/numd_commands_explanations.md +++ b/z_examples/2_numd_commands_explanations/numd_commands_explanations.md @@ -22,6 +22,7 @@ This command is used for parsing initial markdown to detect executable code bloc let $file = $init_numd_pwd_const | path join z_examples 1_simple_markdown simple_markdown.md let $md_orig = open -r $file | toggle-output-fences let $original_md_table = $md_orig | find-code-blocks + $original_md_table | table -e --width 120 # => ╭─block─┬─row_type──┬─────────────────────────────────────line─────────────────────────────────────┬──────action───────╮ # => │ 0 │ text │ ╭───────────────────────────────────────────────────────────────────────╮ │ print-as-it-is │ @@ -85,6 +86,7 @@ The `generate-intermediate-script` command generates a script that contains code # Here we emulate that the `$intermed_script_path` options is not set let $intermediate_script_path = $file | modify-path --prefix $'numd-temp-(generate-timestamp)' --suffix '.nu' + decortate-original-code-blocks $original_md_table | generate-intermediate-script | save -f $intermediate_script_path @@ -137,6 +139,7 @@ The `execute-intermediate-script` command runs and captures outputs of the execu let $no_fail_on_error = false let $nu_res_stdout_lines = execute-intermediate-script $intermediate_script_path $no_fail_on_error false rm $intermediate_script_path + $nu_res_stdout_lines # => #code-block-marker-open-1 # => ```nu @@ -168,6 +171,7 @@ $nu_res_stdout_lines let $md_res = $nu_res_stdout_lines | str join (char nl) | clean-markdown + $md_res # => #code-block-marker-open-1 # => ```nu From 50b166c2b742994aaa413e487c0c7e26a9ffe6a1 Mon Sep 17 00:00:00 2001 From: claude Date: Wed, 10 Dec 2025 22:20:32 -0300 Subject: [PATCH 12/21] fix: preserve blank lines between command groups When a command produces no output (like variable assignments), the blank line delimiter between command groups was being lost. This adds an explicit `print ''` after each command group execution to ensure visual separation is maintained in the output. --- numd/commands.nu | 2 ++ 1 file changed, 2 insertions(+) diff --git a/numd/commands.nu b/numd/commands.nu index 18a5750..2c5bcab 100644 --- a/numd/commands.nu +++ b/numd/commands.nu @@ -347,6 +347,8 @@ export def create-execution-code [ } else { } } | $in + (char nl) + # Always print a blank line after each command group to preserve visual separation + | $in + "print ''" $highlighted_command + $code_execution } From b9c074ba66296ee4b7de98405ef25869fbbf0c6b Mon Sep 17 00:00:00 2001 From: maxim Date: Wed, 10 Dec 2025 22:24:15 -0300 Subject: [PATCH 13/21] fix: example --- .../numd_commands_explanations.md | 147 ++++++++++-------- 1 file changed, 81 insertions(+), 66 deletions(-) diff --git a/z_examples/2_numd_commands_explanations/numd_commands_explanations.md b/z_examples/2_numd_commands_explanations/numd_commands_explanations.md index 68400fb..d4476a5 100644 --- a/z_examples/2_numd_commands_explanations/numd_commands_explanations.md +++ b/z_examples/2_numd_commands_explanations/numd_commands_explanations.md @@ -24,58 +24,62 @@ let $md_orig = open -r $file | toggle-output-fences let $original_md_table = $md_orig | find-code-blocks $original_md_table | table -e --width 120 -# => ╭─block─┬─row_type──┬─────────────────────────────────────line─────────────────────────────────────┬──────action───────╮ -# => │ 0 │ text │ ╭───────────────────────────────────────────────────────────────────────╮ │ print-as-it-is │ -# => │ │ │ │ # This is a simple markdown example │ │ │ -# => │ │ │ │ │ │ │ -# => │ │ │ │ ## Example 1 │ │ │ -# => │ │ │ │ │ │ │ -# => │ │ │ │ the block below will be executed as it is, but won't yield any output │ │ │ -# => │ │ │ │ │ │ │ -# => │ │ │ ╰───────────────────────────────────────────────────────────────────────╯ │ │ -# => │ 1 │ ```nu │ ╭───────────────────╮ │ execute │ -# => │ │ │ │ ```nu │ │ │ -# => │ │ │ │ let $var1 = 'foo' │ │ │ -# => │ │ │ │ ``` │ │ │ -# => │ │ │ ╰───────────────────╯ │ │ -# => │ 2 │ text │ ╭──────────────╮ │ print-as-it-is │ -# => │ │ │ │ │ │ │ -# => │ │ │ │ ## Example 2 │ │ │ -# => │ │ │ │ │ │ │ -# => │ │ │ ╰──────────────╯ │ │ -# => │ 3 │ ```nu │ ╭───────────────────────────────────────────────────────────╮ │ execute │ -# => │ │ │ │ ```nu │ │ │ -# => │ │ │ │ # This block will produce some output in a separate block │ │ │ -# => │ │ │ │ $var1 | path join 'baz' 'bar' │ │ │ -# => │ │ │ │ # => foo/baz/bar │ │ │ -# => │ │ │ │ ``` │ │ │ -# => │ │ │ ╰───────────────────────────────────────────────────────────╯ │ │ -# => │ 4 │ text │ ╭──────────────╮ │ print-as-it-is │ -# => │ │ │ │ │ │ │ -# => │ │ │ │ ## Example 3 │ │ │ -# => │ │ │ │ │ │ │ -# => │ │ │ ╰──────────────╯ │ │ -# => │ 5 │ ```nu │ ╭─────────────────────────────────────────╮ │ execute │ -# => │ │ │ │ ```nu │ │ │ -# => │ │ │ │ # This block will output results inline │ │ │ -# => │ │ │ │ whoami │ │ │ -# => │ │ │ │ # => user │ │ │ -# => │ │ │ │ │ │ │ -# => │ │ │ │ 2 + 2 │ │ │ -# => │ │ │ │ # => 4 │ │ │ -# => │ │ │ │ ``` │ │ │ -# => │ │ │ ╰─────────────────────────────────────────╯ │ │ -# => │ 6 │ text │ ╭──────────────╮ │ print-as-it-is │ -# => │ │ │ │ │ │ │ -# => │ │ │ │ ## Example 4 │ │ │ -# => │ │ │ │ │ │ │ -# => │ │ │ ╰──────────────╯ │ │ -# => │ 7 │ ``` │ ╭──────────────────────────────────────────────────────────────────────╮ │ print-as-it-is │ -# => │ │ │ │ ``` │ │ │ -# => │ │ │ │ # This block doesn't have a language identifier in the opening fence │ │ │ -# => │ │ │ │ ``` │ │ │ -# => │ │ │ ╰──────────────────────────────────────────────────────────────────────╯ │ │ -# => ╰─block─┴─row_type──┴─────────────────────────────────────line─────────────────────────────────────┴──────action───────╯ +# => ╭─block_index─┬───────row_type───────┬───────────────────────────────────line────────────────────────────────────┬─act─╮ +# => │ 0 │ text │ ╭───────────────────────────────────────────────────────────────────────╮ │ pri │ +# => │ │ │ │ # This is a simple markdown example │ │ nt- │ +# => │ │ │ │ │ │ as- │ +# => │ │ │ │ ## Example 1 │ │ it- │ +# => │ │ │ │ │ │ is │ +# => │ │ │ │ the block below will be executed as it is, but won't yield any output │ │ │ +# => │ │ │ │ │ │ │ +# => │ │ │ ╰───────────────────────────────────────────────────────────────────────╯ │ │ +# => │ 1 │ ```nu │ ╭───────────────────╮ │ exe │ +# => │ │ │ │ ```nu │ │ cut │ +# => │ │ │ │ let $var1 = 'foo' │ │ e │ +# => │ │ │ │ ``` │ │ │ +# => │ │ │ ╰───────────────────╯ │ │ +# => │ 2 │ text │ ╭──────────────╮ │ pri │ +# => │ │ │ │ │ │ nt- │ +# => │ │ │ │ ## Example 2 │ │ as- │ +# => │ │ │ │ │ │ it- │ +# => │ │ │ ╰──────────────╯ │ is │ +# => │ 3 │ ```nu separate-block │ ╭───────────────────────────────────────────────────────────╮ │ exe │ +# => │ │ │ │ ```nu separate-block │ │ cut │ +# => │ │ │ │ # This block will produce some output in a separate block │ │ e │ +# => │ │ │ │ $var1 | path join 'baz' 'bar' │ │ │ +# => │ │ │ │ ``` │ │ │ +# => │ │ │ ╰───────────────────────────────────────────────────────────╯ │ │ +# => │ 4 │ ```output-numd │ ╭──────────────────╮ │ del │ +# => │ │ │ │ ```output-numd │ │ ete │ +# => │ │ │ │ # => foo/baz/bar │ │ │ +# => │ │ │ │ ``` │ │ │ +# => │ │ │ ╰──────────────────╯ │ │ +# => │ 5 │ text │ ╭──────────────╮ │ pri │ +# => │ │ │ │ │ │ nt- │ +# => │ │ │ │ ## Example 3 │ │ as- │ +# => │ │ │ │ │ │ it- │ +# => │ │ │ ╰──────────────╯ │ is │ +# => │ 6 │ ```nu │ ╭─────────────────────────────────────────╮ │ exe │ +# => │ │ │ │ ```nu │ │ cut │ +# => │ │ │ │ # This block will output results inline │ │ e │ +# => │ │ │ │ whoami │ │ │ +# => │ │ │ │ # => user │ │ │ +# => │ │ │ │ │ │ │ +# => │ │ │ │ 2 + 2 │ │ │ +# => │ │ │ │ # => 4 │ │ │ +# => │ │ │ │ ``` │ │ │ +# => │ │ │ ╰─────────────────────────────────────────╯ │ │ +# => │ 7 │ text │ ╭──────────────╮ │ pri │ +# => │ │ │ │ │ │ nt- │ +# => │ │ │ │ ## Example 4 │ │ as- │ +# => │ │ │ │ │ │ it- │ +# => │ │ │ ╰──────────────╯ │ is │ +# => │ 8 │ ``` │ ╭──────────────────────────────────────────────────────────────────────╮ │ pri │ +# => │ │ │ │ ``` │ │ nt- │ +# => │ │ │ │ # This block doesn't have a language identifier in the opening fence │ │ as- │ +# => │ │ │ │ ``` │ │ it- │ +# => │ │ │ ╰──────────────────────────────────────────────────────────────────────╯ │ is │ +# => ╰─block_index─┴───────row_type───────┴───────────────────────────────────line────────────────────────────────────┴─act─╯ ``` ## generate-intermediate-script @@ -102,31 +106,33 @@ open $intermediate_script_path # => "let $var1 = 'foo'" | nu-highlight | print # => # => let $var1 = 'foo' -# => +# => print '' # => "```" | print # => # => "#code-block-marker-open-3 -# => ```nu" | print +# => ```nu separate-block" | print # => "# This block will produce some output in a separate block # => $var1 | path join 'baz' 'bar'" | nu-highlight | print # => +# => "```\n```output-numd" | print +# => # => # This block will produce some output in a separate block # => $var1 | path join 'baz' 'bar' | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' -# => +# => print '' # => "```" | print # => -# => "#code-block-marker-open-5 +# => "#code-block-marker-open-6 # => ```nu" | print # => "# This block will output results inline # => whoami" | nu-highlight | print # => # => # This block will output results inline # => whoami | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' -# => +# => print '' # => "2 + 2" | nu-highlight | print # => # => 2 + 2 | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' -# => +# => print '' # => "```" | print ``` @@ -144,26 +150,32 @@ $nu_res_stdout_lines # => #code-block-marker-open-1 # => ```nu # => let $var1 = 'foo' +# => # => ``` # => #code-block-marker-open-3 -# => ```nu +# => ```nu separate-block # => # This block will produce some output in a separate block # => $var1 | path join 'baz' 'bar' +# => ``` +# => ```output-numd # => # => foo/baz/bar # => # => +# => # => ``` -# => #code-block-marker-open-5 +# => #code-block-marker-open-6 # => ```nu # => # This block will output results inline # => whoami # => # => user # => # => +# => # => 2 + 2 # => # => 4 # => # => +# => # => ``` ``` @@ -176,15 +188,18 @@ $md_res # => #code-block-marker-open-1 # => ```nu # => let $var1 = 'foo' +# => # => ``` # => #code-block-marker-open-3 -# => ```nu +# => ```nu separate-block # => # This block will produce some output in a separate block # => $var1 | path join 'baz' 'bar' +# => ``` +# => ```output-numd # => # => foo/baz/bar # => # => ``` -# => #code-block-marker-open-5 +# => #code-block-marker-open-6 # => ```nu # => # This block will output results inline # => whoami @@ -205,9 +220,9 @@ compute-change-stats $file $md_orig $md_res # => ╭──────────────────┬────────────────────╮ # => │ filename │ simple_markdown.md │ # => │ nushell_blocks │ 3 │ -# => │ levenshtein_dist │ 247 │ -# => │ diff_lines │ -13 (-38.2%) │ -# => │ diff_words │ -24 (-32.4%) │ -# => │ diff_chars │ -164 (-35.0%) │ +# => │ levenshtein_dist │ 248 │ +# => │ diff_lines │ -12 (-33.3%) │ +# => │ diff_words │ -24 (-30.8%) │ +# => │ diff_chars │ -163 (-32.5%) │ # => ╰──────────────────┴────────────────────╯ ``` From d25cb8d9e8f1b1cabd97c8d1de63ac040852c7d0 Mon Sep 17 00:00:00 2001 From: maxim Date: Wed, 10 Dec 2025 22:25:08 -0300 Subject: [PATCH 14/21] chore: update examples --- README.md | 8 +-- .../simple_markdown.md_intermed.nu | 14 +++-- .../simple_markdown_with_no_output.md | 2 +- .../numd_commands_explanations.md_intermed.nu | 44 ++++++++------ .../working_with_lists.md | 8 +-- .../working_with_lists.md_intermed.nu | 58 +++++++++---------- .../simple_nu_table.md_intermed.nu | 6 +- z_examples/6_edge_cases/error-with-try.md | 3 +- .../error-with-try.md_intermed.nu | 2 +- .../raw_strings_test.md_intermed.nu | 4 +- ...simple_markdown_first_block.md_intermed.nu | 8 +-- .../numd_commands_explanations.nu | 4 ++ .../99_strip_markdown/simple_markdown.nu | 2 +- 13 files changed, 88 insertions(+), 75 deletions(-) diff --git a/README.md b/README.md index 91274f6..70f786d 100644 --- a/README.md +++ b/README.md @@ -92,10 +92,10 @@ numd run --no-save $path # => ╭──────────────────┬───────────────────────────────────╮ # => │ filename │ simple_markdown_with_no_output.md │ # => │ nushell_blocks │ 3 │ -# => │ levenshtein_dist │ 34 │ -# => │ diff_lines │ +3 (9.7%) │ -# => │ diff_words │ +5 (7.2%) │ -# => │ diff_chars │ +34 (7.8%) │ +# => │ levenshtein_dist │ 52 │ +# => │ diff_lines │ +8 (25.8%) │ +# => │ diff_words │ +6 (8.5%) │ +# => │ diff_chars │ +52 (11.6%) │ # => ╰──────────────────┴───────────────────────────────────╯ ``` diff --git a/z_examples/1_simple_markdown/simple_markdown.md_intermed.nu b/z_examples/1_simple_markdown/simple_markdown.md_intermed.nu index e568de0..2fbf578 100644 --- a/z_examples/1_simple_markdown/simple_markdown.md_intermed.nu +++ b/z_examples/1_simple_markdown/simple_markdown.md_intermed.nu @@ -16,29 +16,31 @@ header_on_separator: true, abbreviated_row_count: 1000} "let $var1 = 'foo'" | nu-highlight | print let $var1 = 'foo' - +print '' "```" | print "#code-block-marker-open-3 -```nu" | print +```nu separate-block" | print "# This block will produce some output in a separate block $var1 | path join 'baz' 'bar'" | nu-highlight | print +"```\n```output-numd" | print + # This block will produce some output in a separate block $var1 | path join 'baz' 'bar' | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - +print '' "```" | print -"#code-block-marker-open-5 +"#code-block-marker-open-6 ```nu" | print "# This block will output results inline whoami" | nu-highlight | print # This block will output results inline whoami | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - +print '' "2 + 2" | nu-highlight | print 2 + 2 | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - +print '' "```" | print diff --git a/z_examples/1_simple_markdown/simple_markdown_with_no_output.md b/z_examples/1_simple_markdown/simple_markdown_with_no_output.md index e244053..1dafbea 100644 --- a/z_examples/1_simple_markdown/simple_markdown_with_no_output.md +++ b/z_examples/1_simple_markdown/simple_markdown_with_no_output.md @@ -10,7 +10,7 @@ let $var1 = 'foo' ## Example 2 -```nu +```nu separate-block # This block will produce some output in a separate block $var1 | path join 'baz' 'bar' ``` diff --git a/z_examples/2_numd_commands_explanations/numd_commands_explanations.md_intermed.nu b/z_examples/2_numd_commands_explanations/numd_commands_explanations.md_intermed.nu index 4b547e5..f91eb03 100644 --- a/z_examples/2_numd_commands_explanations/numd_commands_explanations.md_intermed.nu +++ b/z_examples/2_numd_commands_explanations/numd_commands_explanations.md_intermed.nu @@ -26,7 +26,7 @@ $env.config.table.abbreviated_row_count = 100 # It is added by `numd` in every intermediate script to make it available in cases like below. # We use `path join` here to construct working paths for both Windows and Unix use ($init_numd_pwd_const | path join numd commands.nu) * - +print '' "```" | print "#code-block-marker-open-3 @@ -34,37 +34,41 @@ use ($init_numd_pwd_const | path join numd commands.nu) * "# Here we set the `$file` variable (which will be used in several commands throughout this script) to point to `z_examples/1_simple_markdown/simple_markdown.md`. let $file = $init_numd_pwd_const | path join z_examples 1_simple_markdown simple_markdown.md let $md_orig = open -r $file | toggle-output-fences -let $original_md_table = $md_orig | find-code-blocks -$original_md_table | table -e --width 120" | nu-highlight | print +let $original_md_table = $md_orig | find-code-blocks" | nu-highlight | print # Here we set the `$file` variable (which will be used in several commands throughout this script) to point to `z_examples/1_simple_markdown/simple_markdown.md`. let $file = $init_numd_pwd_const | path join z_examples 1_simple_markdown simple_markdown.md let $md_orig = open -r $file | toggle-output-fences let $original_md_table = $md_orig | find-code-blocks -$original_md_table | table -e --width 120 | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' +print '' +"$original_md_table | table -e --width 120" | nu-highlight | print +$original_md_table | table -e --width 120 | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' +print '' "```" | print "#code-block-marker-open-5 ```nu" | print "# Here we emulate that the `$intermed_script_path` options is not set let $intermediate_script_path = $file - | modify-path --prefix $'numd-temp-(generate-timestamp)' --suffix '.nu' -decortate-original-code-blocks $original_md_table -| generate-intermediate-script -| save -f $intermediate_script_path" | nu-highlight | print + | modify-path --prefix $'numd-temp-(generate-timestamp)' --suffix '.nu'" | nu-highlight | print # Here we emulate that the `$intermed_script_path` options is not set let $intermediate_script_path = $file | modify-path --prefix $'numd-temp-(generate-timestamp)' --suffix '.nu' +print '' +"decortate-original-code-blocks $original_md_table +| generate-intermediate-script +| save -f $intermediate_script_path" | nu-highlight | print + decortate-original-code-blocks $original_md_table | generate-intermediate-script | save -f $intermediate_script_path | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - +print '' "open $intermediate_script_path" | nu-highlight | print open $intermediate_script_path | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - +print '' "```" | print "#code-block-marker-open-7 @@ -72,29 +76,33 @@ open $intermediate_script_path | table --width 120 | default '' | into string | "# the flag `$no_fail_on_error` is set to false let $no_fail_on_error = false let $nu_res_stdout_lines = execute-intermediate-script $intermediate_script_path $no_fail_on_error false -rm $intermediate_script_path -$nu_res_stdout_lines" | nu-highlight | print +rm $intermediate_script_path" | nu-highlight | print # the flag `$no_fail_on_error` is set to false let $no_fail_on_error = false let $nu_res_stdout_lines = execute-intermediate-script $intermediate_script_path $no_fail_on_error false -rm $intermediate_script_path -$nu_res_stdout_lines | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' +rm $intermediate_script_path | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' +print '' +"$nu_res_stdout_lines" | nu-highlight | print +$nu_res_stdout_lines | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' +print '' "```" | print "#code-block-marker-open-9 ```nu" | print "let $md_res = $nu_res_stdout_lines | str join (char nl) - | clean-markdown -$md_res" | nu-highlight | print + | clean-markdown" | nu-highlight | print let $md_res = $nu_res_stdout_lines | str join (char nl) | clean-markdown -$md_res | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' +print '' +"$md_res" | nu-highlight | print +$md_res | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' +print '' "```" | print "#code-block-marker-open-11 @@ -102,5 +110,5 @@ $md_res | table --width 120 | default '' | into string | lines | each {$'# => ($ "compute-change-stats $file $md_orig $md_res" | nu-highlight | print compute-change-stats $file $md_orig $md_res | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - +print '' "```" | print diff --git a/z_examples/4_book_working_with_lists/working_with_lists.md b/z_examples/4_book_working_with_lists/working_with_lists.md index 8887dc0..9ee25cd 100644 --- a/z_examples/4_book_working_with_lists/working_with_lists.md +++ b/z_examples/4_book_working_with_lists/working_with_lists.md @@ -331,9 +331,9 @@ let zones = [UTC CET Europe/Moscow Asia/Yekaterinburg] # Show world clock for selected time zones $zones | wrap 'Zone' | upsert Time {|row| (date now | date to-timezone $row.Zone | format date '%Y.%m.%d %H:%M')} # => ╭────────Zone────────┬───────Time───────╮ -# => │ UTC │ 2025.12.11 00:49 │ -# => │ CET │ 2025.12.11 01:49 │ -# => │ Europe/Moscow │ 2025.12.11 03:49 │ -# => │ Asia/Yekaterinburg │ 2025.12.11 05:49 │ +# => │ UTC │ 2025.12.11 01:24 │ +# => │ CET │ 2025.12.11 02:24 │ +# => │ Europe/Moscow │ 2025.12.11 04:24 │ +# => │ Asia/Yekaterinburg │ 2025.12.11 06:24 │ # => ╰────────Zone────────┴───────Time───────╯ ``` diff --git a/z_examples/4_book_working_with_lists/working_with_lists.md_intermed.nu b/z_examples/4_book_working_with_lists/working_with_lists.md_intermed.nu index 9056d16..fadafa4 100644 --- a/z_examples/4_book_working_with_lists/working_with_lists.md_intermed.nu +++ b/z_examples/4_book_working_with_lists/working_with_lists.md_intermed.nu @@ -16,7 +16,7 @@ header_on_separator: true, abbreviated_row_count: 1000} "[bell book candle] | where ($it =~ 'b')" | nu-highlight | print [bell book candle] | where ($it =~ 'b') | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - +print '' "```" | print "#code-block-marker-open-3 @@ -24,7 +24,7 @@ header_on_separator: true, abbreviated_row_count: 1000} "[1, 2, 3, 4] | insert 2 10" | nu-highlight | print [1, 2, 3, 4] | insert 2 10 | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - +print '' "# [1, 2, 10, 3, 4]" | nu-highlight | print @@ -35,7 +35,7 @@ header_on_separator: true, abbreviated_row_count: 1000} "[1, 2, 3, 4] | update 1 10" | nu-highlight | print [1, 2, 3, 4] | update 1 10 | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - +print '' "# [1, 10, 3, 4]" | nu-highlight | print @@ -54,7 +54,7 @@ let colors = ($colors | prepend red) let colors = ($colors | append purple) let colors = ("black" | append $colors) $colors | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - +print '' "```" | print "#code-block-marker-open-9 @@ -68,7 +68,7 @@ let colors = [red yellow green purple] let colors = ($colors | skip 1) let colors = ($colors | drop 2) $colors | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - +print '' "```" | print "#code-block-marker-open-11 @@ -80,7 +80,7 @@ $colors # [purple black magenta]" | nu-highlight | print let colors = [red yellow green purple black magenta] let colors = ($colors | last 3) $colors | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - +print '' "```" | print "#code-block-marker-open-13 @@ -92,7 +92,7 @@ $colors # [yellow green]" | nu-highlight | print let colors = [yellow green purple] let colors = ($colors | first 2) $colors | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - +print '' "```" | print "#code-block-marker-open-15 @@ -102,7 +102,7 @@ $colors | table --width 120 | default '' | into string | lines | each {$'# => ($ let x = [1 2] [ ...$x 3 ...(4..7 | take 2) ] | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - +print '' "```" | print "#code-block-marker-open-17 @@ -113,12 +113,12 @@ $names | each { |elt| $\"Hello, ($elt)!\" } let names = [Mark Tami Amanda Jeremy] $names | each { |elt| $"Hello, ($elt)!" } | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - +print '' "$names | enumerate | each { |elt| $\"($elt.index + 1) - ($elt.item)\" } # Outputs \"1 - Mark\", \"2 - Tami\", etc." | nu-highlight | print $names | enumerate | each { |elt| $"($elt.index + 1) - ($elt.item)" } | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - +print '' "```" | print "#code-block-marker-open-19 @@ -131,7 +131,7 @@ $colors | where ($it | str ends-with 'e') let colors = [red orange yellow green blue purple] $colors | where ($it | str ends-with 'e') # The block passed to `where` must evaluate to a boolean. - +print '' "```" | print "#code-block-marker-open-21 @@ -141,7 +141,7 @@ $scores | where $it > 7 # [10 8]" | nu-highlight | print let scores = [7 10 8 6 7] $scores | where $it > 7 | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - +print '' "```" | print "#code-block-marker-open-23 @@ -157,7 +157,7 @@ $"total = ($scores | reduce { |elt, acc| $acc + $elt })" # total = 15 $"total = ($scores | math sum)" # easier approach, same result $"product = ($scores | reduce --fold 1 { |elt, acc| $acc * $elt })" # product = 96 $scores | enumerate | reduce --fold 0 { |elt, acc| $acc + $elt.index * $elt.item } | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - +print '' "```" | print "#code-block-marker-open-25 @@ -167,7 +167,7 @@ $names.1 # gives Tami" | nu-highlight | print let names = [Mark Tami Amanda Jeremy] $names.1 | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - +print '' "```" | print "#code-block-marker-open-27 @@ -179,7 +179,7 @@ $names | get $index # gives Tami" | nu-highlight | print let names = [Mark Tami Amanda Jeremy] let index = 1 $names | get $index | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - +print '' "```" | print "#code-block-marker-open-29 @@ -189,13 +189,13 @@ $colors | is-empty # false" | nu-highlight | print let colors = [red green blue] $colors | is-empty | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - +print '' "let colors = [] $colors | is-empty # true" | nu-highlight | print let colors = [] $colors | is-empty | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - +print '' "```" | print "#code-block-marker-open-31 @@ -209,7 +209,7 @@ let colors = [red green blue] 'blue' in $colors # true 'yellow' in $colors # false 'gold' not-in $colors | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - +print '' "```" | print "#code-block-marker-open-33 @@ -221,13 +221,13 @@ $colors | any {|elt| $elt | str ends-with \"e\" } # true" | nu-highlight | print let colors = [red green blue] # Do any color names end with "e"? $colors | any {|elt| $elt | str ends-with "e" } | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - +print '' "# Is the length of any color name less than 3? $colors | any {|elt| ($elt | str length) < 3 } # false" | nu-highlight | print # Is the length of any color name less than 3? $colors | any {|elt| ($elt | str length) < 3 } | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - +print '' "let scores = [3 8 4] # Are any scores greater than 7? $scores | any {|elt| $elt > 7 } # true" | nu-highlight | print @@ -235,13 +235,13 @@ $scores | any {|elt| $elt > 7 } # true" | nu-highlight | print let scores = [3 8 4] # Are any scores greater than 7? $scores | any {|elt| $elt > 7 } | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - +print '' "# Are any scores odd? $scores | any {|elt| $elt mod 2 == 1 } # true" | nu-highlight | print # Are any scores odd? $scores | any {|elt| $elt mod 2 == 1 } | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - +print '' "```" | print "#code-block-marker-open-35 @@ -253,13 +253,13 @@ $colors | all {|elt| $elt | str ends-with \"e\" } # false" | nu-highlight | prin let colors = [red green blue] # Do all color names end with "e"? $colors | all {|elt| $elt | str ends-with "e" } | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - +print '' "# Is the length of all color names greater than or equal to 3? $colors | all {|elt| ($elt | str length) >= 3 } # true" | nu-highlight | print # Is the length of all color names greater than or equal to 3? $colors | all {|elt| ($elt | str length) >= 3 } | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - +print '' "let scores = [3 8 4] # Are all scores greater than 7? $scores | all {|elt| $elt > 7 } # false" | nu-highlight | print @@ -267,13 +267,13 @@ $scores | all {|elt| $elt > 7 } # false" | nu-highlight | print let scores = [3 8 4] # Are all scores greater than 7? $scores | all {|elt| $elt > 7 } | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - +print '' "# Are all scores even? $scores | all {|elt| $elt mod 2 == 0 } # false" | nu-highlight | print # Are all scores even? $scores | all {|elt| $elt mod 2 == 0 } | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - +print '' "```" | print "#code-block-marker-open-37 @@ -281,11 +281,11 @@ $scores | all {|elt| $elt mod 2 == 0 } | table --width 120 | default '' | into s "[1 [2 3] 4 [5 6]] | flatten # [1 2 3 4 5 6]" | nu-highlight | print [1 [2 3] 4 [5 6]] | flatten | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - +print '' "[[1 2] [3 [4 5 [6 7 8]]]] | flatten | flatten | flatten # [1 2 3 4 5 6 7 8]" | nu-highlight | print [[1 2] [3 [4 5 [6 7 8]]]] | flatten | flatten | flatten | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - +print '' "```" | print "#code-block-marker-open-39 @@ -297,5 +297,5 @@ $zones | wrap 'Zone' | upsert Time {|row| (date now | date to-timezone $row.Zone let zones = [UTC CET Europe/Moscow Asia/Yekaterinburg] # Show world clock for selected time zones $zones | wrap 'Zone' | upsert Time {|row| (date now | date to-timezone $row.Zone | format date '%Y.%m.%d %H:%M')} | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - +print '' "```" | print diff --git a/z_examples/5_simple_nu_table/simple_nu_table.md_intermed.nu b/z_examples/5_simple_nu_table/simple_nu_table.md_intermed.nu index 4b34204..f0d4636 100644 --- a/z_examples/5_simple_nu_table/simple_nu_table.md_intermed.nu +++ b/z_examples/5_simple_nu_table/simple_nu_table.md_intermed.nu @@ -16,7 +16,7 @@ header_on_separator: true, abbreviated_row_count: 1000} "$env.numd?" | nu-highlight | print $env.numd? | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - +print '' "```" | print "#code-block-marker-open-2 @@ -24,7 +24,7 @@ $env.numd? | table --width 120 | default '' | into string | lines | each {$'# => "[[a b c]; [1 2 3]]" | nu-highlight | print [[a b c]; [1 2 3]] | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - +print '' "```" | print "#code-block-marker-open-4 @@ -50,5 +50,5 @@ $env.numd? | table --width 120 | default '' | into string | lines | each {$'# => 'ut. Exercitation dolore fugiat nulla ut adipiscing laboris elit. Fugiat nulla ut ' + 'adipiscing, laboris elit quis pariatur. Adipiscing laboris elit quis pariatur. ' + 'Elit quis pariatur, in ut anim anim ut.')]] | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - +print '' "```" | print diff --git a/z_examples/6_edge_cases/error-with-try.md b/z_examples/6_edge_cases/error-with-try.md index 02f3be9..8fd11f4 100644 --- a/z_examples/6_edge_cases/error-with-try.md +++ b/z_examples/6_edge_cases/error-with-try.md @@ -17,7 +17,6 @@ lssomething # => : ^^^^^|^^^^^ # => : `-- Command `lssomething` not found # => `---- -# => help: `lssomething` is neither a Nushell built-in or a known external -# => command +# => help: `lssomething` is neither a Nushell built-in or a known external command # => ``` diff --git a/z_examples/6_edge_cases/error-with-try.md_intermed.nu b/z_examples/6_edge_cases/error-with-try.md_intermed.nu index 77390e3..d65860d 100644 --- a/z_examples/6_edge_cases/error-with-try.md_intermed.nu +++ b/z_examples/6_edge_cases/error-with-try.md_intermed.nu @@ -16,5 +16,5 @@ header_on_separator: true, abbreviated_row_count: 1000} "lssomething" | nu-highlight | print /opt/homebrew/bin/nu -c "lssomething" | complete | if ($in.exit_code != 0) {get stderr} else {get stdout} | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - +print '' "```" | print diff --git a/z_examples/6_edge_cases/raw_strings_test.md_intermed.nu b/z_examples/6_edge_cases/raw_strings_test.md_intermed.nu index db0c096..d5de404 100644 --- a/z_examples/6_edge_cases/raw_strings_test.md_intermed.nu +++ b/z_examples/6_edge_cases/raw_strings_test.md_intermed.nu @@ -18,7 +18,7 @@ header_on_separator: true, abbreviated_row_count: 1000} let $two_single_lines_text = r#'"High up in the mountains, a Snake crawled and lay in a damp gorge, coiled into a knot, staring out at the sea.'# - +print '' "```" | print "#code-block-marker-open-3 @@ -26,5 +26,5 @@ let $two_single_lines_text = r#'"High up in the mountains, a Snake crawled and l "$two_single_lines_text" | nu-highlight | print $two_single_lines_text | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - +print '' "```" | print diff --git a/z_examples/6_edge_cases/simple_markdown_first_block.md_intermed.nu b/z_examples/6_edge_cases/simple_markdown_first_block.md_intermed.nu index d21652d..e82127a 100644 --- a/z_examples/6_edge_cases/simple_markdown_first_block.md_intermed.nu +++ b/z_examples/6_edge_cases/simple_markdown_first_block.md_intermed.nu @@ -16,7 +16,7 @@ header_on_separator: true, abbreviated_row_count: 1000} "let $var1 = 'foo'" | nu-highlight | print let $var1 = 'foo' - +print '' "```" | print "#code-block-marker-open-2 @@ -26,7 +26,7 @@ $var1 | path join 'baz' 'bar'" | nu-highlight | print # This block will produce some output in a separate block $var1 | path join 'baz' 'bar' | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - +print '' "```" | print "#code-block-marker-open-4 @@ -36,9 +36,9 @@ whoami" | nu-highlight | print # This block will output results inline whoami | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - +print '' "2 + 2" | nu-highlight | print 2 + 2 | table --width 120 | default '' | into string | lines | each {$'# => ($in)' | str trim --right} | str join (char nl) | str replace -r '\s*$' "\n" | print; print '' - +print '' "```" | print diff --git a/z_examples/99_strip_markdown/numd_commands_explanations.nu b/z_examples/99_strip_markdown/numd_commands_explanations.nu index 6080c5e..b1d4733 100644 --- a/z_examples/99_strip_markdown/numd_commands_explanations.nu +++ b/z_examples/99_strip_markdown/numd_commands_explanations.nu @@ -13,6 +13,7 @@ use ($init_numd_pwd_const | path join numd commands.nu) * let $file = $init_numd_pwd_const | path join z_examples 1_simple_markdown simple_markdown.md let $md_orig = open -r $file | toggle-output-fences let $original_md_table = $md_orig | find-code-blocks + $original_md_table | table -e --width 120 @@ -20,6 +21,7 @@ $original_md_table | table -e --width 120 # Here we emulate that the `$intermed_script_path` options is not set let $intermediate_script_path = $file | modify-path --prefix $'numd-temp-(generate-timestamp)' --suffix '.nu' + decortate-original-code-blocks $original_md_table | generate-intermediate-script | save -f $intermediate_script_path @@ -32,6 +34,7 @@ open $intermediate_script_path let $no_fail_on_error = false let $nu_res_stdout_lines = execute-intermediate-script $intermediate_script_path $no_fail_on_error false rm $intermediate_script_path + $nu_res_stdout_lines @@ -39,6 +42,7 @@ $nu_res_stdout_lines let $md_res = $nu_res_stdout_lines | str join (char nl) | clean-markdown + $md_res diff --git a/z_examples/99_strip_markdown/simple_markdown.nu b/z_examples/99_strip_markdown/simple_markdown.nu index f0e0855..cba0f81 100644 --- a/z_examples/99_strip_markdown/simple_markdown.nu +++ b/z_examples/99_strip_markdown/simple_markdown.nu @@ -3,7 +3,7 @@ let $var1 = 'foo' - # ```nu + # ```nu separate-block # This block will produce some output in a separate block $var1 | path join 'baz' 'bar' From a5ac69de55b9a878ad5b17969a61f6d01bc1167b Mon Sep 17 00:00:00 2001 From: maxim Date: Wed, 10 Dec 2025 22:32:16 -0300 Subject: [PATCH 15/21] chore: beautify --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 70f786d..8289c77 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,7 @@ It is possible to set Nushell visual settings (and all the others) using the `-- ```nushell let path = $nu.temp-path | path join simple_nu_table.md + # let's generate some markdown and save it to the `simple_nu_table.md` file in the temp directory "```nushell\n[[a b c]; [1 2 3]]\n```\n" | save -f $path @@ -235,13 +236,13 @@ Testing of the `numd` module is done via `toolkit.nu`: ```nushell no-run # Run all tests (unit + integration) -> nu toolkit.nu testing +nu toolkit.nu testing # Run only unit tests (uses nutest framework) -> nu toolkit.nu testing-unit +nu toolkit.nu testing-unit # Run only integration tests (executes example markdown files) -> nu toolkit.nu testing-integration +nu toolkit.nu testing-integration ``` ### Unit tests @@ -253,7 +254,7 @@ Unit tests in `tests/` use the [nutest](https://github.com/vyadh/nutest) framewo Integration tests run all example files in `z_examples/` through numd and report changes via Levenshtein distance. Whatever changes are made in the module - it can be easily seen if they break anything (both by the Levenshtein distance metric or by `git diff` of the updated example files versus their initial versions). ```nushell no-run -> nu toolkit.nu testing-integration +nu toolkit.nu testing-integration # => ╭───────────────────────────────────────────────┬─────────────────┬───────────────────┬────────────┬──────────────┬─────╮ # => │ filename │ nushell_blocks │ levenshtein_dist │ diff_lines │ diff_words │ ... │ # => ├───────────────────────────────────────────────┼─────────────────┼───────────────────┼────────────┼──────────────┼─────┤ From 9f85ff8babe88b5f440fc0512fa9b17cc067dfc4 Mon Sep 17 00:00:00 2001 From: maxim Date: Wed, 10 Dec 2025 22:51:33 -0300 Subject: [PATCH 16/21] chore: beautify --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8289c77..1ceee7e 100644 --- a/README.md +++ b/README.md @@ -6,13 +6,16 @@ Execute blocks of nushell code within markdown documents, write results back to ```nushell no-run # this block won't run as it has the option `no-run` in its code fence + git clone https://github.com/nushell-prophet/numd; cd numd -nupm install --force --path . # optionally you can install this module via nupm +# optionally you can install this module via nupm +nupm install --force --path . use numd -numd run README.md --no-save +# run it on any file to check +numd run z_examples/1_simple_markdown/simple_markdown.md --no-save ``` ## How it works From 563894a92b0c33c25b1a6d69a65a8182a6f5ca90 Mon Sep 17 00:00:00 2001 From: claude Date: Sat, 13 Dec 2025 00:04:28 -0300 Subject: [PATCH 17/21] refactor: remove obsolete --whole_block flag The --whole_block flag in create-execution-code was defined but never used in the function body. It became obsolete when the separate-block fence option was introduced. This commit removes the unused flag from: - Function signature - Example comment - Function call in execute-block-lines Also includes minor spacing beautification around closures. --- numd/commands.nu | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/numd/commands.nu b/numd/commands.nu index 2c5bcab..ca6247d 100644 --- a/numd/commands.nu +++ b/numd/commands.nu @@ -156,7 +156,7 @@ export def --env 'capture start' [ | str replace --regex --all "[\n\r ]+```\n" "\n```\n" } else { # inline output format: command followed by `# =>` prefixed output - let output_lines = $in | lines | each {$'# => ($in)'} | str join (char nl) + let output_lines = $in | lines | each { $'# => ($in)' } | str join (char nl) $"($command)\n($output_lines)\n\n" } | str replace --regex "\n{3,}$" "\n\n" @@ -318,10 +318,9 @@ export def match-action [ # Generate code for execution in the intermediate script within a given code fence. # -# > 'ls | sort-by modified -r' | create-execution-code --whole_block ['no-output'] | save z_examples/999_numd_internals/create-execution-code_0.nu -f +# > 'ls | sort-by modified -r' | create-execution-code ['no-output'] | save z_examples/999_numd_internals/create-execution-code_0.nu -f export def create-execution-code [ fence_options: list - --whole_block ]: string -> string { let code_content = $in # let fence_options = $env.numd.current_block_options @@ -397,12 +396,12 @@ export def execute-block-lines [ if ($group | str trim | is-empty) { # preserve blank line separators '' - } else if ($group | str trim | str starts-with '#') and ($group | str trim | lines | all {|line| $line =~ '^#'}) { + } else if ($group | str trim | str starts-with '#') and ($group | str trim | lines | all {|line| $line =~ '^#' }) { # pure comment group - just highlight it $group | create-highlight-command } else { # executable command group - $group | create-execution-code $fence_options --whole_block + $group | create-execution-code $fence_options } } } From 6904d297af9e153ce4bd6053a205d0bc6c64d547 Mon Sep 17 00:00:00 2001 From: claude Date: Sat, 13 Dec 2025 00:10:56 -0300 Subject: [PATCH 18/21] refactor: simplify execute-block-lines logic --- numd/commands.nu | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/numd/commands.nu b/numd/commands.nu index ca6247d..cc096cf 100644 --- a/numd/commands.nu +++ b/numd/commands.nu @@ -393,14 +393,12 @@ export def execute-block-lines [ | str join (char nl) | split-by-blank-lines | each {|group| - if ($group | str trim | is-empty) { - # preserve blank line separators + let trimmed = $group | str trim + if ($trimmed | is-empty) { '' - } else if ($group | str trim | str starts-with '#') and ($group | str trim | lines | all {|line| $line =~ '^#' }) { - # pure comment group - just highlight it + } else if ($trimmed | lines | all {$in =~ '^#'}) { $group | create-highlight-command } else { - # executable command group $group | create-execution-code $fence_options } } From 507f040a740e2c15d63e688f486bfc2824aced24 Mon Sep 17 00:00:00 2001 From: claude Date: Sat, 13 Dec 2025 00:17:37 -0300 Subject: [PATCH 19/21] refactor: simplify get-last-span, check-print-append, and convert-short-options - get-last-span: Remove redundant str trim -c "\n" before str trim - check-print-append: Replace if/else returning booleans with single boolean expression - convert-short-options: Extract result to explicit variable for clearer flow --- numd/commands.nu | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/numd/commands.nu b/numd/commands.nu index cc096cf..5619dda 100644 --- a/numd/commands.nu +++ b/numd/commands.nu @@ -396,7 +396,7 @@ export def execute-block-lines [ let trimmed = $group | str trim if ($trimmed | is-empty) { '' - } else if ($trimmed | lines | all {$in =~ '^#'}) { + } else if ($trimmed | lines | all { $in =~ '^#' }) { $group | create-highlight-command } else { $group | create-execution-code $fence_options @@ -547,13 +547,13 @@ export def convert-short-options [ option: string ]: nothing -> string { let options_dict = list-code-options + let result = $options_dict | get --optional $option | default $option - $options_dict - | get --optional $option - | default $option - | if $in not-in ($options_dict | values) { - print $'(ansi red)($in) is unknown option(ansi reset)' - } else { } + if $result not-in ($options_dict | values) { + print $'(ansi red)($result) is unknown option(ansi reset)' + } + + $result } # Escape symbols to be printed unchanged inside a `print "something"` statement. @@ -639,7 +639,7 @@ export def remove-comments-plus []: string -> string { export def get-last-span [ command: string ]: nothing -> string { - let command = $command | str trim -c "\n" | str trim + let command = $command | str trim let spans = ast $command --json | get block | from json @@ -677,11 +677,9 @@ export def check-print-append [ ]: nothing -> bool { let last_span = get-last-span $command - if $last_span =~ '(;|print|null)$' { - false - } else { - $last_span !~ '\b(let|mut|def|use)\b' and $last_span !~ '(^|;|\n) ?(? Date: Sat, 13 Dec 2025 00:19:13 -0300 Subject: [PATCH 20/21] refactor: use cleaner negation syntax in where clauses Simplify regex negation from `where not ($it =~ ...)` to `where $it !~ ...` and improve formatting of boolean conditions in check-print-append for consistency with recent refactoring. --- numd/commands.nu | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/numd/commands.nu b/numd/commands.nu index 5619dda..da8a228 100644 --- a/numd/commands.nu +++ b/numd/commands.nu @@ -389,7 +389,7 @@ export def execute-block-lines [ fence_options: list ]: list -> list { skip | drop # skip code fences - | where not ($it =~ '^# =>') # strip existing `# =>` output lines (keep plain `#` comments) + | where $it !~ '^# =>' # strip existing `# =>` output lines (keep plain `#` comments) | str join (char nl) | split-by-blank-lines | each {|group| @@ -677,9 +677,11 @@ export def check-print-append [ ]: nothing -> bool { let last_span = get-last-span $command - ($last_span !~ '(;|print|null)$' - and $last_span !~ '\b(let|mut|def|use)\b' - and $last_span !~ '(^|;|\n) ?(? Date: Sat, 13 Dec 2025 00:23:29 -0300 Subject: [PATCH 21/21] refactor: simplify closures using $in instead of named parameters --- numd/commands.nu | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/numd/commands.nu b/numd/commands.nu index da8a228..61ce6b9 100644 --- a/numd/commands.nu +++ b/numd/commands.nu @@ -232,8 +232,8 @@ export def 'parse-help' [ let input = $in $input - | update Description ($input.Description | take until {|line| $line == '' } | append '') - | upsert Examples {|i| $i.Examples? | append ($input.Description | skip until {|line| $line == '' } | skip) } + | update Description ($input.Description | take until { $in == '' } | append '') + | upsert Examples {|i| $i.Examples? | append ($input.Description | skip until { $in == '' } | skip) } } else { } | if $sections == null { } else { select -o ...$sections } | if $record { @@ -293,12 +293,12 @@ export def find-code-blocks []: string -> table list { # Parse block indices from Nushell output lines and return a table with the original markdown line numbers. export def extract-block-index []: list -> table { - let clean_lines = skip until {|x| $x =~ (mark-code-block) } + let clean_lines = skip until { $in =~ (mark-code-block) } let block_index = $clean_lines | each { @@ -435,7 +435,7 @@ export def extract-block-index []: list -> table list { | split row ',' | str trim | compact --empty - | each {|option| convert-short-options $option } + | each { convert-short-options $in } } # Modify a path by adding a prefix, suffix, extension, or parent directory.