App-mdee
view release on metacpan or search on metacpan
docs/plans/2026-02-16-greple-md-implementation.md view on Meta::CPAN
```
option default \
-G --all --need=0 --filestyle=once --color=always \
--cm code_fence=L20 \
--cm code_lang=L18 \
--cm code_body=/L23;E \
-E '(?!)' \
--print &__PACKAGE__::colorize
```
Note: The current mdee `code_block` key uses comma-separated colors for 4 capture groups: `'L20 , L18 , /L23;E , L20'`. In the module, these become separate `--cm` labels: `code_fence` (opening+closing), `code_lang` (language specifier), `code_body` ...
**Step 4: Test code block colorization**
Run: `greple -Mmd -Ilib /Users/utashiro/Git/tecolicom/App-mdee/t/test.md 2>/dev/null | head -30`
Expected: Code blocks should be visibly colored (gray text/background)
**Step 5: Commit**
```bash
git add lib/App/Greple/md.pm
git commit -m "feat: code block colorization with state machine"
```
---
### Task 3: Inline Code and Comment Protection
Add inline code and HTML comment colorization. These must be processed early to protect their content from emphasis/link matching.
**Files:**
- Modify: `lib/App/Greple/md.pm`
**Step 1: Add inline code pattern**
In `colorize()`, after the code block check, add inline code replacement. Use a protection mechanism: replace matched regions with placeholders, process other patterns, then restore.
```perl
# Protection mechanism: replace regions with NUL-delimited placeholders
my @protected;
sub protect {
my $text = shift;
push @protected, $text;
"\x00" . $#protected . "\x00";
}
sub restore {
my $s = shift;
$s =~ s/\x00(\d+)\x00/$protected[$1]/g;
$s;
}
sub colorize {
@protected = ();
# ... code block handling (return early) ...
# Inline code: protect from further processing
s/((`++)(?:(?!\g{-2}).)+\g{-2})/protect(main::color('inline_code', $1))/ge;
# HTML comments: protect from further processing
s/(^<!--(?![->]).*?-->)/protect(main::color('comment', $1))/gme;
# (links, headings, emphasis in later tasks)
$_ = restore($_);
$_;
}
```
Note: The `protect/restore` mechanism ensures inline code like `` `**bold**` `` is not processed as bold. NUL bytes are safe as placeholders since they don't appear in normal text.
**Step 2: Add colors to __DATA__**
Add to `option default`:
```
--cm inline_code=L15/L23 \
--cm comment=CM+r60 \
```
Note: `comment` color in mdee is `${base}+r60` (base color + reddish). For standalone default, use a hardcoded approximation. mdee will override via `--cm`.
**Step 3: Test inline code protection**
Create test: a line with `` `**not bold**` `` should show inline code color, NOT bold.
Run: `echo '`**not bold**` but **this is bold**' | greple -Mmd -Ilib 2>/dev/null`
Expected: First part colored as inline code, second part not yet colored (bold not implemented yet)
**Step 4: Commit**
```bash
git add lib/App/Greple/md.pm
git commit -m "feat: inline code and comment colorization with protection"
```
---
### Task 4: Link Patterns with OSC 8
Add link, image, and image_link patterns with OSC 8 hyperlink generation.
**Files:**
- Modify: `lib/App/Greple/md.pm`
**Step 1: Add osc8 function and link patterns**
```perl
use URI::Escape;
sub osc8 {
return $_[1] unless $config->{osc8};
my($url, $text) = @_;
my $escaped = uri_escape_utf8($url, "^\\x20-\\x7e");
"\e]8;;${escaped}\e\\${text}\e]8;;\e\\";
}
```
**Step 2: Add link processing to colorize()**
( run in 0.875 second using v1.01-cache-2.11-cpan-5a3173703d6 )