Rand Stats

App::Rak::Markdown

zef:lizmat

Actions Status Actions Status Actions Status

NAME

App::Rak::Markdown - convert App::Rak output to Markdown

SYNOPSIS

use App::Rak::Markdown;

my $rmd = App::Rak::Markdown.new;

spurt "result.md", $rmd.markdown(@output);

spurt "result.md", $rmd.run(<--unicode §love>, :tableize<unicode>);

DESCRIPTION

The App::Rak::Markdown distribution provides logic to convert the output of App::Rak to Markdown format.

This can either be done from captured output, or from a set of arguments to be sent to the rak command line script.

METHODS

new

my $rmd = App::Rak::Markdown.new(
  break => '§§§',  # default: '***'
);

The new method takes 1 named argument:

:break

The string to be used / checked for between grouped items in rak's output (as documented with the --break argument). Defaults to "***".

markdown

say $rmd.markdown(@output);

my $markdown = $rmd.markdown(
  @output,
  :$items,    # store # of items seen, default: don't bother
  :$files,    # store # of files seen, default: don't bother
  :$heads,    # store # of headers seen, default: don't bother
  :headers(0),  # how many levels of headers, default: 1
  :depth<##>,   # markdown string of top headers, default: "###"
  :&tableizer,  # logic to create tables, default: none
  :&splitter,   # headers split logic, default: *.split("/",$headers)
)

The markdown method takes one positional argument and an optional number of named arguments, and returns a string formatted according to Markdown rules.

It takes one positional argument: a list of lines of rak output.

It also takes the following optional named arguments:

Creating tables

If the output from rak is fit to create markdown tables for (e.g. the --unicode option, the :tableizer named argument can be used to indicate a Callable that will be called to manage creating markdown tables.

This Callable is expected to be called without any arguments: in that case it should return two lists: the first with the names of the columns, and the second with formatting info for each column. The formatting info can be specified with the following words:

Any other word will cause no specific aligning to be done.

If called with an argument, it should return a list with the text for each column.

Some standard rak options have a dedicated tableizer, which can be invoked by name. They currently are:

run

say "result.md", $rmd.run(<--unicode §love>, :tableize<unicode>);
hex | name | graph
:- | :-: | :-:
1F3E9 | <b>LOVE</b> HOTEL | 🏩
1F48C | <b>LOVE</b> LETTER | 💌
1F91F | I <b>LOVE</b> YOU HAND SIGN | 🤟

The run method is effectively a wrapper around the markdown method.

It either returns the Markdown string, or Nil if something went wrong, or if not enough lines were received from rak to make parsing to Markdown worthwhile.

The positional argument is required: it should contain the arguments to be sent to rak.

These named arguments can be specified with the run method:

Note that the :@out named argument only makes sense if the :min-lines argument also has been specified with a value greater than 0.

All other named arguments that markdown can receive, can also be specified here and will be passed on to the markdown method:

AUTHOR

Elizabeth Mattijsen liz@raku.rocks

Source can be located at: https://github.com/lizmat/App-Rak-Markdown . Comments and Pull Requests are welcome.

If you like this module, or what I'm doing more generally, committing to a small sponsorship would mean a great deal to me!

COPYRIGHT AND LICENSE

Copyright 2025 Elizabeth Mattijsen

This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.