The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Markdown::Parser::Table - Markdown Table Element

SYNOPSIS

    my $o = Markdown::Parser::Table->new;
    $o->caption( $o->create_table_caption( @_ ) );
    $o->head( $o->create_table_head( @_ ) );
    $o->add_body( $o->create_table_body( @_ ) );
    print $o->as_string, "\n"; # returns html representation of the data
    print $o->as_markdown, "\n"; # returns markdown representation of the data

VERSION

    v0.2.0

DESCRIPTION

This is a class object to represent an entire table. It is used by Markdown::Parser and inherits from Markdown::Parser::Element

For example:

METHODS

new

Instantiate a new table object, which can take the following parameters:

css

This is a CSS::Object object

tag_name

This is the internal value to identify the table object. It is set to table and should not be changed

use_css_grid

A boolean value to set whether to return the table as a css grid rather than as an html table.

When set to true, "as_string" returns "as_css_grid" instead

add_body

Provided with a Markdown::Parser::TableBody object, and this adds it to the stack of Markdown::Parser::TableBody objects.

add_header

Provided with a Markdown::Parser::TableHeader object, and this adds it to the stack of Markdown::Parser::TableHeader objects.

as_css_grid

Returns this table as a CSS grid as a regular string.

This is quite a nifty feature that enables you to transform effortlessly a table into a CSS grid.

as_markdown

Returns a string representation of the table formatted in markdown.

This method will call "caption" if one is set, "header" and "bodies" and get their respective markdown representation of their part.

It returns a plain string.

as_pod

Returns a string representation of the table formatted in pod.

It returns a plain string.

as_string

Returns an html representation of the table. It calls "caption" if one is set, "header" and "bodies" to get their respective html representation.

It returns a plain string.

bodies

Sets or gets a Module::Generic::Array object containing Markdown::Parser::TableBody objects.

body

Alias for "bodies"

caption

Sets or gets a Markdown::Parser::TableCaption object.

When an Markdown::Parser::TableCaption object is provided, this method automatically sets the object "parent" in Markdown::Parser::Element property to the current table object.

Returns the current value set.

Sets or gets a Markdown::Parser::TableHeader object.

When an Markdown::Parser::TableHeader object is provided, this method automatically sets the object "parent" in Markdown::Parser::Element property to the current table object.

Returns the current value set.

headers

Sets or gets a Module::Generic::Array object containing Markdown::Parser::TableHeader objects.

remove_body

Provided with a Markdown::Parser::TableBody object, and this will remove it from the stack of Markdown::Parser::TableBody objects.

Returns the object removed if it was found, or undef otherwise.

reset_stat

Reset the hash reference containing general computed data on the table.

stat

Returns a hash object from Module::Generic::Hash containing table computed data information.

Available information are:

cols
0, 1, 2...

This field key is an integer starting from zero like an array offset. The field value is the width of the cell

In the example above, cell 0 could be, for example, having a width of 10 characters, while cell 1 could be 12 characters and cell 3 too.

    $stat->{cols}->{0}; # 10 characters wide
total

This field contains an integer representing the total number of columns for a row in the table

header
rows

This field contains the number of rows in the header

rows
total

This field contains the total number of rows in the table bodies. So its value is an integer.

table
width

This field contains an integer representing the table width. However, the width here is in number of characters, not in pixel, so you would need to convert it. The conversion ratio is 8 pixels per character.

AUTHOR

Jacques Deguest <jack@deguest.jp>

COPYRIGHT & LICENSE

Copyright (c) 2020 DEGUEST Pte. Ltd.

You can use, copy, modify and redistribute this package and associated files under the same terms as Perl itself.