Skip to:
Content
Pages
Categories
Search
Top
Bottom

MathML and BBpress working together


  • dprice
    Member

    @dprice

    Being both a web nerd and Physics student, I decided it was time for BBpress to meet up with MathML.

    Here’s the steps I took to get it crankin':

    1. Made a copy of the default ‘kakumei’ template, then renamed the folder ‘physics’, my new template name. I then put a copy of ASCIImath.js in there. This does all the hard work.
    2. Changed the physics/header.php from:
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml" <?php bb_language_attributes( '1.1' ); ?>>

      to:

      <?xml version='1.0' encoding='iso-8859-1'?>
      <?xml-stylesheet type="text/xsl" href="http://www.w3.org/Math/XSL/mathml.xsl"?>

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg-flat.dtd" >

      <html xmlns="http://www.w3.org/1999/xhtml"
      xml:lang="en"
      xmlns:pref="http://www.w3.org/2002/Math/preference"
      pref:renderer="css">

      It’d probably still work if you didn’t bother with this step, but seeing as BBpress is making XML we may as well.

    3. Added <script type="text/javascript" src="<?php echo bb_path_to_url( dirname(__FILE__) . '/ASCIIMathML.js'); ?>"> to physics/header.php – this loads the ASCIIMathML.js javascript and does a majority of the MathML magic.
    4. Opened bb-includes/formattingfunctions.php and edited this:
      function code_trick( $text ) {
      $text = str_replace(array("rn", "r"), "n", $text);
      // $text = preg_replace("|<code>(.*?)</code>|e", "'<code>' . encodeit('$1') . '</code>'", $text);
      // $text = preg_replace("|n<code>(.*?)</code>|se", "'<pre><code>' . encodeit('$1') . '</code></pre>'", $text);
      return $text;
      }

      To turn off the backtick code replacement – this is what ASCIIMath.js does!

    That was it. I’ll zip it all up then post it up here. Ideally, it’d be better to not comment out any of the bb-include/ files – if anyone has any suggestions, let me know.

Viewing 5 replies - 1 through 5 (of 5 total)

  • dprice
    Member

    @dprice

    Oh yeah – you can have a play at http://www.thetelegraphic.com/bbpress/bbpress/

    That’s really just a sandbox for now and won’t be there forever.

    I’ll be releasing the black template it’s using too – It’s just Kakumei with a different colour scheme.


    dprice
    Member

    @dprice

    Get bbpress + mathML.

    This is really just a quick knockup – perhaps MathML support would be best in plugin form? I really didn’t do all that much, but I’m not familiar with the BBpress plugin system at all so I’m not sure how easy (if possible), it would be.


    fel64
    Member

    @fel64

    Thanks!

    You can include ASCIIMathML.js in the header via plugin by this sort of code:

    `function incMathJs() {

    $url = bb_path_to_url( dirname(__FILE__) . ‘/ASCIIMathML.js’)

    echo ‘<script type=”text/javascript” src=”‘ . $url . ‘”>';

    }

    add_action( ‘bb_head’, ‘incMathJs’ );

    Not sure when or how the JS kicks in, but perhaps that’s not necessary? Anyway, you could head over to trac and request that code_trick be made pluggable (so a plugin could overwrite it).


    dprice
    Member

    @dprice

    Ah – so ridiculously easy! I’m liking BBpress more and more ;).

    I just requested code_trick to become pluggable too – hopefully that’ll happen, and soon, so I can just use a plugin and not hack at core files.


    Trent Adams
    Member

    @trent

    Created a TRAC for it and it is in your other thread!

    Trent

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