blib/lib/App/mdee.pm

filter: Statementstmt 100% 2 / 2 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 100% 2 / 2 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« blib/lib/App/Greple/md/widen.pm ↑ Summary
1 package App::mdee;
2  
3 # DO NOT EDIT this file manually.
4 # POD documentation is appended from script/mdee at release time.
5 # See minil.toml for details.
6  
7 1 our $VERSION = "1.33";
8  
9 1 1;
10 =encoding utf-8
11  
12 =head1 NAME
13  
14 mdee - em·dee, Markdown Easy on the Eyes
15  
16 =head1 SYNOPSIS
17  
18 mdee [ options ] file ...
19  
20 -h --help show help
21 --version show version
22 -d --debug debug level (repeatable)
23 -x --[no-]trace trace mode (set -x)
24 -n --dryrun dry-run mode
25 -s --style=# output style (nup/pager/cat/filter/raw)
26 -f --filter shortcut for --style=filter
27 -p --plain shortcut for --style=pager
28 --[no-]fold line folding (default: on)
29 --[no-]refill join paragraph lines (default: off)
30 -r reverse the default of --refill
31 --[no-]table table formatting (default: on)
32 --[no-]trim trim cell spaces (default: on)
33 --[no-]nup nup paged output (default: on)
34 -V --parallel show files side by side
35 -L --[no-]lateral all pages in one row, scrolled sideways
36 --[no-]rule use Unicode rules for tables (default: on)
37 --ts --table-style=# table style: lattice, 3line or simple (default: lattice)
38 --keep TYPE=WHAT kept in one pane: table=none|row|head|all (default: table=head)
39 --cat-v visualize whitespace via cat-v
40 --[no-]image[=#] image types to show (default: png,jpeg,gif,mermaid)
41 -w --width=# output width (default: terminal width)
42 --fold-width=# fold width (default: pane width - 3 - run-in)
43 --runin=# run-in width for line breaking (default: 4)
44 --runout=# run-out width for line breaking (default: 4)
45 --runlen=# set both run-in and run-out
46 --boundary=# fold boundary: word, space or none (default: word)
47 -t --theme=#[,#,...] color theme(s) (default: hashed,nomark,markcell,doubleline)
48 -m --mode=# light or dark (default: light)
49 -B --base-color=# override base color of theme
50 (e.g., Ivory, #780043, (120,0,67))
51 --config=KEY=VALUE set config parameter (e.g., h1=RD, FILE=...)
52 --cm --colormap=L=SPEC override color for element (e.g., h1=RD)
53 --hm --heading-markup=# enable markup in headings (all/bold/...)
54 --show=# set field visibility (e.g., italic=1)
55 -C --pane=#[,#] number of columns, and rows
56 -R --row=# number of rows
57 -G --grid=# grid layout (e.g., 2x3)
58 -P --page=# page height in lines
59 -S --pane-width=# pane width (default: 85)
60 --bs --border-style=# border style
61 --[no-]page-number page number on border (default: on)
62 --[no-]filename file name label (default: on)
63 --[no-]pager[=#] pager command
64 -T --device=# output device: tty, pdf, or a paper for PDF
65 (e.g., a4, a4p, a3l)
66 -o --output=FILE output file (PDF when it ends with .pdf)
67  
68 =head1 VERSION
69  
70 Version 1.33
71  
72 =cut
73 =head1 DESCRIPTION
74  
75 B<em·dee> (command: C<mdee>) is a terminal-based multi-column
76 Markdown text viewer with syntax highlighting, particularly
77 useful for reading documents generated by LLMs.
78  
79 =begin html
80  
81 <p><img width="1000" src="https://raw.githubusercontent.com/tecolicom/App-mdee/main/images/3-column.png">
82  
83 =end html
84  
85 It presents Markdown content in a clean, readable form: syntax
86 highlighting distinguishes document structure, line folding wraps
87 long list items, and tables are aligned with proper column
88 formatting. By default, markup characters (C<**>, C<`>,
89 C<[>...C<]>, etc.) are hidden so that the text reads naturally,
90 while color and styling preserve the structural information.
91 Closing hashes are appended to h3-h6 headers to make heading
92 levels visually distinct. On terminals supporting OSC 8, links
93 remain clickable.
94  
95 Use C<--no-theme> to display the original Markdown source with
96 markup characters intact.
97  
98 mdee is a previewer for the author of a document, not a renderer for
99 its readers. The text is shown as it is written, and read as the
100 renderers read it, so that what they will not show as intended is
101 seen before it is published: emphasis follows the rules of
102 CommonMark, the paragraphs of B<--refill> are those of a Markdown
103 parser, and an image whose file is not found is marked. Images and
104 Mermaid diagrams are shown below their lines, which stay as written.
105  
106 The same view is printed to PDF with C<-o file.pdf>. See
107 L</Printing to PDF>.
108  
109 =head2 Concept
110  
111 B<em·dee> began as a viewer for Markdown I<text>, not as a Markdown
112 renderer. The idea was to show a C<.md> file as it is written, line
113 for line, only made easier on the eyes with color: the Markdown is
114 not interpreted or reformatted. Some formatting has been added since
115 because it made the text more readable: tables are aligned, long
116 list items are folded, the default themes hide markup characters,
117 and closing hashes are appended to lower-level headings. With
118 C<--refill>, the lines that a Markdown parser has found to be
119 one paragraph are joined as well. Everything else is still the
120 source text. This is why backslash escapes such as C<\*> are shown
121 as written, and why C<--no-theme> gives back the original file, in
122 color.
123  
124 For full Markdown rendering, many other viewers are available, such
125 as C<glow> and C<mdcat>. Combine them with L<nup(1)|App::nup> for
126 similar paged output (e.g., C<nup glow README.md>, C<nup mdcat README.md>).
127  
128 The pipeline combines L<greple(1)|App::Greple> for colorization and
129 L<nup(1)|App::nup> for multi-column paged output.
130  
131 The following elements are highlighted. Elements marked with
132 C<--show> can be individually disabled via the C<--show> option.
133 Others are always processed for structural integrity.
134  
135 --show bold (**bold**, __bold__)
136 --show italic (*italic*, _italic_)
137 --show strike (~~strike~~)
138 --show code_inline (`code`)
139 --show header, h1-h6 (# heading)
140 --show horizontal_rule (---, ***, ___)
141 --show blockquote (> quote)
142 always code_mark (``` or ~~~)
143 code_block
144 code_info
145 always meta_mark (--- or +++ at the top)
146 meta_block
147 always comment (<!-- ... -->)
148 always link ([text](url))
149 image (![text])
150 image_link (![text](url))
151 image_missing (an image whose file is not found)
152 message (a message from a command, below its part)
153  
154 Tables and list item folding are controlled by C<--table> and
155 C<--fold> options, not by C<--show>.
156  
157 The code in a fenced code block is shown in the colors of its
158 language (C<```perl>), when L<Text::ANSI::Highlight> and the command
159 of its highlighter, C<pandoc> by default, are installed.
160 C<--config highlight=gnu> uses C<source-highlight>, and
161 C<--config highlight=0> turns it off. See
162 L<App::Greple::md/"Syntax Highlight of Code">.
163  
164 =head2 Multi-column Layout and Pagination
165  
166 By default, B<mdee> calculates the number of display columns by
167 dividing the output width (the terminal width unless C<--width>
168 is given) by the pane width (default 85 characters). This determines how the output is laid out and
169 paginated.
170  
171 When two or more columns fit, L<nup(1)|App::nup> arranges output
172 in multi-column layout with page-by-page pagination — content is
173 split into terminal-height pages viewed through a pager.
174  
175 When only one column fits, B<mdee> still uses nup for formatting
176 (borders, document layout) but disables page-by-page splitting,
177 so the content scrolls continuously in the pager. This avoids
178 wasted space from page breaks on narrow terminals while
179 maintaining the same visual appearance.
180  
181 To force page-by-page pagination even in single-column layout,
182 specify C<--nup> explicitly. The C<--pane-width> (C<-S>) option
183 adjusts the column width used for this calculation, and
184 C<--pane> (C<-C>) sets the number of columns directly. The
185 C<--width> (C<-w>) option replaces the terminal width in this
186 calculation and limits the output to that width.
187  
188 With two or more files, C<--parallel> shows the files side by side,
189 one pane per file, instead of one after another. Each file is
190 folded to its pane width, and the panes scroll together in the
191 pager. The screen shows as many files as fit, as many as the pages
192 of a single file, and the files that do not fit in one row continue
193 on the next, or on the right with C<--lateral>; C<--pane> (C<-C>)
194 sets the number of panes.
195  
196 Use C<-p> (C<--style=pager>) for a simpler view without nup
197 formatting — highlighted output is piped directly through a
198 pager. Use C<-f> (C<--style=filter>) to write highlighted
199 output to stdout without a pager, suitable for piping into
200 other commands.
201  
202 =head2 Printing to PDF
203  
204 B<mdee> prints the document to PDF when the output file ends with
205 C<.pdf>, or when a paper is given as the device with C<-T>.
206  
207 mdee -o README.pdf README.md # A4 in landscape
208 mdee -T a4p -o README.pdf README.md # A4 in portrait
209 mdee -T a3 README.md > README.pdf # A3, to the standard output
210  
211 The paper takes the place of the terminal. The number of columns is
212 the width of the paper in characters divided by the pane width, and
213 the text is folded for it, in the same way as on the terminal: A4 in
214 landscape is 206 characters wide and has two panes, and A4 in
215 portrait is 100 characters wide and has one. C<-C> and C<-S> work
216 as on the terminal. The mode is C<light> unless C<--mode> is given,
217 because the paper is white.
218  
219 A paper is given by its name, with the letter C<p> or C<l> for
220 portrait or landscape, and the margin in millimeters after C<:m>.
221 The default is landscape with a margin of 5 mm.
222  
223 mdee -T a4p:m10 -o README.pdf README.md
224  
225 A sheet has 60 lines. The rows of C<-C> divide the sheet, and the
226 size of the characters is kept: C<-C2,2> gives four pages of 30
227 lines on a sheet. C<-P> sets the lines of a page instead, and the
228 characters become smaller or larger to put the pages on the sheet:
229 C<-C2,2 -P60> prints four pages of 60 lines on a sheet in half the
230 size, as a printer does for 4-up.
231  
232 mdee -C2,2 -o README.pdf README.md
233 mdee -C2,2 -P60 -o README.pdf README.md
234  
235 L<nup(1)|App::nup> and
236 L<ansi2pdf(1)|https://github.com/tecolicom/App-ansi2pdf> make the
237 PDF, so C<ansi2pdf> has to be installed, and the output style has to
238 be C<nup>, which is the default. See C<-T> and C<-o> in
239 L</Output Options>.
240  
241 =head1 INSTALLATION
242  
243 =head2 Homebrew
244  
245 Use L<tecolicom/tap|https://github.com/tecolicom/homebrew-tap>:
246  
247 brew tap tecolicom/tap
248 brew install app-mdee
249  
250 =head2 CPAN
251  
252 cpanm -n App::mdee
253  
254 =head1 OPTIONS
255  
256 =head2 General Options
257  
258 =over 4
259  
260 =item B<-h>, B<--help>
261  
262 Show help message.
263  
264 =item B<--version>
265  
266 Show version.
267  
268 =item B<-d>, B<--debug>
269  
270 Set debug level. Can be repeated for increasing verbosity.
271  
272 =over 4
273  
274 =item C<-d>
275  
276 Show theme values (C<theme_light[]>/C<theme_dark[]>, C<md_config[]>)
277 and pipeline stage names.
278  
279 =item C<-dd>
280  
281 Above, plus full command lines for each pipeline stage.
282  
283 =back
284  
285 =item B<-x>, B<--trace>, B<--no-trace>
286  
287 Enable or disable shell trace mode (C<set -x>). Useful for
288 debugging script execution. Can be toggled: C<-x --no-x> enables
289 then disables tracing.
290  
291 =item B<-n>, B<--dryrun>
292  
293 Dry-run mode. Print the commands that would be run, one pipeline
294 stage per line joined with C<|>, without running them. Arguments
295 are quoted so that the output can be pasted into a shell. The
296 environment that B<mdee> sets (C<LESS>, C<LESSANSIENDCHARS>) is not
297 shown. With C<-d>, the stage names are printed to stderr as well.
298  
299 =back
300  
301 =head2 Processing Options
302  
303 =over 4
304  
305 =item B<-s> I<STYLE>, B<--style>=I<STYLE>
306  
307 Set the output style. Default is C<nup>. Available styles:
308  
309 =over 4
310  
311 =item C<nup> - Full pipeline: fold + table + nup paged output (default)
312  
313 =item C<pager> - Fold + table, output to pager (C<$PAGER> or C<less>)
314  
315 =item C<cat> - Fold + table, output to stdout
316  
317 =item C<filter> - Table only (no fold, no nup), suitable for piping
318  
319 =item C<raw> - Highlight only (no fold, no table, no nup)
320  
321 =back
322  
323 The style sets the initial state of C<--fold>, C<--table>, and
324 C<--nup> options. Subsequent options can override individual
325 settings:
326  
327 mdee -s filter --fold file.md # filter + fold
328 mdee -p --no-fold file.md # pager without fold
329  
330 =item B<-f>, B<--filter>
331  
332 Shortcut for C<--style=filter>. Reads from stdin (or files) and
333 outputs highlighted Markdown to stdout. Disables line folding and
334 nup paged output, but keeps table formatting enabled. Useful for
335 piping Markdown content through mdee for syntax highlighting.
336  
337 =item B<-p>, B<--plain>
338  
339 Shortcut for C<--style=pager>. Enables fold and table formatting,
340 outputs through a pager (C<$PAGER> or C<less>) instead of nup.
341  
342 =item B<--[no-]fold>
343  
344 Enable or disable line folding for list items, definition lists,
345 block quotes and, with C<--refill>, paragraphs. When enabled, long
346 lines are wrapped with proper indentation using
347 L<ansifold(1)|App::ansifold>: the continuation lines of a list item
348 are indented under its text, those of a block quote start with the
349 quote marker again. Default is enabled.
350  
351 Supported list markers: C<*>, C<+>, C<->, C<1.>, C<1)>, C<#.>, C<#)>.
352 The C<#.> and C<#)> forms are the auto-numbered lists of Pandoc's
353 Markdown.
354  
355 =item B<--[no-]refill>
356  
357 Join the lines of each paragraph into one line. Default is disabled;
358 C<default[refill]=1> in the configuration file enables it.
359  
360 =item B<-r>
361  
362 Reverse the default of B<--refill>: enable it when the default is
363 disabled, and disable it when C<default[refill]=1> enables it, as for
364 a file which is not Markdown. Each B<-r> reverses it again, so
365 B<-rr> gives the default back. B<--[no-]refill> given on the command
366 line takes effect over it.
367  
368 What a paragraph is, a Markdown parser decides: a run of lines at the
369 top level, in a block quote, in a list item or in a definition body.
370 Those lines are joined in the original text. Headings, tables, code
371 blocks, front matter and everything else stay as written. A hard
372 line break (two or more spaces or a backslash at the end of a line)
373 is kept.
374  
375 Lines are joined with one space, or with nothing after a fullwidth
376 punctuation character and between two characters of a script that is
377 written without spaces, as L<ansifold(1)|App::ansifold> does. When
378 fold is enabled, the joined paragraphs are folded to the fold width
379 like list items; otherwise each is one long line.
380  
381 The parser is L<Markdown::Perl>, which is installed with B<mdee>, or
382 the L<CommonMark> module (an interface to libcmark) when it is there,
383 which is faster. C<--config refill_parser=pandoc> uses pandoc 2.11.3
384 or later instead.
385  
386 Front matter at the top of the file, TOML between C<+++> lines or
387 YAML between C<---> lines (or ended by C<...>), is left as it is
388 and shown as a code block; C<--config front_matter=0> takes its lines
389 as Markdown.
390  
391 =item B<--[no-]table>
392  
393 Enable or disable table formatting. When enabled, Markdown tables
394 are formatted using L<ansicolumn(1)|App::ansicolumn> for aligned column display.
395 Column alignment specified in the separator line (C<:---> for left,
396 C<:---:> for center, C<---:> for right) is respected.
397 A C<< <br> >> (or C<< <br/> >>, C<< <br /> >>) in a cell breaks the
398 cell into lines after it; one in a code span, or escaped as
399 C<< \<br> >>, does not. The default theme C<nomark> hides the
400 C<< <br> >>, and C<--no-theme> shows it.
401 Default is enabled.
402  
403 When folding is enabled, a table wider than the table width is fit
404 into that width. The table width is the fold width; with nup, when
405 the fold width is not given, it is the fold width plus the run-in
406 width but one (81 for a pane of 85), because the lines of a table are
407 sent to nup to be kept intact, not folded (see C<--intact> of
408 L<ansicolumn(1)|App::ansicolumn>); C<--cat-v> does not do it, and
409 the table width is the fold width there. Columns that fit keep
410 their width, and the cells of over-wide columns are wrapped. A cell
411 has no space at its right, so the text of the last column goes up to
412 the end of the width (see C<table_gap> in C<--table-style>). Use C<--config
413 table_width=0> to disable wrapping, or C<--config table_width=N> to
414 use a different width. Per-column
415 widths can be given with C<--config table_cell=SPEC>, where SPEC
416 is a colon-separated list passed to ansicolumn's C<--cell> option
417 (for example C<0:10> fixes the second column at 10 columns, and
418 C<< '<30' >> caps every column at 30). Marks can be put at the
419 start of cell lines, in place of the cell's leading space so that
420 column widths do not change. C<--config table_cell_mark=STRING>
421 marks the first line of every body cell in a column that has a
422 wrapped cell; the header row and columns that fit are left alone.
423 The default theme C<markcell> sets it to C<‣> (U+2023).
424 C<--config table_wrap_mark=STRING> marks the second and later
425 lines of a wrapped cell, so that they are not read as new rows;
426 the theme C<markwrap> sets it to C<›> (U+203A). Without these
427 themes no mark is used.
428  
429 =item B<--[no-]trim>
430  
431 Trim whitespace from table cell content before formatting.
432 This is useful when the source table is pre-formatted with
433 aligned spacing, which would otherwise prevent column alignment
434 directives from working correctly. Default is enabled.
435  
436 =item B<--[no-]nup>
437  
438 Enable or disable L<nup(1)|App::nup> for multi-column paged output.
439 When disabled, output goes directly to stdout without formatting.
440 Default is enabled. When explicitly specified, forces nup's
441 native pagination even in single-column layout (which normally
442 uses the pager instead).
443  
444 =item B<--[no-]rule>
445  
446 Enable or disable Unicode rule characters for table borders.
447 When enabled, ASCII pipe characters (C<|>) are replaced with
448 Unicode box-drawing characters (C<│>, C<├>, C<┤>, C<┼>) and
449 dashes (C<->) in separator lines are replaced with horizontal
450 rules (C<─>). Default is enabled.
451  
452 =item B<--table-style>=I<STYLE>, B<--ts> I<STYLE>
453  
454 Select how tables are drawn. C<lattice> (default) keeps a separator
455 between the columns, C<│> or C<|> depending on C<--rule>. C<pipe> is
456 another name of it, kept for compatibility:
457  
458 Left│ Center│ Right│ Default
459 ─────┼───────┼──────┼────────
460 a │ b │ c│ d
461  
462 C<3line> separates the columns by spaces only and draws three rules: a
463 rule the width of the table above and below it, and a rule per column
464 below the header.
465  
466 ─────────────────────────────
467 Left Center Right Default
468 ───── ─────── ────── ────────
469 a b c d
470 ─────────────────────────────
471  
472 C<simple> also separates the columns by spaces only, and draws the
473 rule per column below the header and below the table.
474  
475 Left Center Right Default
476 ───── ─────── ────── ────────
477 a b c d
478 ───── ─────── ────── ────────
479  
480 The rules are drawn with C<-> with C<--no-rule>.
481  
482 In every style a cell has a space at its left, where the marks of
483 C<--table-wrap-mark> and C<--table-cell-mark> are put, and no space at
484 its right. C<--config table_gap=N> sets the number of columns between
485 the text of a cell and that place of the next column (default 1): the
486 last of them is the column separator, and the others are spaces at the
487 right of the cell. With C<table_gap=2> a cell of C<lattice> has a
488 space on both sides; the spaces at the right end of the table are then
489 left out when the table does not fit the width with them.
490  
491 =item B<--keep> I<TYPE>=I<WHAT>[,...]
492  
493 Tell what of a block of the I<TYPE> is kept in one pane of nup, so
494 that a pane does not end inside it. The block goes to the next pane
495 when that part does not fit in the rest of the pane. The option can
496 be repeated, and the settings can be joined by commas:
497 C<--keep table=all>. C<table> is the only I<TYPE> for now, with
498 these values of I<WHAT> (default: C<head>):
499  
500 =over 4
501  
502 =item C<none>
503  
504 Nothing: a pane may end between any two lines of a table.
505  
506 =item C<row>
507  
508 The lines of a row, which has more than one line when a cell is
509 wrapped.
510  
511 =item C<head>
512  
513 Also the header, the rule below it and the first row, and with
514 C<3line> and C<simple>, the last row and the rule below it.
515  
516 =item C<all>
517  
518 The whole table. A table longer than a pane is laid out as lines,
519 and may be divided anywhere.
520  
521 =back
522  
523 This has an effect only when tables are kept intact: with nup, when
524 folding and table formatting are on, and without C<--cat-v>.
525 C<default[keep]> in the configuration file gives the settings of the
526 types not given on the command line: C<default[keep]=table=all>.
527  
528 =item B<--cat-v>
529  
530 Pass the output through L<cat-v(1)|App::cat::v> to visualize
531 whitespace and special characters. Spaces are shown as C<·>
532 and other invisible characters are made visible. Newline
533 visualization is disabled by default.
534  
535 =item B<-->[B<no->]B<image>[=I<TYPES>]
536  
537 Show images in the terminal (default: on). I<TYPES> is a list of
538 the types of images to show, separated by commas: C<png>, C<jpeg>,
539 C<gif> and C<mermaid> (default: all of them); C<mermaid> draws the
540 Mermaid diagrams (see L</Mermaid Diagrams>). B<--image=png> shows
541 PNG only, and B<--no-image> none. They are shown only in the terminals that
542 support them; see L</IMAGES>.
543  
544 =item B<-w> I<N>, B<--width>=I<N>
545  
546 Set the output width in characters. Default is the terminal
547 width. With nup, this width is used in place of the terminal
548 width to calculate the number of columns, and it is passed to
549 L<ansicolumn(1)|App::ansicolumn> so that the panes fit into it:
550  
551 mdee -w 170 file.md # two 85-column panes on a wide terminal
552 mdee -V -w 170 a.md b.md # two files in 85 columns each
553  
554 Without nup (C<--style=cat>, C<pager>, C<filter>, or C<--no-nup>),
555 the text itself is the output, so this is the fold width.
556  
557 =item B<--fold-width>=I<N>
558  
559 Set the fold width for text wrapping directly. Default is the
560 pane width (output width divided by the number of columns) minus
561 3 for borders and padding and the run-in width (see C<--runin>),
562 which gives 78 when pane-width is 85.
563 Only effective when C<--fold> is enabled. Tables are fit into the
564 same width when it is given; otherwise, with nup, into this width
565 plus the run-in width but one (see C<--table>).
566  
567 =item B<--runin>=I<N>, B<--runout>=I<N>, B<--runlen>=I<N>
568  
569 Set the run-in and run-out widths that L<ansicolumn(1)|App::ansicolumn>
570 uses for line breaking (kinsoku) when nup folds the panes.
571 C<--runlen> sets both; options given later override earlier ones.
572 Default is 4. A run-in character may go past the fold width, so
573 ansicolumn keeps the run-in width free at the end of the pane, and
574 the default fold width is made narrower by the same amount. These
575 values are given to nup, and they take precedence over the values
576 in F<~/.ansicolumnrc>. The same values are given to the md module
577 as C<fold_runin> and C<fold_runout>, so that the lines it folds run
578 in by the width kept free, not more.
579  
580 =item B<--boundary>=C<word>|C<space>|C<none>
581  
582 Set where L<ansicolumn(1)|App::ansicolumn> may break a line when nup
583 folds the panes, as its C<--boundary> option: C<word> (default) does
584 not break inside an alphanumeric word, C<space> not inside a sequence
585 of non-space characters, and C<none> breaks anywhere. Lists, tables
586 and the paragraphs joined by C<--refill> are folded by the md module
587 at word boundaries, and this option keeps the other paragraphs, which
588 are folded by nup, in step with them. The value is given to nup,
589 which gives it to ansicolumn after F<~/.ansicolumnrc>, so it takes
590 precedence over the value there.
591  
592 =back
593  
594 =head2 Theme Options
595  
596 B<em·dee> supports color themes for customizing syntax highlighting.
597 Themes define colors for various Markdown elements (headers, code blocks,
598 bold text, etc.).
599  
600 =over 4
601  
602 =item B<-t> I<NAME>, B<--theme>=I<NAME>[,I<NAME>,...]
603  
604 Select color themes. The default is C<hashed,nomark,markcell,doubleline>,
605 which appends closing hashes to h3-h6 headers, hides markup
606 characters for a clean reading experience, marks the rows of
607 tables whose cells are wrapped, and gives h4 a double underline.
608  
609 Themes specified with C<--theme> are added to the default, not
610 replacing it (C<default[theme]> in the configuration file replaces
611 it). Multiple themes can be specified as comma-separated names or
612 by repeating the option. Each theme is applied in order as a
613 transformation, and when two themes set the same value the later
614 one wins:
615  
616 mdee --theme=warm file.md # the default themes + warm
617 mdee --no-theme --theme=warm # warm only (clear default first)
618 mdee --no-theme file.md # no theme (show all markup)
619  
620 Use C<--no-theme> to clear the default theme. It can be combined
621 with C<--theme> to start fresh.
622  
623 See L</THEMES> for the themes that come with B<mdee> and how to
624 write one.
625  
626 Use C<-d> to dump current theme values in sourceable format.
627  
628 =item B<-m> I<MODE>, B<--mode>=I<MODE>
629  
630 Select light or dark mode. Default is C<light>.
631  
632 If the terminal supports background color detection (via
633 L<Getopt::EX::termcolor>), the mode is automatically selected based on
634 terminal luminance.
635 When the environment variable C<TERM_LUMINANCE> is set (0 to 100, as
636 L<Getopt::EX::termcolor> uses it), its value is taken instead and the
637 terminal is not asked; below 50 is dark.
638  
639 Each theme has light and dark variants optimized for different terminal
640 backgrounds. The built-in C<default> theme uses RoyalBlue as the base
641 color with automatic luminance adjustment:
642  
643 =over 4
644  
645 =item C<light> - RoyalBlue with luminance 25 (dark text for light backgrounds)
646  
647 =item C<dark> - RoyalBlue with luminance 80 (bright text for dark backgrounds)
648  
649 =back
650  
651 =item B<-B> I<COLOR>, B<--base-color>=I<COLOR>
652  
653 Override the theme's base color. The base color determines the overall
654 color scheme because all heading colors (h1, h2, h3, etc.) are derived
655 from it by adjusting luminance. For example, h2 might be C<${base}+y20>
656 (base color with luminance increased by 20).
657  
658 B<Simple color name> - luminance is adjusted automatically:
659  
660 When you specify just a color name (without C<E<lt>E<gt>> brackets or
661 other syntax), the default luminance adjustment is applied based on
662 the current mode:
663  
664 -B RoyalBlue # becomes <RoyalBlue>=y25 in light mode
665 # becomes <RoyalBlue>=y80 in dark mode
666  
667 This makes it easy to try different colors without worrying about
668 luminance values. The default adjustments (C<=y25> for light, C<=y80>
669 for dark) are designed to provide good contrast against typical terminal
670 backgrounds.
671  
672 B<Full color specification> - used exactly as specified:
673  
674 If you include C<E<lt>E<gt>> brackets, luminance modifiers, or use RGB
675 notation, the value is used as-is without any automatic adjustment:
676  
677 -B '<Ivory>' # original color, no adjustment
678 -B '<Ivory>=y50' # explicit luminance 50
679 -B '#780043' # burgundy in hex
680 -B '(120,0,67)' # same color in RGB decimal
681  
682 B<Customizing the default adjustment>:
683  
684 The automatic luminance adjustment values can be customized with the
685 C<--adjust> option:
686  
687 --adjust light='=y30' # use =y30 instead of =y25 for light mode
688 --adjust dark='=y70' # use =y70 instead of =y80 for dark mode
689  
690 B<Note>: Basic ANSI color codes (C<R>, C<G>, C<B>, etc.) cannot be used
691 because heading variations require luminance adjustment, which only works
692 with full color specifications (X11 names, RGB hex, or RGB decimal).
693  
694 =item B<--config>=I<KEY>=I<VALUE>
695  
696 Set config parameters from the command line. Parameters are
697 passed to the L<App::Greple::md> module via
698 L<Getopt::EX::Config>. Theme keys recognized by mdee (C<base>,
699 C<FILE>, C<FILE_FORMAT>) are consumed locally and applied to both
700 light and dark themes; all other parameters are forwarded to the
701 md module.
702  
703 Color labels (C<h1>, C<bold>, C<italic>, etc.) are accepted as
704 config parameters and override default colors. The C<${base}>
705 placeholder can be used and will be expanded at runtime.
706  
707 mdee --config h1=RD # red h1
708 mdee --config bold=GD --config italic=YI # green bold, yellow italic
709 mdee --config h1='L25D/R;E' # custom h1 with background
710 mdee --config FILE='L25D/R;E' # red file label
711 mdee --config FILE_FORMAT=%s: # simple format
712 mdee --config hashed.h3=1 # enable h3 closing hashes
713 mdee --config cjk_friendly=1 # see LIMITATIONS, Emphasis
714  
715 Theme keys consumed by mdee:
716  
717 =over 4
718  
719 =item C<base> - Base color (equivalent to C<--base-color>)
720  
721 =item C<FILE> - Color spec for file label (default: C<L25D/${base};E> for light, C<L00D/${base};E> for dark). This is passed to greple's C<FILE> label and cannot be set via C<--cm>.
722  
723 =item C<FILE_FORMAT> - Format string for file label passed to greple's C<--format FILE=> (default: C<\n %s\n\n>). Cannot be set via C<--cm>.
724  
725 =back
726  
727 All other keys are passed to the md module as config parameters.
728 See L</Highlight Options> for the list of available color labels.
729 The md module also accepts operational parameters such as
730 C<table_trim>, C<table_width>, C<table_cell>, C<rule>, C<osc8>,
731 C<tick_open>, C<tick_close>, etc.
732  
733 =back
734  
735 =head2 Highlight Options
736  
737 =over 4
738  
739 =item B<--colormap>=I<LABEL>=I<SPEC>, B<--cm> I<LABEL>=I<SPEC>
740  
741 Override the color for a specific element. I<LABEL> is one of the
742 color labels listed below. I<SPEC> follows
743 L<Term::ANSIColor::Concise> format.
744  
745 --colormap h1=RD # red bold headings
746 --colormap code_block=/L20;E # dark background for code blocks
747 --colormap bold='${base}D' # base color bold
748  
749 This option is passed to the L<App::Greple::md> module, as a module
750 option before C<--> in the B<greple> command line (see it with C<-n>).
751 It is not the C<--cm> option of B<greple>, so C<FILE> and C<FILE_FORMAT>
752 are set by C<--config> instead.
753  
754 Available labels:
755  
756 h1 - h6 Heading levels 1 through 6
757 bold Bold (**text** or __text__)
758 italic Italic (*text* or _text_)
759 strike Strikethrough (~~text~~)
760 emphasis_mark Emphasis markers (**, *, __, _, ~~)
761 bold_mark Bold markers only (overrides emphasis_mark)
762 italic_mark Italic markers only (overrides emphasis_mark)
763 strike_mark Strike markers only (overrides emphasis_mark)
764 link Inline links [text](url)
765 image Images ![alt](url)
766 image_link Image links [![alt](img)](url)
767 image_missing Images whose file is not found
768 message Messages of the commands run (mmdr), not of the text
769 link_mark Link/image brackets (overrides emphasis_mark)
770 br_mark <br> breaking a table cell (overrides emphasis_mark)
771 blockquote Blockquote marker (>)
772 horizontal_rule Horizontal rules (---, ***, ___)
773 comment HTML comments (<!-- ... -->)
774 code_mark Code block delimiters (``` and ~~~)
775 code_tick Inline code backtick markers
776 code_info Fenced code block info string
777 code_block Fenced code block body
778 code_inline Inline code body
779 meta_mark Front matter delimiter lines
780 meta_block Front matter body
781  
782 This option can be specified multiple times. Color labels can
783 also be set via C<--config>. When both are
784 specified, C<--cm> takes priority over C<--config>.
785  
786 =item B<--heading-markup>=I<STEPS>, B<--hm> I<STEPS>
787  
788 Control inline markup processing inside headings. By default,
789 headings are rendered with uniform heading color without processing
790 bold, italic, strikethrough, or inline code inside them. Links
791 are always processed as OSC 8 hyperlinks regardless of this option.
792  
793 Use C<all> or C<1> to enable all inline formatting within headings
794 using cumulative coloring. To select specific steps, list them
795 separated by colons.
796  
797 Available steps: C<inline_code>, C<horizontal_rules>, C<bold>,
798 C<italic>, C<strike>.
799  
800 mdee --hm all file.md # all markup
801 mdee --hm bold file.md # bold only
802 mdee --hm bold:italic file.md # bold and italic
803  
804 =item B<--show>=I<FIELD>[=I<VALUE>],...
805  
806 Control field visibility for highlighting. Empty value or C<0> disables
807 the field; any other value (including C<1>) enables it.
808  
809 --show italic # enable italic
810 --show bold=0 # disable bold
811 --show all # enable all fields
812 --show all= --show bold # disable all, then enable only bold
813  
814 Multiple fields can be specified with commas or by repeating the option.
815 The special field C<all> affects all fields and is processed first.
816  
817 See L</DESCRIPTION> for the list of available fields and
818 elements that are always active.
819 All controllable fields are enabled by default.
820  
821 =back
822  
823 =head2 Layout Options (passed to nup)
824  
825 =over 4
826  
827 =item B<-V>, B<--parallel>
828  
829 Show two or more files side by side, one pane per file, instead of
830 one after another. The screen shows as many files as fit, as many
831 as the pages of a single file, but not more than there are, and the
832 rest continue below; C<--pane> gives the number. Ignored with a
833 single file.
834  
835 With C<--lateral>, the rest go on to the right in one row instead,
836 and are scrolled sideways, a file at a time:
837  
838 mdee -LV *.md
839 mdee -LVC3 *.md
840  
841 =item B<-L>, B<--[no-]lateral>
842  
843 Put all the pages in one row, given to L<nup(1)|App::nup> as its
844 C<--lateral>. The screen shows as many pages as without it, and
845 space and C<b> of C<less> move by the screen as usual, while C<h> and
846 C<l> move by one page; see L<nup(1)|App::nup> for the keys and the
847 build of C<less> that keeps the pages at the edge of the screen. A
848 single pane goes to nup as well, so that the pages can be shifted one
849 by one. It cannot be used with C<--width>,
850 and nup refuses it with rows (C<-C2,2>, C<-R>, C<-G>) and PDF output.
851 With C<--parallel>, the files go on to the right in the same way,
852 each file a column scrolled up and down as usual; see C<--parallel>.
853 C<default[lateral]=1> in the configuration file makes it the default;
854 the default is left out where the option cannot be used, and
855 C<default[width]> is not used with it.
856  
857 =item B<-C> I<C>[,I<R>], B<--pane>=I<C>[,I<R>]
858  
859 Set the number of columns (panes). The number of rows may follow
860 after a comma: C<-C2,2> is 2 columns and 2 rows on a page, the same
861 as C<-C2 -R2>. When not specified (or 0),
862 the number of columns is calculated from the output width
863 (C<--width>, default terminal width) and C<--pane-width>. If only 1 column fits, nup formatting (borders
864 etc.) is preserved but pagination is handled by the pager instead.
865 Use C<--nup> to force nup's native pagination even in single column.
866  
867 =item B<-R> I<N>, B<--row>=I<N>
868  
869 Set the number of rows. C<-C> takes it as well, as C<-C2,2>.
870  
871 =item B<-G> I<CxR>, B<--grid>=I<CxR>
872  
873 Set grid layout. For example, C<-G2x3> creates 2 columns and 3 rows.
874 The text is folded for the number of columns of C<-C>, which this
875 option does not tell to mdee, so C<-C2,3> is better.
876  
877 =item B<-P> I<N>, B<--page>=I<N>
878  
879 Set the page height in lines.
880  
881 =item B<-S> I<N>, B<--pane-width>=I<N>
882  
883 Set the pane width in characters. Default is 85. This value is
884 used to calculate the number of columns from the output width,
885 and the default fold width. It has no effect when the number of
886 columns is given by C<--pane> or C<--parallel>.
887  
888 =item B<--bs>=I<STYLE>, B<--border-style>=I<STYLE>
889  
890 Set the border style.
891  
892 =item B<-->[B<no->]B<page-number>
893  
894 Show page number on the bottom border of each column. Enabled by
895 default. Use C<--no-page-number> to disable.
896  
897 =item B<-->[B<no->]B<filename>
898  
899 Show the file name label at the top of each file. Enabled by
900 default. Use C<--no-filename> to hide it, for example when files are
901 shown side by side with C<--parallel> and the panes should start with
902 the text. The label format and color are set by the C<FILE_FORMAT>
903 and C<FILE> theme keys (see C<--config>).
904  
905 =back
906  
907 =head2 Output Options
908  
909 =over 4
910  
911 =item B<--[no-]pager>[=I<COMMAND>]
912  
913 Set the pager command. Use C<--pager=less> to specify a pager,
914 or C<--no-pager> to disable paging.
915  
916 =item B<-T> I<DEVICE>, B<--device>=I<DEVICE>
917  
918 Set the device to show the output on, which is given to
919 L<nup(1)|App::nup>. The default is C<tty>, the terminal. Any other
920 device is a paper, and the output is printed to PDF by
921 L<ansi2pdf(1)|https://github.com/tecolicom/App-ansi2pdf>: C<a4> is A4
922 in landscape, C<a4p> is A4 in portrait and C<a3l> is A3 in landscape.
923 The device C<pdf> is the default paper, A4.
924  
925 mdee -T a4 README.md > README.pdf
926 mdee -T a4p -o README.pdf README.md
927  
928 The paper takes the place of the terminal, as described in
929 L</Printing to PDF>, and the pager is not used.
930  
931 This requires the nup style, and C<ansi2pdf>
932 0.1.3 or later for PDF (0.1.4 or later for the margin).
933  
934 =item B<-o> I<FILE>, B<--output>=I<FILE>
935  
936 Write the output to I<FILE>, which is given to L<nup(1)|App::nup>.
937 When the name ends with C<.pdf>, the output is PDF without C<-T> as
938 well. Otherwise, what is shown on the terminal is written to the
939 file as it is.
940  
941 mdee -o README.pdf README.md
942  
943 =back
944  
945 =head1 IMAGES
946  
947 B<mdee> shows images in the terminal, below the line that refers to
948 them. The line itself is kept, so the output with C<--no-image> is
949 the same text without the images. When the image is shown, the line
950 is markup only: it is shown as it is written, in C<code_info>, the
951 color of the info string of a code fence.
952  
953 =head2 Which Images
954  
955 An image is shown when its line contains nothing else. The line is
956 one of:
957  
958 =over 4
959  
960 =item * a Markdown image, C<![alt](file)>, or one in a link,
961 C<[![alt](file)](url)>;
962  
963 =item * an HTML C<< <img src="file"> >>, alone or inside C<< <p> >>,
964 C<< <div> >>, C<< <a> >> or C<< <center> >>. This is the form which
965 is written in C<=begin html> in POD and copied into README.
966  
967 =back
968  
969 Images inside a paragraph or a code block are not shown.
970  
971 =head2 Mermaid Diagrams
972  
973 With C<mermaid> in B<--image> (the default), a fenced code block
974 whose info string is C<mermaid>, or has the class C<.mermaid> in the
975 attributes of pandoc, as pandoc-plot takes it
976 (C<{.mermaid caption="..." #fig:x}>), is followed by the image of its
977 diagram, when B<mmdc> or B<mmdr> is installed; without them, the
978 code is shown alone. The code is shown as it is, as the line of an
979 image is, so the output with B<--no-image> is the same text without
980 the images.
981  
982 The diagrams are drawn by B<mmdr> of
983 L<mermaid-rs-renderer|https://github.com/1jehuang/mermaid-rs-renderer>,
984 which needs no browser, is quick, and draws the diagrams in its own
985 way, or by B<mmdc> of
986 L<mermaid-cli|https://github.com/mermaid-js/mermaid-cli>, which is
987 Mermaid itself in a browser and takes a second or more, for all the
988 new diagrams of the file at once (one by one when one has an error),
989 while lines on the terminal tell that they are being drawn, how
990 many are drawn, and the seconds gone by;
991 B<mmdc> is used when it is found in C<PATH>, for it draws the
992 diagrams as GitHub does, and B<mmdr> when only that is. They are drawn on the background GitHub shows them on: the
993 C<default> theme on white, or the C<dark> theme on C<#0d1117> in the
994 dark mode. The images are kept in
995 F<mdee-mermaid-I<UID>> of the temporary directory (C<TMPDIR>, or
996 F</tmp>), which only the user can read, and drawn again only when the
997 code changes or the system has cleaned them up. A diagram that
998 cannot be drawn is not shown, and is tried again the next time; what
999 the command says then is shown below the closing fence, in a box
1000 with the name of the command on its top, in the color of C<message>,
1001 so that it is not taken for the text; the stack of JavaScript that
1002 B<mmdc> writes after its error is left out.
1003 B<mmdr> reads the code in its own way, and draws a diagram even with
1004 an error such as a C<[> not closed: that a diagram is drawn does not
1005 mean that the code is right. B<mmdc> reads it as GitHub does, and
1006 tells such an error (C<--config mermaid_command=mmdc>).
1007  
1008 Nothing is fetched from the network for a diagram either: the browser
1009 of B<mmdc> is given a proxy that is not there, so that a remote image
1010 in a diagram is not shown, and B<mmdr> does not fetch anything.
1011  
1012 B<mmdc> draws in a browser of puppeteer, which looks only for its
1013 own, and the mermaid-cli of Homebrew comes without one: mdee gives it
1014 Google Chrome or Chromium when one is found, in F</Applications> of
1015 macOS or in C<PATH> (C<google-chrome>, C<chromium> and others).
1016 C<PUPPETEER_EXECUTABLE_PATH>, when set, is used instead.
1017  
1018 The look is set by C<--config>: C<mermaid_theme=NAME> (C<default>,
1019 C<dark>, C<forest> or C<neutral>), C<mermaid_background=COLOR> (a color
1020 of CSS, or C<transparent>, with which the background of the terminal
1021 shows through) and C<mermaid_scale=N> (1.5 by default). A diagram is
1022 shown at its size, in the cells of the terminal, and reduced to the
1023 fold width when it is wider; a larger scale makes a small diagram take
1024 more cells, and fewer panes (C<-C1>, or C<-p>) leave more width for a
1025 wide one.
1026  
1027 The command is chosen by C<--config mermaid_command=COMMAND>, split
1028 into words as a shell does: C<mermaid_command=mmdc>, or a path, or a
1029 command with options. One whose name starts with C<mmdr> is given
1030 the options of B<mmdr>, one whose name starts with C<mermaidx> those
1031 of B<mermaidx>, and any other those of B<mmdc>.
1032  
1033 B<mermaidx> of L<PyPI|https://pypi.org/project/mermaidx/>
1034 (C<mermaid_command=mermaidx>) runs Mermaid itself in Python, without
1035 a browser, and takes less than a second for a diagram. It draws the
1036 text in a font of its own, DejaVu Sans, which has no glyphs for
1037 Japanese, Chinese or Korean: such text is shown as boxes.
1038 A command with its own C<-p> (the options of puppeteer) is not given
1039 the proxy, and B<mmdr> with its own C<-c> is not given the background.
1040  
1041 B<mmdc> is given the config of Mermaid in a file of C<-c>, with
1042 C<useMaxWidth: false> for each type of diagram: without it, Mermaid
1043 makes a diagram as narrow as the page of the browser, about 800
1044 pixels, and the text of a wide one small. A diagram is drawn in its
1045 own size, and made as narrow as the fold width when it is shown.
1046 B<mmdc> with its own C<-c> is not given it.
1047  
1048 =head2 Image Files
1049  
1050 The file is read from the local disk, by a path relative to the
1051 Markdown file or an absolute path. Nothing is fetched from the
1052 network, with one exception for GitHub URLs:
1053  
1054 https://raw.githubusercontent.com/OWNER/REPO/BRANCH/PATH
1055 https://github.com/OWNER/REPO/blob/BRANCH/PATH
1056  
1057 These are read as the file I<PATH> in the git work tree of the Markdown
1058 file, if one of its remotes is C<github.com/OWNER/REPO>. The branch is
1059 ignored. The README files of CPAN distributions often refer to their
1060 images this way.
1061  
1062 PNG, JPEG and GIF files are shown, those of the types given to
1063 B<--image>. The type is detected from the content, not the file name. JPEG and GIF are converted to PNG with
1064 C<sips> (macOS) or ImageMagick; without either, they are not shown.
1065 A PNG much larger than the screen is reduced by the same tools, to
1066 send less data; without them, it is sent as it is.
1067 A file that is not found is not shown, and its C<![text]> is in the
1068 color of C<image_missing> (red), with images shown or not, so that a
1069 wrong path is seen before the text is published. Only a path is
1070 looked at, not a URL, and not in the text from the standard input,
1071 which has no directory.
1072  
1073 =head2 Size
1074  
1075 An image is shown at its pixel size, reduced to fit within the fold
1076 width and within the terminal height minus four lines. With nup, an
1077 image is not split across panes: if it does not fit in the rest of a
1078 pane, it starts in the next one (requires
1079 L<ansicolumn(1)|App::ansicolumn> 1.71 or later).
1080  
1081 An image is put in the middle of the fold width. With
1082 C<--config image_align=left> it is put at the left end.
1083  
1084 =head2 Conditions
1085  
1086 Images are shown only when all of the following are true:
1087  
1088 =over 4
1089  
1090 =item * The output goes to the terminal or to a pipe, not to a file:
1091 no C<-o> or C<--cat-v> (see below for paper). Through a pipe, the image data is
1092 still sent to the terminal, and the program at the other end shows
1093 the rows, as C<mdee -f file.md | LESSUTFCHARDEF=10EEEE:p less -R>
1094 does.
1095  
1096 =item * The terminal is iTerm2 3.7.3 or later (C<TERM_PROGRAM=iTerm.app>),
1097 Ghostty (C<TERM_PROGRAM=ghostty>) or kitty (C<TERM=xterm-kitty>).
1098  
1099 =item * The pager is C<less> 632 or later, which supports
1100 C<LESSUTFCHARDEF>.
1101  
1102 =back
1103  
1104 The terminal is identified from the environment. A terminal started
1105 from another one (for example, by C<open -a> from iTerm2) may inherit
1106 the wrong C<TERM_PROGRAM>. Use C<--no-image> in that case.
1107  
1108 On paper (C<-T>, or C<-o> with a PDF file), the images are drawn by
1109 B<ansi2pdf> instead: the rows of an image tell it the file, and
1110 nothing is sent to the terminal. PNG and JPEG are drawn; GIF is not.
1111 This requires B<ansi2pdf> that knows the rows of an image; an older
1112 one prints them as characters it has no glyph for.
1113  
1114 =head2 How It Works
1115  
1116 Images are drawn with the Unicode placeholders of the kitty graphics
1117 protocol. Each row of an image is a line of special characters, so
1118 it is laid out in columns and paged like text, but never folded. The image data is sent
1119 directly to the terminal once.
1120  
1121 As the rows are text, a search in C<less> can match them, as with
1122 C<.*>. The matched cells are drawn in the color of the search
1123 highlight instead of the image; C<ESC-u>, which turns the highlight
1124 off, shows the image again.
1125  
1126 =head1 THEMES
1127  
1128 A theme changes how the document looks: the colors, the marks that
1129 are shown or hidden, and the decoration of headings and tables.
1130 Themes are chosen with C<--theme> (see L</Theme Options>), and each
1131 is applied in order as a transformation of the default.
1132  
1133 =head2 Built-in Themes
1134  
1135 =over 4
1136  
1137 =item C<hashed> (default)
1138  
1139 Append closing hashes to h3-h6 headers.
1140  
1141 =item C<nomark> (default)
1142  
1143 Hide emphasis markers (C<**>, C<*>, C<__>, C<_>, C<~~>),
1144 inline code backticks, link brackets (C<[>, C<]>), and the
1145 C<< <br> >> that breaks a table cell into lines.
1146 Content text keeps its formatting (bold, italic,
1147 strikethrough, code, clickable links) but the surrounding
1148 markers are not displayed. Table marks (C<markcell>,
1149 C<markwrap>) are independent of this theme.
1150  
1151 =item C<doubleline> (default)
1152  
1153 Give h4 headers a double underline, which is C<ESC[4:2m>, in the
1154 terminals known to take it, decided by environment variables: iTerm2,
1155 Ghostty, cmux, VS Code, WezTerm, kitty, Alacritty, Konsole, Windows
1156 Terminal and terminals based on VTE 0.52 or later. Elsewhere, inside
1157 B<tmux> and B<screen>, and where the variables do not reach, as through
1158 B<ssh>, this theme does nothing and h4 has a single underline, the same
1159 as h5. Many terminals do not take the sequence: it becomes a background color in Terminal.app and
1160 rxvt-unicode, and the Linux console and mosh drop the whole sequence
1161 with its color.
1162  
1163 =item C<warm>
1164  
1165 Change base color to Coral.
1166  
1167 =item C<fatchap>
1168  
1169 Add decorative border lines (C<#>) above and below h1 headings,
1170 using C<=+> to append a text transformation while preserving the
1171 original heading color.
1172  
1173 With C<--refill>, the added lines are not counted, so paragraphs below
1174 the h1 headings may not be folded properly by this module. The text
1175 itself does not change. For this reason, this theme turns off
1176 C<default[refill]> in the configuration file; C<--refill> given on the
1177 command line still works.
1178  
1179 =item C<widen>
1180  
1181 Give circled digits and the wastebasket (U+1F5D1) a column of their
1182 own, by adding a no-break space after them, for terminals that draw
1183 them over two columns on top of the next character, as on macOS.
1184 This gives the function of L<App::Greple::md::widen> to the C<--begin>
1185 option of the md module.
1186  
1187 The characters are listed in the array C<widen_chars> of the theme, as
1188 code points and ranges in hexadecimal. Add more in F<config.sh>:
1189  
1190 widen_chars+=(3248-324F) # circled numbers on black squares
1191  
1192 =item C<markcell> (default)
1193  
1194 In a table that has wrapped cells, mark the first line of every
1195 body cell in the wrapped columns with C<‣> (U+2023), so that the
1196 rows read like a bulleted list and the continuation lines stand
1197 apart. The header row, columns that fit, and tables that fit are
1198 not marked. Sets C<table_cell_mark>; C<nomark> does not affect it.
1199 To use another character, set it in the configuration file or in a
1200 theme of your own:
1201  
1202 md_config+=(table_cell_mark=∙) # U+2219
1203  
1204 =item C<markwrap>
1205  
1206 Mark the second and later lines of a wrapped table cell with C<›>
1207 (U+203A). Sets C<table_wrap_mark>. It can be combined with
1208 C<markcell>.
1209  
1210 =back
1211  
1212 =head2 Theme Files
1213  
1214 Theme files are searched in the following order:
1215  
1216 =over 4
1217  
1218 =item 1. User theme directory: C<${XDG_CONFIG_HOME:-~/.config}/mdee/theme/NAME.sh>
1219  
1220 =item 2. Share theme directory: installed with the distribution under C<auto/share/dist/App-mdee/theme/>
1221  
1222 =back
1223  
1224 Theme files are Bash scripts that can modify C<theme_light[]>,
1225 C<theme_dark[]>, C<md_config[]>, and/or C<pass_md[]>:
1226  
1227 # theme/warm.sh — change base color
1228 theme_light[base]='<Coral>=y25'
1229 theme_dark[base]='<Coral>=y80'
1230  
1231 # theme/hashed.sh — enable closing hashes on h3-h6
1232 md_config+=(hashed.h3=1 hashed.h4=1 hashed.h5=1 hashed.h6=1)
1233  
1234 # theme/nomark.sh — hide markers and brackets
1235 pass_md+=(--cm 'emphasis_mark=sub{""}')
1236 pass_md+=(--cm 'code_tick=sub{""}')
1237 pass_md+=(--cm 'link_mark=sub{""}')
1238  
1239 =head1 CONFIGURATION
1240  
1241 User configuration is loaded from:
1242  
1243 ${XDG_CONFIG_HOME:-~/.config}/mdee/config.sh
1244  
1245 This is a shell script that can set defaults and override colors:
1246  
1247 # ~/.config/mdee/config.sh
1248 default[mode]=dark # set default mode
1249 default[theme]=warm # set default theme(s)
1250 default[style]=pager # set default style
1251 default[width]=170 # set default output width
1252 default[fold_width]=80 # set default fold width
1253 default[refill]=1 # join paragraph lines
1254 default[lateral]=1 # all pages in one row
1255 default[keep]=table=all # a table in one pane
1256 default[base_color]=DarkCyan # set default base color
1257  
1258 A value which has spaces or characters special to the shell, as C<< < >>,
1259 C<< > >>, C<;> or C<|>, is put in quotes: C<< theme_light[base]='<DarkCyan>=y25' >>.
1260  
1261 The C<default> associative array supports the following keys:
1262  
1263 =over 4
1264  
1265 =item C<default[mode]> - Corresponds to C<--mode> (e.g., C<dark>, C<light>)
1266  
1267 =item C<default[theme]> - Corresponds to C<--theme> (e.g., C<warm>, C<warm,hashed>)
1268  
1269 =item C<default[style]> - Corresponds to C<--style> (e.g., C<pager>, C<cat>)
1270  
1271 =item C<default[width]> - Corresponds to C<--width> (e.g., C<170>)
1272  
1273 =item C<default[fold_width]> - Corresponds to C<--fold-width> (e.g., C<80>)
1274  
1275 =item C<default[refill]> - Corresponds to C<--refill> (C<1> to enable)
1276  
1277 =item C<default[lateral]> - Corresponds to C<--lateral> (C<1> to enable)
1278  
1279 =item C<default[keep]> - Corresponds to C<--keep> (e.g., C<table=all>)
1280  
1281 =item C<default[pane_width]> - Corresponds to C<--pane-width> (e.g., C<100>)
1282  
1283 =item C<default[pane]> - Corresponds to C<--pane> (e.g., C<2> or C<2,2>)
1284  
1285 =item C<default[base_color]> - Corresponds to C<--base-color> (e.g., C<DarkCyan>)
1286  
1287 =back
1288  
1289 C<default[refill]> and C<default[lateral]> are on with any value,
1290 C<1>, C<0> and C<no> alike, and off when empty.
1291  
1292 B<Overriding theme colors>
1293  
1294 Config.sh can modify theme variables directly, using the same
1295 mechanism as theme files:
1296  
1297 # Change base color for both modes
1298 theme_light[base]='<DarkCyan>=y25'
1299 theme_dark[base]='<DarkCyan>=y80'
1300  
1301 # Enable md module features
1302 md_config+=(hashed.h3=1 hashed.h4=1 hashed.h5=1 hashed.h6=1)
1303  
1304 # Use another character for the table cell mark
1305 md_config+=(table_cell_mark=∙)
1306  
1307 These settings take precedence over the default themes.
1308  
1309 Changing the base color automatically affects all derived colors
1310 (h1, h2, bold, etc.) because the md module expands C<${base}>
1311 references.
1312  
1313 Use C<-d> to dump current theme values in sourceable format.
1314  
1315 B<Color specification format>
1316  
1317 Color specifications use L<Term::ANSIColor::Concise> format.
1318 The C<FG/BG> notation specifies foreground and background colors
1319 (e.g., C<L25D/${base};E> means gray foreground on base-colored background).
1320 The C<${base}> string is expanded to the base color value after loading.
1321  
1322 To change the text before it is formatted, give a function to the
1323 C<--begin> option of the md module:
1324  
1325 pass_md+=(--begin 'sub{ s/\(C\)/\x{A9}/g }')
1326  
1327 =head1 EXAMPLES
1328  
1329 mdee README.md # view markdown file
1330 mdee -C2 document.md # 2-column view
1331 mdee -C2,2 manual.md # 2x2 grid (4-up)
1332 mdee -w170 file.md # two 85-column panes on a wide terminal
1333 mdee -V -w170 a.md b.md # two files in 85 columns each
1334 mdee --fold-width=60 a.md # narrower text within the pane
1335 mdee --no-pager file.md # without pager
1336 mdee --no-nup file.md # output to stdout without nup
1337 mdee --no-fold file.md # disable line folding
1338 mdee --no-table file.md # disable table formatting
1339 mdee -r file.md # join paragraph lines
1340  
1341 # PDF
1342 mdee -o file.pdf file.md # A4 in landscape
1343 mdee -T a4p -o file.pdf file.md # A4 in portrait
1344 mdee -T a4p -C1,2 -o file.pdf file.md # two pages on a sheet
1345  
1346 # Output styles
1347 mdee -s pager file.md # fold + table, output to pager
1348 mdee -s cat file.md # fold + table, output to stdout
1349 mdee -s filter file.md # table only, no fold/nup
1350 mdee -s raw file.md # highlight only
1351  
1352 # Style shortcuts
1353 mdee -p file.md # same as --style=pager
1354 cat file.md | mdee -f # highlight stdin (filter mode)
1355 mdee -f file.md # highlighted output to stdout
1356  
1357 # Override individual settings
1358 mdee -f --fold file.md # filter + fold
1359 mdee -p --no-fold file.md # pager without fold
1360  
1361 # Theme examples
1362 mdee --mode=dark file.md # use dark mode
1363 mdee --mode=light file.md # use light mode
1364 mdee -B Ivory file.md # override base color
1365 mdee --mode=dark -B '#780043' file.md # dark mode with burgundy
1366 mdee --theme=warm file.md # warm (Coral) base color
1367 mdee --no-theme file.md # show all markup characters
1368  
1369 =head1 DEPENDENCIES
1370  
1371 This command requires the following:
1372  
1373 =over 4
1374  
1375 =item * L<App::Greple> - pattern matching and highlighting
1376  
1377 =item * L<App::Greple::tee> - filter integration
1378  
1379 =item * L<App::ansifold> - ANSI-aware text folding
1380  
1381 =item * L<App::ansicolumn> - ANSI-aware column formatting
1382  
1383 =item * L<App::nup> - N-up multi-column paged output
1384  
1385 =item * L<App::ansiecho> - ANSI color output
1386  
1387 =item * L<Getopt::Long::Bash> - bash option parsing
1388  
1389 =item * L<Getopt::EX::termcolor> - terminal background detection
1390  
1391 =back
1392  
1393 The code in fenced code blocks is colored by
1394 L<Text::ANSI::Highlight>, with C<pandoc> 3.4 or later
1395 (C<brew install pandoc>), or with C<source-highlight> or
1396 C<skylighting>. Without the command, the code is shown as it is.
1397  
1398 C<--refill> finds the paragraphs with L<Markdown::Perl> (pure Perl,
1399 installed with this distribution). The L<CommonMark> module, which
1400 needs the libcmark C library (C<brew install cmark>, C<apt-get install
1401 libcmark-dev>) and is only recommended, is used when it is there
1402 because it is faster; L<pandoc|https://pandoc.org> 2.11.3 or later is
1403 a third choice.
1404  
1405 =head1 LIMITATIONS
1406  
1407 =head2 HTML Comments
1408  
1409 Only HTML comments starting at the beginning of a line are highlighted.
1410 Inline comments are not matched to avoid conflicts with inline code
1411 containing comment-like text (e.g., C<< `<!-->` >>).
1412  
1413 =head2 Emphasis
1414  
1415 Emphasis patterns (bold and italic) do not span multiple lines.
1416 Multi-line emphasis text is not supported.
1417  
1418 C<***bold italic***> and C<___bold italic___> are supported.
1419 Other nested forms (e.g., C<< **bold _italic_** >>) are not.
1420  
1421 C<*> and C<**> start and end emphasis as in CommonMark: a delimiter
1422 with a letter on one side and punctuation on the other does not
1423 count, so C<L*=50, a*=68> is not italic. CommonMark counts Unicode
1424 punctuation, and this rejects some emphasis in Japanese text,
1425 such as C<日本語の*「強調」*です> and C<日本語の**強調。**です>. mdee
1426 shows them as the commonmark and gfm readers of pandoc and zenn.dev
1427 do, with the markers and without emphasis, so that such text can be
1428 found before it is published.
1429  
1430 With C<cjk_friendly=1> (C<--config cjk_friendly=1>, or
1431 C<md_config+=(cjk_friendly=1)> in F<config.sh>), the rules of
1432 L<markdown-cjk-friendly|https://github.com/tats-u/markdown-cjk-friendly>
1433 are used instead: CJK punctuation does not count, and a CJK character
1434 on the other side is as good as a space, so these are emphasis. This
1435 is a proposal, not part of CommonMark; use it for text that is
1436 processed by an implementation of it.
1437  
1438 =head2 Block Quotes
1439  
1440 A block quote is recognized by its C<E<gt>> markers at the start of a
1441 line, after up to three spaces. Only the markers are colored, not the
1442 quoted text. Headings, lists and code blocks inside a quote are not
1443 recognized, so they get no color of their own, and a code block in a
1444 quote does not protect its contents from inline highlighting.
1445  
1446 A line without a marker that continues a quoted paragraph (a lazy
1447 continuation in CommonMark) is shown as an ordinary line, unless
1448 C<--refill> joins it to the quote.
1449  
1450 =head2 Links
1451  
1452 Link patterns do not span multiple lines. The link text and URL must
1453 be on the same line.
1454  
1455 Reference-style links (C<[text][ref]> with C<[ref]: url> elsewhere)
1456 are not supported.
1457  
1458 =head2 Paragraph Refill
1459  
1460 C<--refill> joins lines by the rules of Markdown, as the parser
1461 reads them. Lines of verse, addresses or lyrics that rely on the line
1462 breaks without a hard line break (two spaces or a backslash at the
1463 end of the line) are joined as well, and so are the lines of a
1464 display math block between C<$$> lines. Do not use C<--refill>
1465 for such documents.
1466  
1467 =head2 Table Alignment
1468  
1469 Column alignment assumes that cell content in the source is not
1470 pre-padded. If the source table is already formatted with aligned
1471 spacing (e.g., C<| c |>), the embedded spaces become part of
1472 the cell content and alignment directives in the separator line
1473 will not produce the expected result. This is by design: pre-formatted
1474 tables are assumed to be correctly aligned as-is.
1475  
1476 =head2 OSC 8 Hyperlinks
1477  
1478 Links are converted to OSC 8 terminal hyperlinks for clickable URLs:
1479  
1480 =over 4
1481  
1482 =item C<[text](url)> - C<[text]> links to url
1483  
1484 =item C<![alt](url)> - C<![alt]> links to url (image)
1485  
1486 =item C<[![alt](img)](url)> - C<!> links to img, C<[alt]> links to url
1487  
1488 =back
1489  
1490 This requires terminal support. Compatible terminals include iTerm2,
1491 Kitty, WezTerm, Ghostty, and recent versions of GNOME Terminal.
1492 Apple's default Terminal.app does not support OSC 8.
1493  
1494 When using C<less> as pager, version 566 or later is required with
1495 C<-R> option.
1496  
1497 For OSC 8 specification, see:
1498 L<https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda>
1499  
1500 =head2 Terminal Luminance
1501  
1502 Without C<--mode> or C<default[mode]>, B<mdee> asks the terminal for
1503 its background color (OSC 11) through L<Getopt::EX::termcolor> to
1504 choose between light and dark mode. Set C<TERM_LUMINANCE> to a value
1505 from 0 to 100 to give the answer yourself and skip the query, for
1506 example in scripts or tests, where a reply that arrives late would
1507 show up as terminal input.
1508  
1509 =head2 Less Environment Variables
1510  
1511 When C<less> is used as pager (either directly via C<--style=pager> or
1512 through C<nup>), the following environment variables affect behavior.
1513 B<mdee> sets defaults for these when they are not already defined:
1514  
1515 =over 4
1516  
1517 =item C<LESS>
1518  
1519 Default: C<-R>. The C<-R> option is required for ANSI color
1520 sequences to be displayed correctly.
1521  
1522 =item C<LESS_TERMCAP_ti>
1523  
1524 When images are shown with C<less> in Ghostty or kitty (see
1525 L</IMAGES>), B<mdee> sets C<LESS_TERMCAP_ti>, the string with which
1526 C<less> switches to the alternate screen, to that string (the one
1527 given in C<LESS_TERMCAP_ti>, or C<tput smcup>) followed by the
1528 sequences which send the images again by their files. Ghostty and kitty keep the images for each
1529 screen, and those sent to the screen shown before are not on the
1530 alternate screen. The text is made before the pager starts, so
1531 that the string is known then. iTerm2 shows the images on the
1532 alternate screen, and is not given it. The images are sent to the
1533 screen shown as well, for C<less -F>, which does not switch the
1534 screen when the text fits in it.
1535  
1536 =item C<LESSUTFCHARDEF>
1537  
1538 When images are shown, B<mdee> adds C<10EEEE:p>, so that C<less>
1539 treats the placeholder character of the images as printable.
1540  
1541 =item C<LESSANSIENDCHARS>
1542  
1543 Default: C<mK>. This tells C<less> to recognize ANSI sequences
1544 ending with C<m> (SGR color) and C<K> (erase line). The erase line
1545 sequence is used for background color rendering.
1546  
1547 =back
1548  
1549 If you already have these variables set in your environment, B<mdee>
1550 does not override them.
1551  
1552 =head1 SEE ALSO
1553  
1554 =over 4
1555  
1556 =item L<Implementation of em·dee|https://github.com/tecolicom/App-mdee/blob/main/IMPLEMENTATION.md>
1557  
1558 How the pipeline, the themes and the colors work inside.
1559  
1560 =item L<App::Greple::md>
1561  
1562 Greple module for Markdown syntax highlighting, table formatting,
1563 and text folding. Bundled with this distribution.
1564  
1565 =item L<greple>
1566  
1567 General-purpose extensible grep tool used for pattern matching.
1568  
1569 =item L<nup>
1570  
1571 Multi-column paged output formatter.
1572  
1573 =item L<ansi2pdf|https://github.com/tecolicom/App-ansi2pdf>
1574  
1575 Renders the output to PDF.
1576  
1577 =item L<ansifold|https://metacpan.org/dist/App-ansifold/view/script/ansifold>
1578  
1579 ANSI-aware text folding for line wrapping.
1580  
1581 =item L<ansicolumn>
1582  
1583 ANSI-aware column formatting for table alignment.
1584  
1585 =item L<CommonMark>, L<Markdown::Perl>, L<pandoc|https://pandoc.org>
1586  
1587 One of them finds the paragraphs for C<--refill>.
1588  
1589 =item L<CommonMark Spec 0.31.2, Emphasis and strong emphasis|https://spec.commonmark.org/0.31.2/#emphasis-and-strong-emphasis>
1590  
1591 The rules that C<*> and C<**> follow by default (see L</Emphasis>).
1592  
1593 =item L<CommonMark CJK-friendly Amendments|https://github.com/tats-u/markdown-cjk-friendly/blob/main/specification.md>
1594  
1595 The rules that C<cjk_friendly=1> follows. The proposal comes from
1596 L<commonmark-spec issue #650, Emphasis with CJK punctuation|https://github.com/commonmark/commonmark-spec/issues/650>,
1597 open since 2020.
1598  
1599 =item L<Terminal graphics protocol, Unicode placeholders|https://sw.kovidgoyal.net/kitty/graphics-protocol/#unicode-placeholders>
1600  
1601 The protocol by which images are shown (see L</IMAGES>).
1602  
1603 =item L<Text::ANSI::Image>
1604  
1605 Draws the images as lines of text by the protocol.
1606  
1607 =item L<https://github.com/tecolicom/App-mdee>
1608  
1609 Repository and bug tracker.
1610  
1611 =back
1612  
1613 =head1 AUTHOR
1614  
1615 Kazumasa Utashiro
1616  
1617 =head1 LICENSE
1618  
1619 Copyright © 2026 Kazumasa Utashiro.
1620  
1621 This software is released under the MIT License.
1622 L<https://opensource.org/licenses/MIT>
1623  
1624 =cut
« blib/lib/App/Greple/md/widen.pm ↑ Summary