[formatter] implement slice operator as format specifier

this allows using a slice operator alongside other (special) format
specifiers like J, to first join list elements to a string and then
trimming that with a slice.

{tags:J, /[:50]}
This commit is contained in:
Mike Fährmann
2022-06-25 16:45:34 +02:00
parent 241e82e18d
commit 54525d2e21
3 changed files with 48 additions and 7 deletions

View File

@@ -139,6 +139,12 @@ Format specifiers can be used for advanced formatting by using the options provi
<td><code>{empty:?[/]/}</code></td>
<td><code></code></td>
</tr>
<tr>
<td><code>[&lt;start&gt;:&lt;stop&gt;]</code></td>
<td>Applies a <a href="https://python-reference.readthedocs.io/en/latest/docs/brackets/slicing.html">Slicing</a> operation to the current value, similar to <a href="#field-names">Field Names</a></td>
<td><code>{foo:[1:-1]}</code></td>
<td><code>oo&nbsp;Ba</code></td>
</tr>
<tr>
<td rowspan="2"><code>L&lt;maxlen&gt;/&lt;repl&gt;/</code></td>
<td rowspan="2">Replaces the entire output with <code>&lt;repl&gt;</code> if its length exceeds <code>&lt;maxlen&gt;</code></td>