Skip to:
Content
Pages
Categories
Search
Top
Bottom

Add custom bbcode tags into BBcode lite

  • @thebreiflabb

    Member

    I have installed BBcode lite, and I want to add my own custom bbcode tag, I tried making my own plugin to allow [tex][/tex], though I can still not fully understand the preg_replace() function. Would be greatly appriciated with some help.

    What I am trying to achieve is:

    [tex]some code here[/tex]…

    The code in between the tags get’s converted to <img class=”latex-image” src=”/path/image.cgi?#code goes here with urlencoding#” alt=”” />

    If it’s not too complicated to make the standard plugin to put code tags from the bbcode tags into additional pre tags when outputted, that would be great too.

    [code] tags into additional pre tags when outputted, that would be great too.

Viewing 4 replies - 1 through 4 (of 4 total)
  • @thebreiflabb

    Member

    I made it work in a way using this:


    <?php
    /*
    Plugin Name: BBTexCode
    Description: [tex][/tex] to image
    Plugin URI:
    Author: Sondre Kjøniksen
    Version: 1.00
    */

    function bb_tex_replace( $text ) {
    $text = preg_replace('/[tex](.*?)[/tex]/ie', "'<img src="/cgi-bin/mathtex.cgi?'.rawurlencode('$1').'" align="middle" />'", $text);
    return $text;
    }
    add_filter('post_text', 'bb_tex_replace');
    ?>

    Though I still have a problem, it seems bbpress strips backslashes when adding the post to the DB. Is it possible to do so bbpress skips stripping backslashes from [tex][/tex] tags? At the moment it works if I write double backslashes like: [tex]\LaTeX \frac12[/tex] But it is kind of annyoing having to type double every time.

    @thebreiflabb

    Member

    I made it work in a way using this:


    <?php
    /*
    Plugin Name: BBTexCode
    Description: [tex][/tex] to image
    Plugin URI:
    Author: Sondre Kjøniksen
    Version: 1.00
    */

    function bb_tex_replace( $text ) {
    $text = preg_replace('/[tex](.*?)[/tex]/ie', "'<img src="/cgi-bin/mathtex.cgi?'.rawurlencode('$1').'" align="middle" />'", $text);
    return $text;
    }
    add_filter('post_text', 'bb_tex_replace');
    ?>

    Though I still have a problem, it seems bbpress strips backslashes when adding the post to the DB. Is it possible to do so bbpress skips stripping backslashes from [tex][/tex] tags? At the moment it works if I write double backslashes like: [tex]\LaTeX \frac12[/tex] But it is kind of annyoing having to type double every time.

    @thebreiflabb

    Member

    Edit, this seems to only apply when I use override posting restrictions from the admin-can-post-anything plugin.

    @thebreiflabb

    Member

    Edit, this seems to only apply when I use override posting restrictions from the admin-can-post-anything plugin.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
Skip to toolbar