Support markdown format on input (#1478)

* Support markdown on input

* unit-test files

* doc mods

* Unit-test cases for I/O-format keystroke-savers

* -i/-o md as well as -i/-o markdown
This commit is contained in:
John Kerl 2024-01-20 16:51:15 -05:00 committed by GitHub
parent 2abb9b4729
commit af021f28d7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
243 changed files with 803 additions and 114 deletions

View file

@ -69,7 +69,7 @@ PPRINT: pretty-printed tabular
| 4 5 6 | Record 2: "apple":"4", "bat":"5", "cog":"6"
+---------------------+
Markdown tabular (supported for output only):
Markdown tabular:
+-----------------------+
| | apple | bat | cog | |
| | --- | --- | --- | |
@ -435,7 +435,8 @@ which renders like this when dropped into various web tools (e.g. github comment
![pix/omd.png](pix/omd.png)
As of Miller 4.3.0, markdown format is supported only for output, not input.
As of Miller 4.3.0, markdown format is supported only for output, not input; as of Miller 6.11.0, markdown format
is supported for input as well.
## XTAB: Vertical tabular
@ -635,19 +636,19 @@ While you can do format conversion using `mlr --icsv --ojson cat myfile.csv`, th
FORMAT-CONVERSION KEYSTROKE-SAVER FLAGS
As keystroke-savers for format-conversion you may use the following.
The letters c, t, j, l, d, n, x, p, and m refer to formats CSV, TSV, DKVP, NIDX,
JSON, JSON Lines, XTAB, PPRINT, and markdown, respectively. Note that markdown
format is available for output only.
JSON, JSON Lines, XTAB, PPRINT, and markdown, respectively.
| In\out | CSV | TSV | JSON | JSONL | DKVP | NIDX | XTAB | PPRINT | Markdown |
+--------+-------+-------+--------+--------+--------+--------+--------+----------+
| CSV | | --c2t | --c2j | --c2l | --c2d | --c2n | --c2x | --c2p | --c2m |
| TSV | --t2c | | --t2j | --t2l | --t2d | --t2n | --t2x | --t2p | --t2m |
| JSON | --j2c | --j2t | | --j2l | --j2d | --j2n | --j2x | --j2p | --j2m |
| JSONL | --l2c | --l2t | | | --l2d | --l2n | --l2x | --l2p | --l2m |
| DKVP | --d2c | --d2t | --d2j | --d2l | | --d2n | --d2x | --d2p | --d2m |
| NIDX | --n2c | --n2t | --n2j | --n2l | --n2d | | --n2x | --n2p | --n2m |
| XTAB | --x2c | --x2t | --x2j | --x2l | --x2d | --x2n | | --x2p | --x2m |
| PPRINT | --p2c | --p2t | --p2j | --p2l | --p2d | --p2n | --p2x | | --p2m |
| In\out | CSV | TSV | JSON | JSONL | DKVP | NIDX | XTAB | PPRINT | Markdown |
+----------+-------+-------+--------+--------+--------+--------+--------+--------+----------|
| CSV | | --c2t | --c2j | --c2l | --c2d | --c2n | --c2x | --c2p | --c2m |
| TSV | --t2c | | --t2j | --t2l | --t2d | --t2n | --t2x | --t2p | --t2m |
| JSON | --j2c | --j2t | | --j2l | --j2d | --j2n | --j2x | --j2p | --j2m |
| JSONL | --l2c | --l2t | | | --l2d | --l2n | --l2x | --l2p | --l2m |
| DKVP | --d2c | --d2t | --d2j | --d2l | | --d2n | --d2x | --d2p | --d2m |
| NIDX | --n2c | --n2t | --n2j | --n2l | --n2d | | --n2x | --n2p | --n2m |
| XTAB | --x2c | --x2t | --x2j | --x2l | --x2d | --x2n | | --x2p | --x2m |
| PPRINT | --p2c | --p2t | --p2j | --p2l | --p2d | --p2n | --p2x | | --p2m |
| Markdown | --m2c | --m2t | --m2j | --m2l | --m2d | --m2n | --m2x | --m2p | |
-p Keystroke-saver for `--nidx --fs space --repifs`.
-T Keystroke-saver for `--nidx --fs tab`.

View file

@ -177,7 +177,8 @@ which renders like this when dropped into various web tools (e.g. github comment
![pix/omd.png](pix/omd.png)
As of Miller 4.3.0, markdown format is supported only for output, not input.
As of Miller 4.3.0, markdown format is supported only for output, not input; as of Miller 6.11.0, markdown format
is supported for input as well.
## XTAB: Vertical tabular

View file

@ -101,7 +101,7 @@ This is simply a copy of what you should see on running `man mlr` at a command p
| 4 5 6 | Record 2: "apple":"4", "bat":"5", "cog":"6"
+---------------------+
Markdown tabular (supported for output only):
Markdown tabular:
+-----------------------+
| | apple | bat | cog | |
| | --- | --- | --- | |
@ -381,6 +381,7 @@ This is simply a copy of what you should see on running `man mlr` at a command p
seqgen verb, which is more useful/intuitive.
--ijson Use JSON format for input data.
--ijsonl Use JSON Lines format for input data.
--imd or --imarkdown Use markdown-tabular format for input data.
--inidx Use NIDX format for input data.
--io {format name} Use format name for input and output data. For
example: `--io csv` is the same as `--csv`.
@ -398,7 +399,7 @@ This is simply a copy of what you should see on running `man mlr` at a command p
--odkvp Use DKVP format for output data.
--ojson Use JSON format for output data.
--ojsonl Use JSON Lines format for output data.
--omd Use markdown-tabular format for output data.
--omd or --omarkdown Use markdown-tabular format for output data.
--onidx Use NIDX format for output data.
--opprint Use PPRINT format for output data.
--otsv Use TSV format for output data.
@ -440,19 +441,19 @@ This is simply a copy of what you should see on running `man mlr` at a command p
1mFORMAT-CONVERSION KEYSTROKE-SAVER FLAGS0m
As keystroke-savers for format-conversion you may use the following.
The letters c, t, j, l, d, n, x, p, and m refer to formats CSV, TSV, DKVP, NIDX,
JSON, JSON Lines, XTAB, PPRINT, and markdown, respectively. Note that markdown
format is available for output only.
JSON, JSON Lines, XTAB, PPRINT, and markdown, respectively.
| In\out | CSV | TSV | JSON | JSONL | DKVP | NIDX | XTAB | PPRINT | Markdown |
+--------+-------+-------+--------+--------+--------+--------+--------+----------+
| CSV | | --c2t | --c2j | --c2l | --c2d | --c2n | --c2x | --c2p | --c2m |
| TSV | --t2c | | --t2j | --t2l | --t2d | --t2n | --t2x | --t2p | --t2m |
| JSON | --j2c | --j2t | | --j2l | --j2d | --j2n | --j2x | --j2p | --j2m |
| JSONL | --l2c | --l2t | | | --l2d | --l2n | --l2x | --l2p | --l2m |
| DKVP | --d2c | --d2t | --d2j | --d2l | | --d2n | --d2x | --d2p | --d2m |
| NIDX | --n2c | --n2t | --n2j | --n2l | --n2d | | --n2x | --n2p | --n2m |
| XTAB | --x2c | --x2t | --x2j | --x2l | --x2d | --x2n | | --x2p | --x2m |
| PPRINT | --p2c | --p2t | --p2j | --p2l | --p2d | --p2n | --p2x | | --p2m |
| In\out | CSV | TSV | JSON | JSONL | DKVP | NIDX | XTAB | PPRINT | Markdown |
+----------+-------+-------+--------+--------+--------+--------+--------+--------+----------|
| CSV | | --c2t | --c2j | --c2l | --c2d | --c2n | --c2x | --c2p | --c2m |
| TSV | --t2c | | --t2j | --t2l | --t2d | --t2n | --t2x | --t2p | --t2m |
| JSON | --j2c | --j2t | | --j2l | --j2d | --j2n | --j2x | --j2p | --j2m |
| JSONL | --l2c | --l2t | | | --l2d | --l2n | --l2x | --l2p | --l2m |
| DKVP | --d2c | --d2t | --d2j | --d2l | | --d2n | --d2x | --d2p | --d2m |
| NIDX | --n2c | --n2t | --n2j | --n2l | --n2d | | --n2x | --n2p | --n2m |
| XTAB | --x2c | --x2t | --x2j | --x2l | --x2d | --x2n | | --x2p | --x2m |
| PPRINT | --p2c | --p2t | --p2j | --p2l | --p2d | --p2n | --p2x | | --p2m |
| Markdown | --m2c | --m2t | --m2j | --m2l | --m2d | --m2n | --m2x | --m2p | |
-p Keystroke-saver for `--nidx --fs space --repifs`.
-T Keystroke-saver for `--nidx --fs tab`.

View file

@ -80,7 +80,7 @@
| 4 5 6 | Record 2: "apple":"4", "bat":"5", "cog":"6"
+---------------------+
Markdown tabular (supported for output only):
Markdown tabular:
+-----------------------+
| | apple | bat | cog | |
| | --- | --- | --- | |
@ -360,6 +360,7 @@
seqgen verb, which is more useful/intuitive.
--ijson Use JSON format for input data.
--ijsonl Use JSON Lines format for input data.
--imd or --imarkdown Use markdown-tabular format for input data.
--inidx Use NIDX format for input data.
--io {format name} Use format name for input and output data. For
example: `--io csv` is the same as `--csv`.
@ -377,7 +378,7 @@
--odkvp Use DKVP format for output data.
--ojson Use JSON format for output data.
--ojsonl Use JSON Lines format for output data.
--omd Use markdown-tabular format for output data.
--omd or --omarkdown Use markdown-tabular format for output data.
--onidx Use NIDX format for output data.
--opprint Use PPRINT format for output data.
--otsv Use TSV format for output data.
@ -419,19 +420,19 @@
1mFORMAT-CONVERSION KEYSTROKE-SAVER FLAGS0m
As keystroke-savers for format-conversion you may use the following.
The letters c, t, j, l, d, n, x, p, and m refer to formats CSV, TSV, DKVP, NIDX,
JSON, JSON Lines, XTAB, PPRINT, and markdown, respectively. Note that markdown
format is available for output only.
JSON, JSON Lines, XTAB, PPRINT, and markdown, respectively.
| In\out | CSV | TSV | JSON | JSONL | DKVP | NIDX | XTAB | PPRINT | Markdown |
+--------+-------+-------+--------+--------+--------+--------+--------+----------+
| CSV | | --c2t | --c2j | --c2l | --c2d | --c2n | --c2x | --c2p | --c2m |
| TSV | --t2c | | --t2j | --t2l | --t2d | --t2n | --t2x | --t2p | --t2m |
| JSON | --j2c | --j2t | | --j2l | --j2d | --j2n | --j2x | --j2p | --j2m |
| JSONL | --l2c | --l2t | | | --l2d | --l2n | --l2x | --l2p | --l2m |
| DKVP | --d2c | --d2t | --d2j | --d2l | | --d2n | --d2x | --d2p | --d2m |
| NIDX | --n2c | --n2t | --n2j | --n2l | --n2d | | --n2x | --n2p | --n2m |
| XTAB | --x2c | --x2t | --x2j | --x2l | --x2d | --x2n | | --x2p | --x2m |
| PPRINT | --p2c | --p2t | --p2j | --p2l | --p2d | --p2n | --p2x | | --p2m |
| In\out | CSV | TSV | JSON | JSONL | DKVP | NIDX | XTAB | PPRINT | Markdown |
+----------+-------+-------+--------+--------+--------+--------+--------+--------+----------|
| CSV | | --c2t | --c2j | --c2l | --c2d | --c2n | --c2x | --c2p | --c2m |
| TSV | --t2c | | --t2j | --t2l | --t2d | --t2n | --t2x | --t2p | --t2m |
| JSON | --j2c | --j2t | | --j2l | --j2d | --j2n | --j2x | --j2p | --j2m |
| JSONL | --l2c | --l2t | | | --l2d | --l2n | --l2x | --l2p | --l2m |
| DKVP | --d2c | --d2t | --d2j | --d2l | | --d2n | --d2x | --d2p | --d2m |
| NIDX | --n2c | --n2t | --n2j | --n2l | --n2d | | --n2x | --n2p | --n2m |
| XTAB | --x2c | --x2t | --x2j | --x2l | --x2d | --x2n | | --x2p | --x2m |
| PPRINT | --p2c | --p2t | --p2j | --p2l | --p2d | --p2n | --p2x | | --p2m |
| Markdown | --m2c | --m2t | --m2j | --m2l | --m2d | --m2n | --m2x | --m2p | |
-p Keystroke-saver for `--nidx --fs space --repifs`.
-T Keystroke-saver for `--nidx --fs tab`.

View file

@ -157,6 +157,7 @@ are overridden in all cases by setting output format to `format2`.
* `--igen`: Ignore input files and instead generate sequential numeric input using --gen-field-name, --gen-start, --gen-step, and --gen-stop values. See also the seqgen verb, which is more useful/intuitive.
* `--ijson`: Use JSON format for input data.
* `--ijsonl`: Use JSON Lines format for input data.
* `--imd or --imarkdown`: Use markdown-tabular format for input data.
* `--inidx`: Use NIDX format for input data.
* `--io {format name}`: Use format name for input and output data. For example: `--io csv` is the same as `--csv`.
* `--ipprint`: Use PPRINT format for input data.
@ -173,7 +174,7 @@ are overridden in all cases by setting output format to `format2`.
* `--odkvp`: Use DKVP format for output data.
* `--ojson`: Use JSON format for output data.
* `--ojsonl`: Use JSON Lines format for output data.
* `--omd`: Use markdown-tabular format for output data.
* `--omd or --omarkdown`: Use markdown-tabular format for output data.
* `--onidx`: Use NIDX format for output data.
* `--opprint`: Use PPRINT format for output data.
* `--otsv`: Use TSV format for output data.

View file

@ -80,7 +80,7 @@
| 4 5 6 | Record 2: "apple":"4", "bat":"5", "cog":"6"
+---------------------+
Markdown tabular (supported for output only):
Markdown tabular:
+-----------------------+
| | apple | bat | cog | |
| | --- | --- | --- | |
@ -360,6 +360,7 @@
seqgen verb, which is more useful/intuitive.
--ijson Use JSON format for input data.
--ijsonl Use JSON Lines format for input data.
--imd or --imarkdown Use markdown-tabular format for input data.
--inidx Use NIDX format for input data.
--io {format name} Use format name for input and output data. For
example: `--io csv` is the same as `--csv`.
@ -377,7 +378,7 @@
--odkvp Use DKVP format for output data.
--ojson Use JSON format for output data.
--ojsonl Use JSON Lines format for output data.
--omd Use markdown-tabular format for output data.
--omd or --omarkdown Use markdown-tabular format for output data.
--onidx Use NIDX format for output data.
--opprint Use PPRINT format for output data.
--otsv Use TSV format for output data.
@ -419,19 +420,19 @@
1mFORMAT-CONVERSION KEYSTROKE-SAVER FLAGS0m
As keystroke-savers for format-conversion you may use the following.
The letters c, t, j, l, d, n, x, p, and m refer to formats CSV, TSV, DKVP, NIDX,
JSON, JSON Lines, XTAB, PPRINT, and markdown, respectively. Note that markdown
format is available for output only.
JSON, JSON Lines, XTAB, PPRINT, and markdown, respectively.
| In\out | CSV | TSV | JSON | JSONL | DKVP | NIDX | XTAB | PPRINT | Markdown |
+--------+-------+-------+--------+--------+--------+--------+--------+----------+
| CSV | | --c2t | --c2j | --c2l | --c2d | --c2n | --c2x | --c2p | --c2m |
| TSV | --t2c | | --t2j | --t2l | --t2d | --t2n | --t2x | --t2p | --t2m |
| JSON | --j2c | --j2t | | --j2l | --j2d | --j2n | --j2x | --j2p | --j2m |
| JSONL | --l2c | --l2t | | | --l2d | --l2n | --l2x | --l2p | --l2m |
| DKVP | --d2c | --d2t | --d2j | --d2l | | --d2n | --d2x | --d2p | --d2m |
| NIDX | --n2c | --n2t | --n2j | --n2l | --n2d | | --n2x | --n2p | --n2m |
| XTAB | --x2c | --x2t | --x2j | --x2l | --x2d | --x2n | | --x2p | --x2m |
| PPRINT | --p2c | --p2t | --p2j | --p2l | --p2d | --p2n | --p2x | | --p2m |
| In\out | CSV | TSV | JSON | JSONL | DKVP | NIDX | XTAB | PPRINT | Markdown |
+----------+-------+-------+--------+--------+--------+--------+--------+--------+----------|
| CSV | | --c2t | --c2j | --c2l | --c2d | --c2n | --c2x | --c2p | --c2m |
| TSV | --t2c | | --t2j | --t2l | --t2d | --t2n | --t2x | --t2p | --t2m |
| JSON | --j2c | --j2t | | --j2l | --j2d | --j2n | --j2x | --j2p | --j2m |
| JSONL | --l2c | --l2t | | | --l2d | --l2n | --l2x | --l2p | --l2m |
| DKVP | --d2c | --d2t | --d2j | --d2l | | --d2n | --d2x | --d2p | --d2m |
| NIDX | --n2c | --n2t | --n2j | --n2l | --n2d | | --n2x | --n2p | --n2m |
| XTAB | --x2c | --x2t | --x2j | --x2l | --x2d | --x2n | | --x2p | --x2m |
| PPRINT | --p2c | --p2t | --p2j | --p2l | --p2d | --p2n | --p2x | | --p2m |
| Markdown | --m2c | --m2t | --m2j | --m2l | --m2d | --m2n | --m2x | --m2p | |
-p Keystroke-saver for `--nidx --fs space --repifs`.
-T Keystroke-saver for `--nidx --fs tab`.

View file

@ -111,7 +111,7 @@ PPRINT: pretty-printed tabular
| 4 5 6 | Record 2: "apple":"4", "bat":"5", "cog":"6"
+---------------------+
Markdown tabular (supported for output only):
Markdown tabular:
+-----------------------+
| | apple | bat | cog | |
| | --- | --- | --- | |
@ -441,6 +441,7 @@ are overridden in all cases by setting output format to `format2`.
seqgen verb, which is more useful/intuitive.
--ijson Use JSON format for input data.
--ijsonl Use JSON Lines format for input data.
--imd or --imarkdown Use markdown-tabular format for input data.
--inidx Use NIDX format for input data.
--io {format name} Use format name for input and output data. For
example: `--io csv` is the same as `--csv`.
@ -458,7 +459,7 @@ are overridden in all cases by setting output format to `format2`.
--odkvp Use DKVP format for output data.
--ojson Use JSON format for output data.
--ojsonl Use JSON Lines format for output data.
--omd Use markdown-tabular format for output data.
--omd or --omarkdown Use markdown-tabular format for output data.
--onidx Use NIDX format for output data.
--opprint Use PPRINT format for output data.
--otsv Use TSV format for output data.
@ -516,19 +517,19 @@ See the Flatten/unflatten doc page for more information.
.nf
As keystroke-savers for format-conversion you may use the following.
The letters c, t, j, l, d, n, x, p, and m refer to formats CSV, TSV, DKVP, NIDX,
JSON, JSON Lines, XTAB, PPRINT, and markdown, respectively. Note that markdown
format is available for output only.
JSON, JSON Lines, XTAB, PPRINT, and markdown, respectively.
| In\eout | CSV | TSV | JSON | JSONL | DKVP | NIDX | XTAB | PPRINT | Markdown |
+--------+-------+-------+--------+--------+--------+--------+--------+----------+
| CSV | | --c2t | --c2j | --c2l | --c2d | --c2n | --c2x | --c2p | --c2m |
| TSV | --t2c | | --t2j | --t2l | --t2d | --t2n | --t2x | --t2p | --t2m |
| JSON | --j2c | --j2t | | --j2l | --j2d | --j2n | --j2x | --j2p | --j2m |
| JSONL | --l2c | --l2t | | | --l2d | --l2n | --l2x | --l2p | --l2m |
| DKVP | --d2c | --d2t | --d2j | --d2l | | --d2n | --d2x | --d2p | --d2m |
| NIDX | --n2c | --n2t | --n2j | --n2l | --n2d | | --n2x | --n2p | --n2m |
| XTAB | --x2c | --x2t | --x2j | --x2l | --x2d | --x2n | | --x2p | --x2m |
| PPRINT | --p2c | --p2t | --p2j | --p2l | --p2d | --p2n | --p2x | | --p2m |
| In\eout | CSV | TSV | JSON | JSONL | DKVP | NIDX | XTAB | PPRINT | Markdown |
+----------+-------+-------+--------+--------+--------+--------+--------+--------+----------|
| CSV | | --c2t | --c2j | --c2l | --c2d | --c2n | --c2x | --c2p | --c2m |
| TSV | --t2c | | --t2j | --t2l | --t2d | --t2n | --t2x | --t2p | --t2m |
| JSON | --j2c | --j2t | | --j2l | --j2d | --j2n | --j2x | --j2p | --j2m |
| JSONL | --l2c | --l2t | | | --l2d | --l2n | --l2x | --l2p | --l2m |
| DKVP | --d2c | --d2t | --d2j | --d2l | | --d2n | --d2x | --d2p | --d2m |
| NIDX | --n2c | --n2t | --n2j | --n2l | --n2d | | --n2x | --n2p | --n2m |
| XTAB | --x2c | --x2t | --x2j | --x2l | --x2d | --x2n | | --x2p | --x2m |
| PPRINT | --p2c | --p2t | --p2j | --p2l | --p2d | --p2n | --p2x | | --p2m |
| Markdown | --m2c | --m2t | --m2j | --m2l | --m2d | --m2n | --m2x | --m2p | |
-p Keystroke-saver for `--nidx --fs space --repifs`.
-T Keystroke-saver for `--nidx --fs tab`.

View file

@ -762,6 +762,9 @@ var FileFormatFlagSection = FlagSection{
parser: func(args []string, argc int, pargi *int, options *TOptions) {
CheckArgCount(args, *pargi, argc, 2)
options.ReaderOptions.InputFileFormat = args[*pargi+1]
if options.ReaderOptions.InputFileFormat == "md" {
options.ReaderOptions.InputFileFormat = "markdown" // alias
}
*pargi += 2
},
},
@ -823,6 +826,9 @@ var FileFormatFlagSection = FlagSection{
parser: func(args []string, argc int, pargi *int, options *TOptions) {
CheckArgCount(args, *pargi, argc, 2)
options.WriterOptions.OutputFileFormat = args[*pargi+1]
if options.WriterOptions.OutputFileFormat == "md" {
options.WriterOptions.OutputFileFormat = "markdown" // alias
}
*pargi += 2
},
},
@ -896,8 +902,19 @@ var FileFormatFlagSection = FlagSection{
},
{
name: "--omd",
help: "Use markdown-tabular format for output data.",
name: "--imd",
altNames: []string{"--imarkdown"},
help: "Use markdown-tabular format for input data.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.ReaderOptions.InputFileFormat = "markdown"
*pargi += 1
},
},
{
name: "--omd",
altNames: []string{"--omarkdown"},
help: "Use markdown-tabular format for output data.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.WriterOptions.OutputFileFormat = "markdown"
*pargi += 1
@ -1151,19 +1168,19 @@ var FileFormatFlagSection = FlagSection{
func FormatConversionKeystrokeSaverPrintInfo() {
fmt.Println(`As keystroke-savers for format-conversion you may use the following.
The letters c, t, j, l, d, n, x, p, and m refer to formats CSV, TSV, DKVP, NIDX,
JSON, JSON Lines, XTAB, PPRINT, and markdown, respectively. Note that markdown
format is available for output only.
JSON, JSON Lines, XTAB, PPRINT, and markdown, respectively.
| In\out | CSV | TSV | JSON | JSONL | DKVP | NIDX | XTAB | PPRINT | Markdown |
+--------+-------+-------+--------+--------+--------+--------+--------+----------+
| CSV | | --c2t | --c2j | --c2l | --c2d | --c2n | --c2x | --c2p | --c2m |
| TSV | --t2c | | --t2j | --t2l | --t2d | --t2n | --t2x | --t2p | --t2m |
| JSON | --j2c | --j2t | | --j2l | --j2d | --j2n | --j2x | --j2p | --j2m |
| JSONL | --l2c | --l2t | | | --l2d | --l2n | --l2x | --l2p | --l2m |
| DKVP | --d2c | --d2t | --d2j | --d2l | | --d2n | --d2x | --d2p | --d2m |
| NIDX | --n2c | --n2t | --n2j | --n2l | --n2d | | --n2x | --n2p | --n2m |
| XTAB | --x2c | --x2t | --x2j | --x2l | --x2d | --x2n | | --x2p | --x2m |
| PPRINT | --p2c | --p2t | --p2j | --p2l | --p2d | --p2n | --p2x | | --p2m |`)
| In\out | CSV | TSV | JSON | JSONL | DKVP | NIDX | XTAB | PPRINT | Markdown |
+----------+-------+-------+--------+--------+--------+--------+--------+--------+----------|
| CSV | | --c2t | --c2j | --c2l | --c2d | --c2n | --c2x | --c2p | --c2m |
| TSV | --t2c | | --t2j | --t2l | --t2d | --t2n | --t2x | --t2p | --t2m |
| JSON | --j2c | --j2t | | --j2l | --j2d | --j2n | --j2x | --j2p | --j2m |
| JSONL | --l2c | --l2t | | | --l2d | --l2n | --l2x | --l2p | --l2m |
| DKVP | --d2c | --d2t | --d2j | --d2l | | --d2n | --d2x | --d2p | --d2m |
| NIDX | --n2c | --n2t | --n2j | --n2l | --n2d | | --n2x | --n2p | --n2m |
| XTAB | --x2c | --x2t | --x2j | --x2l | --x2d | --x2n | | --x2p | --x2m |
| PPRINT | --p2c | --p2t | --p2j | --p2l | --p2d | --p2n | --p2x | | --p2m |
| Markdown | --m2c | --m2t | --m2j | --m2l | --m2d | --m2n | --m2x | --m2p | |`)
}
func init() { FormatConversionKeystrokeSaverFlagSection.Sort() }
@ -1288,6 +1305,18 @@ var FormatConversionKeystrokeSaverFlagSection = FlagSection{
*pargi += 1
},
},
{
name: "--c2m",
help: "Use CSV for input, markdown-tabular for output.",
// For format-conversion keystroke-savers, a matrix is plenty -- we don't
// need to print a tedious 60-line list.
suppressFlagEnumeration: true,
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.ReaderOptions.InputFileFormat = "csv"
options.WriterOptions.OutputFileFormat = "markdown"
*pargi += 1
},
},
{
name: "--c2b",
help: "Use CSV for input, PPRINT with `--barred` for output.",
@ -1408,6 +1437,18 @@ var FormatConversionKeystrokeSaverFlagSection = FlagSection{
*pargi += 1
},
},
{
name: "--t2m",
help: "Use TSV for input, markdown tabular for output.",
// For format-conversion keystroke-savers, a matrix is plenty -- we don't
// need to print a tedious 60-line list.
suppressFlagEnumeration: true,
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.ReaderOptions.InputFileFormat = "tsv"
options.WriterOptions.OutputFileFormat = "markdown"
*pargi += 1
},
},
{
name: "--t2b",
help: "Use TSV for input, PPRINT with `--barred` for output.",
@ -1527,6 +1568,18 @@ var FormatConversionKeystrokeSaverFlagSection = FlagSection{
*pargi += 1
},
},
{
name: "--d2m",
help: "Use DKVP for input, markdown tabular for output.",
// For format-conversion keystroke-savers, a matrix is plenty -- we don't
// need to print a tedious 60-line list.
suppressFlagEnumeration: true,
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.ReaderOptions.InputFileFormat = "dkvp"
options.WriterOptions.OutputFileFormat = "markdown"
*pargi += 1
},
},
{
name: "--d2b",
help: "Use DKVP for input, PPRINT with `--barred` for output.",
@ -1642,6 +1695,18 @@ var FormatConversionKeystrokeSaverFlagSection = FlagSection{
*pargi += 1
},
},
{
name: "--n2m",
help: "Use NIDX for input, markdown tabular for output.",
// For format-conversion keystroke-savers, a matrix is plenty -- we don't
// need to print a tedious 60-line list.
suppressFlagEnumeration: true,
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.ReaderOptions.InputFileFormat = "nidx"
options.WriterOptions.OutputFileFormat = "markdown"
*pargi += 1
},
},
{
name: "--n2b",
help: "Use NIDX for input, PPRINT with `--barred` for output.",
@ -1756,6 +1821,18 @@ var FormatConversionKeystrokeSaverFlagSection = FlagSection{
*pargi += 1
},
},
{
name: "--j2m",
help: "Use JSON for input, markdown-tabular for output.",
// For format-conversion keystroke-savers, a matrix is plenty -- we don't
// need to print a tedious 60-line list.
suppressFlagEnumeration: true,
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.ReaderOptions.InputFileFormat = "json"
options.WriterOptions.OutputFileFormat = "markdown"
*pargi += 1
},
},
{
name: "--j2b",
help: "Use JSON for input, PPRINT with --barred for output.",
@ -1867,6 +1944,18 @@ var FormatConversionKeystrokeSaverFlagSection = FlagSection{
*pargi += 1
},
},
{
name: "--l2m",
help: "Use JSON Lines for input, markdown-tabular for output.",
// For format-conversion keystroke-savers, a matrix is plenty -- we don't
// need to print a tedious 60-line list.
suppressFlagEnumeration: true,
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.ReaderOptions.InputFileFormat = "json"
options.WriterOptions.OutputFileFormat = "markdown"
*pargi += 1
},
},
{
name: "--l2b",
help: "Use JSON Lines for input, PPRINT with --barred for output.",
@ -2023,6 +2112,115 @@ var FormatConversionKeystrokeSaverFlagSection = FlagSection{
},
},
{
name: "--m2c",
help: "Use markdown-tabular for input, CSV for output.",
// For format-conversion keystroke-savers, a matrix is plenty -- we don't
// need to print a tedious 60-line list.
suppressFlagEnumeration: true,
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.ReaderOptions.InputFileFormat = "markdown"
options.WriterOptions.OutputFileFormat = "csv"
options.ReaderOptions.ifsWasSpecified = true
options.WriterOptions.orsWasSpecified = true
*pargi += 1
},
},
{
name: "--m2t",
help: "Use markdown-tabular for input, TSV for output.",
// For format-conversion keystroke-savers, a matrix is plenty -- we don't
// need to print a tedious 60-line list.
suppressFlagEnumeration: true,
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.ReaderOptions.InputFileFormat = "markdown"
options.WriterOptions.OutputFileFormat = "tsv"
options.ReaderOptions.ifsWasSpecified = true
*pargi += 1
},
},
{
name: "--m2d",
help: "Use markdown-tabular for input, DKVP for output.",
// For format-conversion keystroke-savers, a matrix is plenty -- we don't
// need to print a tedious 60-line list.
suppressFlagEnumeration: true,
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.ReaderOptions.InputFileFormat = "markdown"
options.WriterOptions.OutputFileFormat = "dkvp"
options.ReaderOptions.ifsWasSpecified = true
*pargi += 1
},
},
{
name: "--m2n",
help: "Use markdown-tabular for input, NIDX for output.",
// For format-conversion keystroke-savers, a matrix is plenty -- we don't
// need to print a tedious 60-line list.
suppressFlagEnumeration: true,
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.ReaderOptions.InputFileFormat = "markdown"
options.WriterOptions.OutputFileFormat = "nidx"
options.ReaderOptions.ifsWasSpecified = true
*pargi += 1
},
},
{
name: "--m2j",
help: "Use markdown-tabular for input, JSON for output.",
// For format-conversion keystroke-savers, a matrix is plenty -- we don't
// need to print a tedious 60-line list.
suppressFlagEnumeration: true,
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.ReaderOptions.InputFileFormat = "markdown"
options.WriterOptions.OutputFileFormat = "json"
options.WriterOptions.WrapJSONOutputInOuterList = true
options.WriterOptions.JSONOutputMultiline = true
options.ReaderOptions.ifsWasSpecified = true
*pargi += 1
},
},
{
name: "--m2l",
help: "Use markdown-tabular for input, JSON Lines for output.",
// For format-conversion keystroke-savers, a matrix is plenty -- we don't
// need to print a tedious 60-line list.
suppressFlagEnumeration: true,
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.ReaderOptions.InputFileFormat = "markdown"
options.WriterOptions.OutputFileFormat = "json"
options.WriterOptions.WrapJSONOutputInOuterList = false
options.WriterOptions.JSONOutputMultiline = false
options.ReaderOptions.ifsWasSpecified = true
*pargi += 1
},
},
{
name: "--m2x",
help: "Use markdown-tabular for input, XTAB for output.",
// For format-conversion keystroke-savers, a matrix is plenty -- we don't
// need to print a tedious 60-line list.
suppressFlagEnumeration: true,
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.ReaderOptions.InputFileFormat = "markdown"
options.WriterOptions.OutputFileFormat = "xtab"
options.ReaderOptions.ifsWasSpecified = true
*pargi += 1
},
},
{
name: "--m2p",
help: "Use markdown-tabular for input, PPRINT for output.",
// For format-conversion keystroke-savers, a matrix is plenty -- we don't
// need to print a tedious 60-line list.
suppressFlagEnumeration: true,
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.ReaderOptions.InputFileFormat = "markdown"
options.WriterOptions.OutputFileFormat = "pprint"
*pargi += 1
},
},
{
name: "--x2c",
help: "Use XTAB for input, CSV for output.",
@ -2112,6 +2310,18 @@ var FormatConversionKeystrokeSaverFlagSection = FlagSection{
*pargi += 1
},
},
{
name: "--x2m",
help: "Use XTAB for input, markdown-tabular for output.",
// For format-conversion keystroke-savers, a matrix is plenty -- we don't
// need to print a tedious 60-line list.
suppressFlagEnumeration: true,
parser: func(args []string, argc int, pargi *int, options *TOptions) {
options.ReaderOptions.InputFileFormat = "xtab"
options.WriterOptions.OutputFileFormat = "markdown"
*pargi += 1
},
},
{
name: "--x2b",
help: "Use XTAB for input, PPRINT with `--barred` for output.",

View file

@ -18,6 +18,10 @@ func Create(readerOptions *cli.TReaderOptions, recordsPerBatch int64) (IRecordRe
return NewRecordReaderJSON(readerOptions, recordsPerBatch)
case "nidx":
return NewRecordReaderNIDX(readerOptions, recordsPerBatch)
case "md":
return NewRecordReaderMarkdown(readerOptions, recordsPerBatch)
case "markdown":
return NewRecordReaderMarkdown(readerOptions, recordsPerBatch)
case "pprint":
return NewRecordReaderPPRINT(readerOptions, recordsPerBatch)
case "tsv":

View file

@ -0,0 +1,30 @@
package input
import (
"regexp"
"github.com/johnkerl/miller/pkg/cli"
)
func NewRecordReaderMarkdown(
readerOptions *cli.TReaderOptions,
recordsPerBatch int64,
) (IRecordReader, error) {
readerOptions.IFS = "|"
readerOptions.AllowRepeatIFS = false
reader := &RecordReaderPprintBarredOrMarkdown{
readerOptions: readerOptions,
recordsPerBatch: recordsPerBatch,
separatorMatcher: regexp.MustCompile(`^\|[-\| ]+\|$`),
fieldSplitter: newFieldSplitter(readerOptions),
}
if reader.readerOptions.UseImplicitHeader {
reader.recordBatchGetter = getRecordBatchImplicitPprintHeader
} else {
reader.recordBatchGetter = getRecordBatchExplicitPprintHeader
}
return reader, nil
}

View file

@ -1,23 +1,5 @@
package input
// Multi-file cases:
//
// a,a a,b c d
// -- FILE1: -- FILE1: -- FILE1: -- FILE1:
// a,b,c a,b,c a,b,c a,b,c
// 1,2,3 1,2,3 1,2,3 1,2,3
// 4,5,6 4,5,6 4,5,6 4,5,6
// -- FILE2: -- FILE2:
// a,b,c d,e,f,g a,b,c d,e,f
// 7,8,9 3,4,5,6 7,8,9 3,4,5
// --OUTPUT: --OUTPUT: --OUTPUT: --OUTPUT:
// a,b,c a,b,c a,b,c a,b,c
// 1,2,3 1,2,3 1,2,3 1,2,3
// 4,5,6 4,5,6 4,5,6 4,5,6
// 7,8,9 7,8,9
// d,e,f,g d,e,f
// 3,4,5,6 3,4,5
import (
"container/list"
"fmt"
@ -39,14 +21,13 @@ func NewRecordReaderPPRINT(
if readerOptions.BarredPprintInput {
// Implemented in this file
// XXX TEMP
readerOptions.IFS = "|"
readerOptions.AllowRepeatIFS = false
reader := &RecordReaderPprintBarred{
reader := &RecordReaderPprintBarredOrMarkdown{
readerOptions: readerOptions,
recordsPerBatch: recordsPerBatch,
separatorMatcher: regexp.MustCompile(`^\+[-+]*\+`),
separatorMatcher: regexp.MustCompile(`^\+[-+]*\+$`),
fieldSplitter: newFieldSplitter(readerOptions),
}
if reader.readerOptions.UseImplicitHeader {
@ -76,7 +57,7 @@ func NewRecordReaderPPRINT(
}
}
type RecordReaderPprintBarred struct {
type RecordReaderPprintBarredOrMarkdown struct {
readerOptions *cli.TReaderOptions
recordsPerBatch int64 // distinct from readerOptions.RecordsPerBatch for join/repl
@ -91,7 +72,7 @@ type RecordReaderPprintBarred struct {
// recordBatchGetterPprint points to either an explicit-PPRINT-header or
// implicit-PPRINT-header record-batch getter.
type recordBatchGetterPprint func(
reader *RecordReaderPprintBarred,
reader *RecordReaderPprintBarredOrMarkdown,
linesChannel <-chan *list.List,
filename string,
context *types.Context,
@ -101,7 +82,7 @@ type recordBatchGetterPprint func(
eof bool,
)
func (reader *RecordReaderPprintBarred) Read(
func (reader *RecordReaderPprintBarredOrMarkdown) Read(
filenames []string,
context types.Context,
readerChannel chan<- *list.List, // list of *types.RecordAndContext
@ -154,7 +135,7 @@ func (reader *RecordReaderPprintBarred) Read(
readerChannel <- types.NewEndOfStreamMarkerList(&context)
}
func (reader *RecordReaderPprintBarred) processHandle(
func (reader *RecordReaderPprintBarredOrMarkdown) processHandle(
handle io.Reader,
filename string,
context *types.Context,
@ -183,7 +164,7 @@ func (reader *RecordReaderPprintBarred) processHandle(
}
func getRecordBatchExplicitPprintHeader(
reader *RecordReaderPprintBarred,
reader *RecordReaderPprintBarredOrMarkdown,
linesChannel <-chan *list.List,
filename string,
context *types.Context,
@ -242,6 +223,9 @@ func getRecordBatchExplicitPprintHeader(
// Skip the leading and trailing pipes
paddedFields := reader.fieldSplitter.Split(line)
npad := len(paddedFields)
if npad < 2 {
continue
}
fields := make([]string, npad-2)
for i, _ := range paddedFields {
if i == 0 || i == npad-1 {
@ -318,7 +302,7 @@ func getRecordBatchExplicitPprintHeader(
}
func getRecordBatchImplicitPprintHeader(
reader *RecordReaderPprintBarred,
reader *RecordReaderPprintBarredOrMarkdown,
linesChannel <-chan *list.List,
filename string,
context *types.Context,

View file

@ -16,6 +16,8 @@ func Create(writerOptions *cli.TWriterOptions) (IRecordWriter, error) {
return NewRecordWriterDKVP(writerOptions)
case "json":
return NewRecordWriterJSON(writerOptions)
case "md":
return NewRecordWriterMarkdown(writerOptions)
case "markdown":
return NewRecordWriterMarkdown(writerOptions)
case "nidx":

View file

@ -408,7 +408,7 @@ PPRINT: pretty-printed tabular
| 4 5 6 | Record 2: "apple":"4", "bat":"5", "cog":"6"
+---------------------+
Markdown tabular (supported for output only):
Markdown tabular:
+-----------------------+
| | apple | bat | cog | |
| | --- | --- | --- | |

View file

@ -0,0 +1 @@
mlr --c2p cat test/input/abixy.csv

View file

@ -0,0 +1 @@
mlr --d2p cat test/input/abixy.dkvp

View file

@ -0,0 +1 @@
mlr --j2p cat test/input/abixy.json

View file

@ -0,0 +1,11 @@
a b i x y
pan pan 1 0.34679014 0.72680286
eks pan 2 0.75867996 0.52215111
wye wye 3 0.20460331 0.33831853
eks wye 4 0.38139939 0.13418874
wye pan 5 0.57328892 0.86362447
zee pan 6 0.52712616 0.49322129
eks zee 7 0.61178406 0.18788492
zee wye 8 0.59855401 0.97618139
hat wye 9 0.03144188 0.74955076
pan wye 10 0.50262601 0.95261836

View file

@ -0,0 +1 @@
mlr --l2m cat test/input/abixy.json

View file

@ -0,0 +1 @@
mlr --m2c cat test/input/abixy.md

Some files were not shown because too many files have changed in this diff Show more