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

COPYLEFT

AUBBC2.pm, v1.00 alpha 6 11/28/2011 By: N.K.A.

------------------>^- Yes this is a test version and is subjected to changes.

shakaflex [at] gmail.com

http://search.cpan.org/~sflex/

Advanced Universal Bulletin Board Code 2

BBcode Placeholders with HTML Template

SYNOPSIS

      use AUBBC2;
      $AUBBC2::MEMOIZE     = 1; # Module Speed
      @AUBBC2::TAGS        = ();# Tags
      %AUBBC2::regex       = ();# regex for add_tag()
      $AUBBC2::Config      = '';# Path to configuration file

      my $aubbc = AUBBC2->new();
      
      $aubbc->add_tag(
          'tag' => 'b|i', # b or i
          'type' => 'balanced',
          'function' => '',
          'message' => 'any',
          'extra' => '',
          'markup' => '<%{tag}>%{message}</%{tag}>',
        );
        
      my $message = '[b]Foo[/b]'; # bold tag
      print  $aubbc->parse_bbcode($message);

ABSTRACT

BBcode Placeholders with HTML Template

DESCRIPTION

The main concept for this is to parse bbcode to markup and give a lot of control over each tag designed through placeholders and templating the markup. As it is now the BBcode tags end up being a big list that can be saved in a back-end or configuration file to be parsed. The attributes syntax for 'extra' should help to reduce the need to do regular-expressions to validate attributes. Still under development so concept can change.

AUBBC vs AUBBC2

AUBBC = Has more time used in production and testing but does not fully support Strict markup.

AUBBC2 = Is an alpha version meaning any part of the program is subjected to changes and may not fully work or needs more testing.

This module can fully support BBcode to HTML/XHTML Strict. Block in Inline and incorrectly nested tags do not exists if you switch to CSS classes in DIV elements.

Testing

In this version all of the filters except for the script_escape and html_to_text are in the config file and the strip parser works. This list of methods are the focus of testing for this version. The methods with * should be low in testing priority or will work well.

# Parser's

parse_bbcode()

        single(
         'tag'       => '',  # Tag
         'function'  => '',  # Function
         'message'   => '',  # Message area of the tag
         'extra'     => '',  # Extra areas of the tag
         'markup'    => '',  # Tag Temptlate
         'parse'     => '',  # Parse Content & must script_escape for security
         );

balanced()

linktag()

strip()

# Editing tags

add_tag()

remove_tag()

clear_tags()

tag_list()

# %AUBBC settings editing

add_settings()

get_setting()

remove_setting()

# Error Messages *

error_message()

# filters *

script_escape()

html_to_text()

# Module version *

version()

Adding Tags

        $aubbc->add_tag(
          'tag' => 'Tag',               # Tag name:
          'type' => 'X',                # Type name: tag style
          'function' => '',             # Function: subroutine to expand methods
          'message' => 'any',           # Message: of tag
          'extra' => '',                # Extra: of tag
          'markup' => '',               # Template: output
        );

Type name: Tag style

single [tag]

balanced [tag]message[/tag] or [tag=extra]message[/tag] or [tag attr=x...]message[/tag] or [tag=x attr=x...]message[/tag]

linktag [tag://message] or [tag://message|extra]

strip replace or remove

Tag name: This allows a single tag added to change many tags and supports more complex regex:

        # This is an example of bold and italic in the same add_tag()
        # Tags: [b]message[/b] or [i]message[/i]
        # Output: <b>message</b> or <i>message</i>
        $aubbc->add_tag(
          'tag' => 'b|i', # b or i
          'type' => 'balanced',
          'function' => '',
          'message' => 'any',
          'extra' => '',
          'markup' => '<%{tag}>%{message}</%{tag}>',
        );

Function: The name gets check to make sure its a defined subroutine then gets passed these variables of the tag.

        sub new_function {
        # $tag, $message, $attrs are the captured group of its place
         my ($type, $tag, $message, $markup, $extra, $attrs) = @_;

         # expand functions....

         # A) if there is a $message and blank $markup the $message will replace the tag.
         # B) if there is both $message and $markup, then $message can be inserted
         # into $markup if $markup has %{message} or any "Markup Template Tags",
         # then markup will replace the tag.
         # C) if both are blank the tag doesnt change.

         return ($message, $markup);
         # May have to return more so we have better/more control
        }

Message: Allows regex or fast regex for 'any', 'href', 'src'

href-> protocal://location/web/path/or/file

src-> protocal://location/web/path/or/file or /local/web/path/or/file

Extra: supports -> any href src

Allows regex after tag= and message| or if negative pipe is in front will switch to the attribute syntax for attribute range matching.

Attributes syntax and rules:

-Rules

-1) -| must be at the beginning of 'extra'

-2) All attributes listed in 'extra' must be used at least one time for the tag to convert.

-3) The tag will not convert if an attribute is out of range

-4) Do not use extra delimiters like / and , in 'extra', use as needed.

Attribute syntax:

    -|attribute_name/switch{range},attribute_name2/switch{range}

Switches:

n{0-0000} = Number range n{1-10} means any number from 1 to 10

w{0000} = Word range character pre-set limit is '\w,.!?- ' w{5} means text 5 in length or less

w{xx|xx} = Word match w{This|That} will match 'This' or 'That' and supports regex in w{regex}

l{x-y} = Letter range with no length check l{a-c} means any letters from a to c

l{0000} = Length check l{5} means text 5 in length or less

note: usage of X{attribute_name} in the markup will be replaced with the value if everything is correct.

        # tag: [dd=Stuff 7 attr=33]stuff[/dd]
        # output: <dd attr="33" alt="Stuff 7">stuff</dd>
        $aubbc->add_tag(
          'tag' => 'dd',
          'type' => 'balanced',
          'function' => '',
          'message' => 'any',
          'extra' => '-|attr/n{20-100},dd/w{7}',
          'markup' => '<%{tag} attr="X{attr}" alt="X{dd}">%{message}</%{tag}>',
        );

        # tag: [video height=90 width=115]http://www.video.com/video.mp4[/video]
        # output: <video width="115" height="90" controls="controls">
        #<source src="http://www.video.com/video.mp4" type="video/mp4" />
        #Your browser does not support the video tag.
        #</video>
        $aubbc->add_tag(
          'tag' => 'video',
          'type' => 'balanced',
          'function' => '',
          'message' => 'src',
          'extra' => '-|width/n{90-120},height/n{60-90}',
          'markup' => '<video width="X{width}" height="X{height}" controls="controls">
        <source src="%{message}" type="video/mp4" />
        Your browser does not support the video tag.
        </video>',
        );

Markup:

This is the template of the tag and has tags of its own giving you more control

Markup Template Tags:

Tag: Info

%setting% Any setting name in AUBBC2's main setting hash %AUBBC

%{tag} Tag value

%{message} Message value

%{extra} Extra value for non-attribute syntax

X{attribute} Attribute names for values of attribute syntax

Development Guidance

http://www.perlmonks.com/

http://perldoc.perl.org/