In a previous post you could see how to transform a table structure into Markdown markup for a table using the to md command.
Nushell also supports transforming lists into Markdown markup for ordered and unordered lists.
The input into the to md command should be a list of items.
This returns by default an unordered list in Markdown markup.
With the option --list (or short option -l) you can specify the value ordered to get an ordered list.
With value none the list of items is simply returned which each item on a new line.
Finally you can also explicitly use the value unordered to get the default behavior of an unordered list in Markdown markup.
The following examples show the output of transforming a list of items into Markdown markup using several options:
use std/assert
# Sample list with four items.
let items = [a b c d]
# Use `to md` to get the Markdown markup for
# an unordered list (default).
(assert equal ($items | to md)
("
* a
* b
* c
* d" | str trim))
# Use `to md` to get the Markdown markup for
# an unordered list, but use the explicit option
# `--list` with the value `unordered`.
(assert equal ($items | to md --list unordered)
("
* a
* b
* c
* d" | str trim))
# Use `to md` to get the Markdown markup for
# an unordered list, but use the short option
# `-l` with the value `unordered`.
(assert equal ($items | to md -l unordered)
("
* a
* b
* c
* d" | str trim))
# Use `to md` with option `--list` with value
# `ordered` to get the Markdown markup for
# an ordered list.
(assert equal ($items | to md --list ordered)
("
1. a
2. b
3. c
4. d" | str trim))
# Finally use `to md` with the short option `-l`
# with value `none` to get a each item of the
# list on a new line.
(assert equal ($items | to md -l none)
("
a
b
c
d" | str trim))
Written with Nushell 0.117.0.