New 2011 FluxBB Parser

Documantation and Test Sandbox.

You are not logged in.

#1 2011-01-22 19:23:48

Admin
Administrator
Registered: 2011-01-22
Posts: 20

Features in a Nutshell

This thread highlights the new parser features.

  • Textile extensions.

  • Code syntax highlighting.

  • Error reporting.

  • New tags.

  • New attributes.

Offline

#2 2011-01-22 19:50:29

Admin
Administrator
Registered: 2011-01-22
Posts: 20

Re: Features in a Nutshell

Textile extensions.

You can use the following textile shortcuts when composing a post:

Phrase elements:
This is regular text and _this is emphasized_ and *this is strong* and @this is inline code@. And you can do super^script^ and you can do sub~script~ as well as -deleting- text and +inserting+ text.

Bulleted and numbered lists:
* Item one.
* Item two.
# Number one.
# Number two.

When you press preview, it looks like this:

Phrase elements:
This is regular text and this is emphasized and this is strong and this is inline code. And you can do superscript and you can do subscript as well as deleting text and inserting text.

Bulleted and numbered lists:

  • Item one.

  • Item two.

  1. Number one.

  2. Number two.

The textile markup lives for only a brief moment before the pre-parser converts it to bbcode and places it in the textarea input box (the Textile markup is not stored in the database.):

Phrase elements:
This is regular text and [i]this is emphasized[/i] and [b]this is strong[/b] and [tt]this is inline code[/tt]. And you can do super[sup]script[/sup] and you can do sub[sub]script[/sub] as well as [del]deleting[/del] text and [ins]inserting[/ins] text.
Bulleted and numbered lists:
[list]
[*]Item one.[/*]
[*]Item two.[/*]
[/list]
[list=1]
[*]Number one.[/*]
[*]Number two.[/*]
[/list]

Offline

#3 2011-01-22 19:58:30

Admin
Administrator
Registered: 2011-01-22
Posts: 20

Re: Features in a Nutshell

Code syntax highlighting.

You can write a simple CODE tag with no attribute which looks like so:

[code]This is some simple code[/code]

You can add a title message to the code block by adding an attribute to the CODE tag like so:

Code: "This is a code block title."

[code=This is a code block title.]This is some code with a message attribute.[/code]

You can specify a computer language as the first word of the attribute (such as "php"), and the message will have color syntax highlighting applied like so:

Code: PHP - "New FluxBB parser.php Rev:20110122_1800"

<?php ...edited...
//
// Helper preg_replace_callback function for smilies processing.
//
function _do_smilies_callback($matches) {
	global $g;
	return $g['smilies'][$matches[0]]['html'];
}
//
// Parse message text
//
function parse_message($text, $hide_smilies) {
	global $g, $pun_config, $pun_user;
	$g['in_signature'] = FALSE;
	// Disable images via the $bbcd['in_post'] flag if globally disabled.
	if ($pun_config['p_message_img_tag'] !== '1' || $pun_user['show_img'] !== '1')
		if (isset($g['bbcd']['img'])) $g['bbcd']['img']['in_post'] = FALSE;
	return parse_bbcode($text, $hide_smilies);
}
//
// Parse signature text
//
function parse_signature($text) {
	global $g, $pun_config, $pun_user;
	$g['in_signature'] = TRUE;
	// Disable images via the $bbcd['in_sig'] flag if globally disabled.
	if ($pun_config['p_sig_img_tag'] !== '1' || $pun_user['show_img_sig'] !== '1')
		if (isset($g['bbcd']['img'])) $g['bbcd']['img']['in_sig'] = FALSE;
	return parse_bbcode($text);
}
?>

The above PHP code is colorized using the open source "SyntaxHighlighter" Javascript scripts. There are quite a few syntaxes supported including: applescript, as3, bash, coldfusion, c, cpp, csharp, css, delphi, diff, erlang, groovy, java, javafx, js, jscript, perl, php, plain, powershell, python, ruby, sass, scala, sql, vb and 'xml'.

There is an additional dynamic syntax highlighting script for Perl Compatible Regular Expressions (DynamicRegexHighlighter). This script provides mouseover effects which highlight nested grouping brackets. Here is the main regex from the new parser:

Code: Regex (PCREx) - "The One Regex to match them all."

're_bbcode'	=> '% # re_bbcode Rev:20110202_1500
# First, match opening tag of syntax: "[TAGNAME (= ("\')ATTRIBUTE("\') )]";
\[                              # Match opening bracket of outermost opening TAGNAME tag.
(?>(b|code|color|colour|del|email|em|h|img|ins|i|list|\*|quote|sub|sup|s|tt|url|u|vimeo|youtube|err|dbug)\s*+) # $1:
(?>                             # Atomically group remainder of opening tag.
  (?:                           # Optional attribute.
    (=)\s*+                     # $2: = Optional attribute\'s equals sign delimiter, ws.
    (?:                         # Group for 1-line attribute value alternatives.
      \'([^\'\r\n\\\\]*+(?:\\\\.[^\'\r\n\\\\]*+)*+)\'  # Either $3: == single quoted,
    | "([^"\r\n\\\\]*+(?:\\\\.[^"\r\n\\\\]*+)*+)"      # or     $4: == double quoted,
    | ( [^[\]\r\n]*+            # or $5: == un-or-any-quoted. "normal*" == non-"[]"
        (?:                     # Begin "(special normal*)*" "Unrolling-the-loop" construct.
          \[[^[\]\r\n]*+\]      # Allow matching [square brackets] 1 level deep. "special".
            [^[\]\r\n]*+        # More "normal*" any non-"[]", non-newline characters.
        )*+                     # End "(special normal*)*" "Unrolling-the-loop" construct.
      )                         # End $5: Un-or-any-quoted attribute value.
    )                           # End group of attribute values alternatives.
    \s*+                        # Optional whitespace following quoted values.
  )?                            # End optional attribute group.
  \]                            # Match closing bracket of outermost opening TAGNAME tag.
)                               # End atomic group with opening tag remainder.
# Second, match the contents of the tag.
(                               # $6: Non-trimmed contents of TAGNAME tag.
  (?>                           # Atomic group for contents alternatives.
    [^\[]++                     # Option 1: Match non-tag chars (starting with non-"[").
    (?:                         # Begin "(special normal*)*" "Unrolling-the-loop" construct.
      (?!\[/?+\1[\]=\s])\[      # "special" = "[" if not start of [TAGNAME*] or [/TAGNAME].
      [^\[]*+                   # More "normal*".
    )*+                         # Zero or more "special normal*"s allowed for option 1.
  | (?:                         # or Option 2: Match non-tag chars (starting with "[").
      (?!\[/?+\1[\]=\s])\[      # "special" = "[" if not start of [TAGNAME*] or [/TAGNAME].
      [^\[]*+                   # More "normal*".
    )++                         # One or more "special normal*"s required for option 2.
  | (?R)                        # Or option 3: recursively match nested [TAGNAME]..[/TAGNAME].
  )*+                           # One of these three options as many times as necessary.
)                               # End $6: Non-trimmed contents of TAGNAME tag.
# Finally, match the closing tag.
\[/\1\s*+\]                     # Match outermost closing [/  TAGNAME  ]
                                %ix',

Offline

#4 2011-01-22 20:36:53

Admin
Administrator
Registered: 2011-01-22
Posts: 20

Re: Features in a Nutshell

Error reporting.


When attempting to post a message having BBCode syntax errors, a message preview is presented with the erroneous tags highlighted in red. Placing the mouse cursor over these red tags reveals helpful tooltip error messages. Here is an example which attempts to demonstrate every error recognized by the parser:

Error 1.  [b=b has no attribute]This is bold[/b]
Error 2.  [list=x]stuf inside a list[/list]
Error 3.  [dbug]These require message in attribute[/dbug]
Error 4.  [url=http://jmrware.com]link [url=http://jmrware.com]nested link text[/url]  text[/url]
Error 5.  [url=http://jmrware.com]link [url=http://jmrware.com]nested link text[/url] text[/url]
Error 6.  [url=http://jmrware.com]link [quote]nested link text[/quote] text[/url]
Error 7.  [*]This ain't gonna happen.[/*]
Error 8a.  [img]xyzcorp@gizko[/img]
Error 8b.  [url=xyzcorp@gizko]Link text[/url]
Error 9. [color=#FFxF]This is color xyz[/color]
Error 10. [youtube]This is not valid youtube content![/youtube]
Error 11. cannot reproduce this error.
Error 12. cannot reproduce this error.
Error 13. [img]http://www.jmrware.com/[/img]
Error 14. [img]http://jmrware.com/non-existant-file.txt[/img]
Error 15. cannot reproduce this error.
And you CAN SET YOUR OWN ERROR MESSAGES!

Offline

#5 2011-01-24 13:23:28

Admin
Administrator
Registered: 2011-01-22
Posts: 20

Re: Features in a Nutshell

Old BBCodes:

These are all the tags currently recognized by FluxBB 1.4.3:

This is a plain quote with no attribute.

quote attribute wrote:

This is a quote with a "quote attribute" attribute.

This line has bold text.
This line has italic text.
This line has underlined text.
This line has strike text.
This line has deleted text.
This line has inserted text.
This line has emphasized text.
This line has colored text.
This line has coloured text.
This line has http://jmrware.com a no-attribute URL.
This line has an attribute URL.
This line has jmr@example.com a no-attribute email.
This line has an attribute email.
Default bulleted list: no-attribute

  • one

  • two


Bulleted list: attribute='*'

  • one

  • two


Numeric list: attribute='1'

  1. one

  2. two


Alpha list: attribute='a'

  1. one

  2. two


This is code

This line has an image: http://jmrware.com/articles/2001/phyn/LonePeak.jpg

Offline

#6 2011-01-27 00:26:13

Admin
Administrator
Registered: 2011-01-22
Posts: 20

Re: Features in a Nutshell

Enhanced BBCodes:
  1. Quote tags are now, by default, linkified back to the original. This behavior is controlled via the new: "Linkify QUOTE citation" parser option. When ON, a quoted post links back to the original like so:

    Admin wrote:

    This thread highlights the new parser features.

    • Textile extensions.

    • Code syntax highlighting.

    • Error reporting.

    • New tags.

    • New attributes.

  2. The graphical display of images within quotes is controlled via new parser admin config option: "Display QUOTE images". When this option is off, then images within quotes are NOT show graphically, but rather as text hyperlinks to the original.

    Admin wrote:

    This is an image: {image} inside a quote.

  3. The COLOR (and COLOUR) tags now allow specifying both the forground and background colors. To set both, specify the foreground color first followed by the background color second separated by a semi-colon like so: color=#000;#FFF or color=#FFCC00;green or color=white;purple or color=purple;white. Note also that the color value can be one of the recognized CSS color names (English): maroon, red, orange, yellow, olive, purple, fuchsia, white, lime, green, navy, blue, aqua, teal, black, silver, or gray.

  4. The CODE tag allows an attribute which may contain a computer language specified as the first word. Syntax highlighting is applied for known languages.

    Code: "C" - "The classic "Hello World" program:"

    #include <stdio.h>
    void main(void) {
        printf("Hello, world.");
    }
  5. During pre-parsing, the remote image files of IMGs tags are checked. The remote image is queried to verfy that its Content-Type is "image" and its size is less than the parser option: "max_size". If the "valid_imgs" option is set to yes, then images with dimensions greater than the default are scaled down to fit within the default box.

Offline

#7 2011-01-27 02:25:15

Admin
Administrator
Registered: 2011-01-22
Posts: 20

Re: Features in a Nutshell

New BBCodes:
  1. TT - "Teletype" inline CODE tag. This line has [tt] - "Teletype" inline CODE where anything goes [i]even[/i] [b]tags[/b] (just like the [code] block code.{/code] tag).[/tt].

  2. SUP - Super-script tag. This line has the SUP tag for superscript.

  3. SUB - Sub-script tag. This line has the SUB tag for subscript.

  4. ERR - Error tag. This is used to identify bad BBcode markup. The offending tags are wrapped in the ERR tags like so: [BADTAG]Bad tag markup[/BADTAG]

  5. DBUG - Debug tag. This block tag provides a place to write debug information. For example:

    This is some debug content.

  6. Video: YOUTUBE & VIMEO - Embedded video player.
    youtube: and vimeo: .

Basically, these and any other tags you would like to add (or remove) are available. Although most useful codes are already provided by default, adding a new one is as easy as editing the bbcd_source.php and adding a new member to the $bbcd global array. Tags can be removed by deleting or commenting them out from this file.

Adding a simple new inline tag:

Lets say you want: "V" to represent html element "VAR" (i.e. The parser will convert: "[v]$variable[/v]", into: "<var>$variable</var>". Implementing this is easy. Edit: include/bbcd_source.php and add the following member to the $bbcd array.

    'v' => array(
        'html_name' => 'var'
    ),

Go to the Parser admin panel and click: "Reset". This re-compiles the source BBCode data file into the runtime cache file.
You're done. That's all there is to it.

Adding a new tag which takes an attribute:

But lets say you also want to be able to specify an optional attribute with this tag that is transformed into a tooltip (i.e. html TITLE atttribute message that appears when moused over). This involves writing format conversion strings (which use a simplified printf-like syntax). The %a_str% and %c_str% tokens are replaced with the actual attribute and contents of the tag. Here are the format strings we'll use for our enhanced var tag:

  'v' => array(
        'html_name'             => 'var',
        'handlers'              => array(
            'ATTRIB'            => array(
                'format'        =>
                    '<var title="%a_str%">%c_str%</var>'
            ),
            'NO_ATTRIB'         => array(
                'format'        =>
                    '<var>%c_str%</var>'
            )
        )
    ),

The NO_ATTRIB handler is used when there is no attribute provided and the ATTRIB handler is used when an attribute is present. There are other properties that can be set when specifying a new tag. Read the $bbcd documentation for more.

Offline

#8 2011-01-31 23:55:09

Admin
Administrator
Registered: 2011-01-22
Posts: 20

Re: Features in a Nutshell

New Attributes:

The new parser provides enhanced tag attributes.
First, there are three ways the parser can deal with a tag's attributes:

  1. Attribute is forbidden.

  2. Attribute is optional.

  3. Attribute is required.

These three cases are handled with the tag's ATTRIB and NO_ATTRIB handlers.

  • You can add a language as the first word of an attribute for the CODE tag.

  • You can add a "width=640 height=480" to an IMG tag's attribute. Or variations including: "w=640", "h=480" or "640x480".

  • You can add the originating post number to a QUOTE attribute and it will make the quote citation a link back to the original.

Offline

Board footer

Powered by FluxBB 1.4.5