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.
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)
To install Markdown::Table, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Markdown::Table
CPAN shell
perl -MCPAN -e shell install Markdown::Table
For more information on module installation, please visit the detailed CPAN module installation guide.