SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Hybrid View

  1. #1
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Earth
    Posts
    739
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Showing BBcode in real time

    Hi,

    I have made a BBcode editor and would like to add a function so as the user types and adds bbcode to the text area, have it show the html below it in real time as they are typing.

    I beleave this would be possible using javascript?

    Thanks

  2. #2
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This might interest you, although that's markdown syntax, and not bbcode:
    http://www.attacklab.net/showdown-gui.html

  3. #3
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Earth
    Posts
    739
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Thats basically what I have. Im using BBcode tags in my text area and need then converted to html for the preview.

    Im guessing you could maybe use something like

    PHP Code:
            $BBCode = array(
            
    "[center]" => "<center>""[/center]" => "</center>"
            
    "[b]" => "<b>""[/b]" => "</b>"
            
    "[u]" => "<u>""[/u]" => "</u>",
            
    "[i]" => "<i>""[/i]" => "</i>"); 
    Within the javascript?


    Thanks

  4. #4
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As Raffles said, it's not as simple as that; If any tags are context-dependent (and some are), you need to write a parser.

  5. #5
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Earth
    Posts
    739
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Thats basically what I am after, I cant find the javascript that is associated to it tho ...


    Thanks

    *edit.. there was a post above here from a member then it got deleted?

  6. #6
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by _matrix_ View Post
    Hi,

    Thats basically what I am after, I cant find the javascript that is associated to it tho ...


    Thanks

    *edit.. there was a post above here from a member then it got deleted?
    Yeah that was me. I deleted it because I realised it was rather unhelpful because using innerHTML makes that kind of thing pretty easy.

    The JS can be found here: http://www.mikeindustries.com/blog/s...on-20060417.js look for ReloadTextDiv. There's also some inline JS in the HTML that it uses.

    For BBCode you'd have to write a parser. Maybe it could be done with a single regular expression if only certain simple HTML is allowed. If nesting tags can happen that adds another layer of complexity.

  7. #7
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Earth
    Posts
    739
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Great, so far I have:

    Code:
    <script type="text/javascript" LANGUAGE="Javascript">
    function textdiv()
    {
    var NewText = document.getElementById("text").value;
    NewText = NewText.replace(/\n/g, '<br />'); 
    var DivElement = document.getElementById("display");
    DivElement.innerHTML = NewText;
    }
    </script>
    I have buttons that add bbcode tags around the text. Is there away to use my existing code or do I have to write code into the javascript to convert tags?

    Thanks


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •