App-mdee
view release on metacpan or search on metacpan
flowchart LR
A[Input File] --> B[greple -Mmd]
B --> G{style?}
G -->|nup| H[nup]
G -->|pager| J[pager]
G -->|cat/filter/raw| I[stdout]
H --> I
J --> I
subgraph "Syntax Highlighting + Table Formatting + Text Folding"
B
end
subgraph "Output"
H
J
end
```
Each stage is controlled by `--style` and individual `--[no-]fold`, `--[no-]table`, `--[no-]trim`, `--[no-]rule`, `--[no-]nup` options. Fold and table processing are handled within the greple `-Mmd` module (not as separate pipeline stages).
### Style System
The `--style` (`-s`) option controls which pipeline stages are active:
| Style | fold | table | rule | nup | pager | Use case |
|-------|------|-------|------|-----|-------|----------|
| `nup` (default) | on | on | on | on | - | Multi-column paged output |
| `pager` | on | on | on | - | on | Single-column with pager |
| `cat` | on | on | on | - | - | Output to stdout |
| `filter` | - | on | on | - | - | Piping / stdin |
| `raw` | - | - | - | - | - | Highlight only |
Shortcuts: `-f` = `--style=filter`, `-p` = `--style=pager`
```bash
mdee -s pager file.md # fold + table, output to pager
mdee -f file.md # table only (filter mode)
mdee -p file.md # fold + table + pager
mdee -f --fold file.md # filter + fold override
```
#### Implementation
Style defaults are applied after option parsing using a sentinel value:
```bash
[ style | s : # output style ]=nup
[ filter | f ! # filter mode ]=
[ plain | p ! # plain mode ]=
[ fold | # line folding ]=_
[ table | # table formatting ]=_
[ trim | # trim table cell spaces]=1
[ nup | # use nup ]=_
[ rule | # table rule lines ]=_
```
- `fold`/`table`/`nup`/`rule` default to sentinel `_` (not user-set)
- `trim` defaults to `1` (always on unless explicitly `--no-trim`), not style-dependent
- After getoptlong.sh, style defaults are applied only to sentinel values
- Explicit `--fold`/`--no-fold` sets the value to `1`/empty, overriding style
- `filter()` and `plain()` callbacks set `$style` during option parsing
- The `!` marker triggers the callback when option is parsed
```bash
filter() { style=filter; }
plain() { [[ $plain ]] && style=pager || style=nup; }
# After getoptlong.sh:
case $style in
nup) style_defaults=([fold]=1 [table]=1 [nup]=1 [rule]=1) ;;
pager) style_defaults=([fold]=1 [table]=1 [nup]= [rule]=1) ;;
...
esac
[[ $fold == _ ]] && fold=${style_defaults[fold]}
[[ $table == _ ]] && table=${style_defaults[table]}
[[ $nup == _ ]] && nup=${style_defaults[nup]}
[[ $rule == _ ]] && rule=${style_defaults[rule]}
[[ ${rule:-} ]] && rule='â'
```
#### Pager Stage
When `style=pager`, the `run_pager` function is appended to the pipeline:
```bash
run_pager() { invoke ${PAGER:-less}; }
# Set defaults for less environment
export LESS="${LESS:--R}"
export LESSANSIENDCHARS="${LESSANSIENDCHARS:-mK}"
# Added to stages when style=pager:
[[ $style == pager ]] && stages+=(run_pager)
```
- `LESS=-R`: Required for ANSI color sequences (set when `LESS` is not defined)
- `LESSANSIENDCHARS=mK`: Recognize SGR (`m`) and erase line (`K`) sequences (set when not defined)
- These affect both direct pager mode and `nup` (which invokes `less` internally)
- User's existing environment settings are not overridden
#### Command Invocation Wrapper
All `run_XXX` functions use `invoke` to execute commands. When `debug > 1` (`-dd`), it prints the full command with quoted arguments to stderr. In dryrun mode, `invoke` skips execution:
```bash
invoke() {
(( debug > 1 )) && echo "debug: $(printf '%q ' "$@")" >&2
[[ ${dryrun:-} ]] && return
"$@"
}
```
Debug levels:
- `-d` (`debug > 0`): `theme_light[]`/`theme_dark[]` values (sourceable format), pipeline stage names
- `-dd` (`debug > 1`): above + full command lines for each pipeline stage
Dryrun combinations:
- `-dn`: show pipeline as function names (e.g., `run_greple "$@" | run_nup`)
- `-ddn`: show expanded command lines for each stage without executing
### App::Greple::md Module
( run in 0.919 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )