to md

For formats.

Convert table into simple Markdown.

Command Type

built-in

Signature

> to md {flags}

Flags

  • --pretty, -p: Formats the Markdown table to vertically align items.
  • --per-element, -e: Treat each row as markdown syntax element.
  • --center, -c {list<cell-path>}: Formats the Markdown table to center given columns.
  • --escape-md, -m: Escapes Markdown special characters.
  • --escape-html, -t: Escapes HTML special characters.
  • --escape-all, -a: Escapes both Markdown and HTML special characters.
  • --list, -l {string}: Format lists as ‘ordered’ (1. 2. 3.), ‘unordered’ (* * *), or ‘none’. Default: unordered.

Input/output types:

input output
any string

Examples

Outputs an MD string representing the contents of this table.

> [[foo bar]; [1 2]] | to md
| foo | bar |
| --- | --- |
| 1 | 2 |

Optionally, output a formatted markdown string.

> [[foo bar]; [1 2]] | to md --pretty
| foo | bar |
| --- | --- |
| 1   | 2   |

Treat each row as a markdown element.

> [{"H1": "Welcome to Nushell" } [[foo bar]; [1 2]]] | to md --per-element --pretty
# Welcome to Nushell
| foo | bar |
| --- | --- |
| 1   | 2   |

Render a list (unordered by default).

> [0 1 2] | to md
* 0
* 1
* 2

Separate list into markdown tables.

> [ {foo: 1, bar: 2} {foo: 3, bar: 4} {foo: 5}] | to md --per-element
| foo | bar |
| --- | --- |
| 1 | 2 |
| 3 | 4 |

| foo |
| --- |
| 5 |

Center a column of a markdown table.

> [ {foo: 1, bar: 2} {foo: 3, bar: 4}] | to md --pretty --center [bar]
| foo | bar |
| --- |:---:|
| 1   |  2  |
| 3   |  4  |

Escape markdown special characters.

> [ {foo: "_1_", bar: "\# 2"} {foo: "[3]", bar: "4|5"}] | to md --escape-md
| foo | bar |
| --- | --- |
| \_1\_ | \# 2 |
| \[3\] | 4\|5 |

Escape html special characters.

> [ {a: p, b: "<p>Welcome to nushell</p>"}] | to md --escape-html
| a | b |
| --- | --- |
| p | &lt;p&gt;Welcome to nushell&lt;&#x2f;p&gt; |

Render a list as an ordered markdown list.

> [one two three] | to md --list ordered
1. one
2. two
3. three

Render a list without markers.

> [one two three] | to md --list none
one
two
three

Ported from nushell/nushell.github.io. Copyright (c) 2021 Nushell Project. MIT License.