NAME

App::Greple::md::Blocks - find the paragraphs of a Markdown text

SYNOPSIS

use App::Greple::md::Blocks qw(blocks available);

my @blocks = blocks($text);                    # first available parser
my @blocks = blocks($text, parser => 'cmark'); # or 'mdperl', 'pandoc'
my @parsers = available();                     # ('cmark', 'mdperl', 'pandoc')

DESCRIPTION

This module gives App::Greple::md the line numbers of the paragraphs in a Markdown text, for its refill option, which joins the lines of each paragraph. The text itself is not changed or rendered: the module is only asked where the paragraphs are.

Each block is a hash with type (Para or Plain for a paragraph), depth (the number of block quotes the block is in) and first and last (its first and last line, counted from 1).

Three parsers are supported:

cmark

The CommonMark module, an interface to libcmark, run in this process. It is fast, but it does not know GFM tables and definition lists, which it reports as paragraphs; App::Greple::md keeps their lines apart by their shape.

mdperl

Markdown::Perl, a CommonMark implementation in pure Perl and a dependency of this distribution, so it is always there. It publishes no parse tree or positions; the module wraps two private subroutines of its block parser while it parses and reads the line numbers from there, checks first that those subroutines exist, and parses tables as paragraphs, like libcmark, so that the three parsers agree.

pandoc

pandoc 2.11.3 or later, run as a child process with -f gfm+sourcepos+definition_lists -t json.

available() returns the names of the parsers that work on this system, the fastest first (cmark, mdperl, pandoc), and blocks() uses the first of them unless parser is given.

SEE ALSO

App::Greple::md, CommonMark, Markdown::Perl, https://pandoc.org

AUTHOR

Kazumasa Utashiro

LICENSE

Copyright 2026 Kazumasa Utashiro.

This software is released under the MIT License. https://opensource.org/licenses/MIT