NAME
Markdown::Parser::Element - Markdown Element Object Class
SYNOPSIS
my $o = Markdown::Parser::Code->new;
# or
$doc->add_element( $o->create_code( @_ ) );
VERSION
v0.3.0
DESCRIPTION
This is the base class from which all other elements inherit.
METHODS
add_attributes
Provided with an attributes definition string such as the one below, and this will parse it and set the corresponding classes and/or id for the element.
````` {.html #codeid}
<b>bold</b>
`````
Returns the current object for chaining.
add_element
Provided with an element object, and this will add it to the children stack.
my $bq = $doc->create_blockquote;
$bq->add_element( $doc->create_text( "Hello world" ) );
It sets the "parent" value of the object to the current object.
Returns the current object for chaining.
add_to
Provided with an element object, and this will add it to the children stack.
my $bq = $doc->create_blockquote;
my $txt = $doc->create_text( "Hello world" );
$txt->add_to( $bq );
as_markdown
Returns a string representation of the code formatted in markdown.
It returns a plain string.
as_pod
Returns a string representation of the code formatted in pod.
It returns a plain string.
as_string
Returns an html representation of the code.
It returns a plain string.
attr
Sets or gets the hash object used to contain the key-value pair for attributes.
Returns a Module::Generic::Hash object.
attributes
Alias for "attr"
base_class
Returns the computed base class for this object.
This is used to enable inheriting this class Module::Parser
children
Sets or get the array object containing all the element contained inside the object.
Returns a Module::Generic::Array object.
class
Read only. Returns the current class name for this object.
closest
Returns the closest element within an object children elements which is either anything but not non-new line element or the one specified, if found
create_abbreviation
Create a Markdown::Parser::Abbr object and return it.
create_blockquote
Create a Markdown::Parser::Blockquote object and return it.
create_bold
Create a Markdown::Parser::Bold object and return it.
create_checkbox
Create a Markdown::Parser::Checkbox object and return it.
create_code
Create a Markdown::Parser::Code object and return it.
create_em
Create a Markdown::Parser::Emphasis object and return it.
create_footnote
Create a Markdown::Parser::Footnote object and return it.
create_footnote_ref
Create a Markdown::Parser::FootnoteReference object and return it.
create_header
Create a Markdown::Parser::Header object and return it.
create_html
Create a Markdown::Parser::HTML object and return it.
create_image
Create a Markdown::Parser::Image object and return it.
create_insertion
Create a Markdown::Parser::Insertion object and return it.
create_line
Create a Markdown::Parser::Line object and return it.
create_link_definition
Create a Markdown::Parser::LinkDefinition object and return it.
create_link
Create a Markdown::Parser::Link object and return it.
create_list
Create a Markdown::Parser::List object and return it.
create_list_item
Create a Markdown::Parser::ListItem object and return it.
create_new_line
Create a Markdown::Parser::NewLine object and return it.
create_paragraph
Create a Markdown::Parser::Paragraph object and return it.
create_strikethrough
Create a Markdown::Parser::StrikeThrough object and return it.
create_subscript
Create a Markdown::Parser::Subscript object and return it.
create_superscript
Create a Markdown::Parser::Superscript object and return it.
create_table
Create a Markdown::Parser::Table object and return it.
create_table_body
Create a Markdown::Parser::TableBody object and return it.
create_table_caption
Create a Markdown::Parser::TableCaption object and return it.
create_table_cell
Create a Markdown::Parser::TableCell object and return it.
create_table_column
Create a Markdown::Parser::TableColumn object and return it.
create_table_header
Create a Markdown::Parser::TableHeader object and return it.
create_table_row
Create a Markdown::Parser::TableRow object and return it.
create_text
Create a Markdown::Parser::Text object and return it.
css
Sets or gets the CSS::Object object.
css_inline
Get a new CSS::Object with formater set to CSS::Object::Format::Inline
detach
Remove all the children element and returns them as an array object (Module::Generic::Array object)
dict
Sets or gets the dictionary hash object, which is a Module::Generic::Hash object.
It is used to contain word-definition pairs.
document
Sets or gets a Markdown::Parser::Document object.
empty
Empty the object of any children.
Returns the current object for chaining.
encode_html
Provided with an array reference of characters to encode and a string of text or a reference to a string of text, and this will encode those characters in their html entity equivalent. For example:
< => <
< => >
& => &
Returns the text encoded.
extract_links
Returns an array object of link objects
format_attributes
Provided with attributes object (Module::Generic::Hash) such as set by "attr" and this will retur a new Module::Generic::Array object of attribute name-attribute value pairs.
format_class
If "class" is set, then this will return a formatted class
attribute with the class separated by comma, otherwise it returns an empty string.
format_id
If "id" is set, then this will return a formatted id
attribute with its value set to the "id" value, otherwise it returns an empty string.
get_link_by_id
Provided with a link id, and this will return its corresponding value.
id
Sets or gets an array reference of id
attribute value.
Returns a Module::Generic::Array object.
insert_after
Provided with an element and this will add it to the stack of elements, right after the current object.
Returns the element object being added for chaining.
insert_before
Provided with an element and this will add it to the stack of elements, right before the current object.
Returns the element object being added for chaining.
links
Returns an array object of Markdown::Parser::Link objects.
look
my $array = $e->look(
tag => $tag,
# or 'up'
direction => 'down',
class => $class,
);
This will crawl the element tree in search of matching elements, and returns an array object.
Upon error, it sets an exception object and returns undef
in scalar context and an empty list in list context.
It takes the following options:
class
An element class.
direction
The direction to crawl. Either
down
orup
.tag
A tag to look for.
look_down
my $array = $e->look(
tag => $tag,
class => $class,
);
This will crawl down the element tree in search of matching elements, and returns an array object.
Upon error, it sets an exception object and returns undef
in scalar context and an empty list in list context.
It takes the following options:
class
An element class.
tag
A tag to look for.
look_up
my $array = $e->look(
tag => $tag,
class => $class,
);
This will crawl up the element tree in search of matching elements, and returns an array object.
Upon error, it sets an exception object and returns undef
in scalar context and an empty list in list context.
It takes the following options:
class
An element class.
tag
A tag to look for.
make_html_parser
Returns a HTML::TreeBuilder object with the proper parameters set. This means ignore_unknown set to false, store_comments set to true, no_space_compacting set to true, implicit_tags set to false, implicit set to true, and tighten set to false.
object_id
Returns the object reference id generated using "refaddr" in Scalar::Util
package
Returns the current object package name.
parent
Sets or gets the parent object for the current object.
The value provided must be a subclass of Markdown::Parser::Element
parse_html
Provided with some html data, and this will use a HTML::Object object to parse the data.
Returns the resulting HTML::Object::Document object, which inherits from HTML::Object::Element.
pos
Sets or get the current cursor position in the string being parsed, as a Module::Generic::Number object.
Returns the current value.
raw
Sets or gets the raw data found using regular expression and before any processing was made. This is used essentially for debugging.
The value is stored as a Module::Generic::Scalar object.
remove
Provided with an element object, and this will look up within all its children if it exists, and if it does, will remove it.
It returns the object removed.
When no value is provided, ie. when called in void context, this method will remove the current object from its parent.
remove_children
Remove all element objects contained.
tag_name
Sets or gets the tag name value as a Module::Generic::Scalar object.
wrap
Provided with an element object to wrap, and this will wrap all current elements contained using the wrapping object.
For example:
my $bq = $doc->create_blockquote;
$bq->add_element( $doc->create_text( "Hello world" ) ); # Hello world is now contained within the blockquotes
# Now, wrap Hello world inside a paragraph
$bq->wrap( $doc->create_paragraph );
# Data would now be <p>Hello world</p>
PRIVATE METHODS
_append_text
Provided with an element object, and this will ad it to the stack of children elements.
If the value provided is just a string, it will append it to the previous text element, if any, or create one
Returns the element object being added for chaining.
_create_element
This private method is used to create various elements. It is called from methods like "create_paragraph".
It will automatically load the module if not already loaded and instantiate an object, setting the debug value same as our current object.
SEE ALSO
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.