Simple BBTag Parser

Small, short code snippets that other people may find useful. Do you have a good regex that you would like to share? Share it! Even better, the code can be commented on, and improved.

Moderator: General Moderators

sean-xd
Forum Newbie
Posts: 1
Joined: Wed Sep 10, 2008 8:03 pm

Re: Simple BBTag Parser

Post by sean-xd »

hi new to this site

how could i impliment this code into nanocms?

my php knowlage isnt great.

this is the code that puts the text on the page

Code: Select all

 
function show_content_slug()
{
    global $cap;
    $slug = $cap->slug;
    $contentFile = pageDataDir( $slug );
    if( file_exists( $contentFile ) ) {
        runTweak( 'slug_load_before' );
        require_once( $contentFile );
        runTweak( 'slug_load_after' );
    }
    else {
        header("HTTP/1.0 404 Not Found");
        echo "404 : File Requested was Not Found";
    }
}
 
thanks in advance
sean
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: Simple BBTag Parser

Post by s.dot »

Hey Chris,

I am using your BBCode parser (posted on page one, after mine).. works great! Yours is way better. I've extended the functionality to include size, color, center, right, marquee, and youtube (you know, annoying things)

However I've noticed that if a certain tag doesn't have the correct opening and closing tags, none of the same tags will get parsed. Is this easily fixable?

I've tried for days now but no luck. It is a bit complicated (for me).

For example:

Code: Select all

[ i ]italics[ /i ] [ i ] no closing tag here
This would not parse anything although I believe the first one should be parsed.

I tried editing the checkClosure() method to add tags that were open.. but no luck :(
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Simple BBTag Parser

Post by Christopher »

I don't think Corbyn checks in much these days. From looking at his code, I don't think malformed tags like "[ i ]" will work.
(#10850)
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: Simple BBTag Parser

Post by s.dot »

I did that so the board wouldn't parse it

but i wrote my own parser that will just match the start tag through to the end tag and replace
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Simple BBTag Parser

Post by josh »

Surely there is lots that could be re-factored, but since when has BBcode had to change? If it aint broke don't fix it! (if it has to be changed often then by all means refactor the hell out of it)
-- directed at @arborint (even tho your response are excellent advice for learning about refactoring & good practices)

Based on that note I'd change the find & replace arrays to be only ONE array, and use key() and current() to read them out. That way you don't have to jump like 20 lines of code to match them up

array(
'find1',
'find2'
)

array(
'replace1'
'replace'2
)

change to

array(
'find1' => 'replace1',
'find2' => 'replace2'
)

Image
Forumguru
Forum Newbie
Posts: 10
Joined: Sat Jul 31, 2010 7:15 am

Re: Simple BBTag Parser

Post by Forumguru »

While designing a good layout for a webpage, sometimes we need to convert bbcode tag to html and vice versa. Thanks for such simple and yet simple bb tag parser to convert common bb tags to html, and vice versa. Wish you best of luck as a professional coder.
Post Reply