Markdown::Table - Create and parse tables in Markdown
version 0.04
To generate a table
use Markdown::Table;
my $table = Markdown::Table->new;
my @columns = qw(Id Name Role);
$table->set_cols( @columns );
my @data = (
[ 1, 'John Smith', 'Testrole' ],
[ 2, 'Jane Smith', 'Admin' ],
);
$table->add_rows( @data );
print $table->get_table;
To get tables from an existing Markdown document
use Markdown::Table;
my $markdown = q~
This table shows all employees and their role.
| Id | Name | Role |
|---|---|---|
| 1 | John Smith | Testrole |
| 2 | Jane Smith | Admin |
~;
my @tables = Markdown::Table->parse(
$markdown,
);
print $tables[0]->get_table;
These are read-only attributes
- cols
- rows
Create a new object
use Markdown::Table;
my @columns = qw(Id Name Role);
my @data = (
[ 1, 'John Smith', 'Testrole' ],
[ 2, 'Jane Smith', 'Admin' ],
);
my $table = Markdown::Table->new(
cols => \@columns,
rows => \@data,
);
# or
my $table = Markdown::Table->new;
$table->set_cols( @columns );
$table->add_rows( @data );
Set the columns of the table
my @columns = qw(Id Name Role);
$table->set_cols( @columns );
Add a row to the table
my @data = (
[ 1, 'John Smith', 'Testrole' ],
[ 2, 'Jane Smith', 'Admin' ],
);
$table->add_rows( @data );
Get the table in markdown format
my $md_table = $table->get_table
Parses the Markdown document and creates a Markdown::Table object for each table found in the document.
use Markdown::Table;
my $markdown = q~
This table shows all employees and their role.
| Id | Name | Role |
+---+---+---+
| 1 | John Smith | Testrole |
| 2 | Jane Smith | Admin |
~;
my @tables = Markdown::Table->parse(
$markdown,
);
print $tables[0]->get_table;
If you just want to generate tables for Markdown documents, you can use Text::ASCIITable. This is the module, Markdown::Table uses for table generation, too.
The distribution is contained in a Git repository, so simply clone the repository
$ git clone git://github.com/perlservices/Markdown-Table.git
and change into the newly-created directory.
$ cd Markdown-Table
The project uses Dist::Zilla
to
build the distribution, hence this will need to be installed before
continuing:
$ cpanm Dist::Zilla
To install the required prequisite packages, run the following set of commands:
$ dzil authordeps --missing | cpanm
$ dzil listdeps --author --missing | cpanm
The distribution can be tested like so:
$ dzil test
To run the full set of tests (including author and release-process tests),
add the --author
and --release
options:
$ dzil test --author --release
Renee Baecker reneeb@cpan.org
This software is Copyright (c) 2020 by Renee Baecker.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)