I pushed out a consept code for a new BBcode engine. Its main function gives the developer controle over many parts of the BBcode tags through its placeholders with HTML template design.
AUBBC2
One main reason why I posted this is to ask: Does this look easy to use?
Note: The add_tag() in alpha 3 doesnt work and Im sure a few other things.
Adding Tags
$aubbc->add_tag(
'tag' => 'Tag', # Tag name:
'type' => '#', # Type number: tag style
'function' => '', # Function: subroutine to expa
+nd methods
'message' => 'any', # Message: of tag
'extra' => '', # Extra: of tag
'markup' => '', # Template: output
);
Type number: Tag style
1 [tag]
2 [tag]message[/tag] or [tag=extra]message[/tag] or [tag attr=x...]message[/tag] or [tag=x attr=x...]message[/tag]
3 [tag://message] or [tag://message|extra]
4 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' => '2',
'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 wi
+ll 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 Templ
+ate 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 controle
}
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 atleast 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' => '2',
'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.m
+p4[/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' => '2',
'function' => '',
'message' => 'src',
'extra' => '-|width/n{90-120},height/n{60-90}',
'markup' => '<video width="X{width}" height="X{height}" cont
+rols="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 controle
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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.