Skip to the Main Content

Note:These pages make extensive use of the latest XHTML and CSS Standards. They ought to look great in any standards-compliant modern browser. Unfortunately, they will probably look horrible in older browsers, like Netscape 4.x and IE 4.x. Moreover, many posts use MathML, which is, currently only supported in Mozilla. My best suggestion (and you will thank me when surfing an ever-increasing number of sites on the web which have been crafted to use the new standards) is to upgrade to the latest version of your browser. If that's not possible, consider moving to the Standards-compliant and open-source Mozilla browser.

May 19, 2003

Text Filters for Comments

One of my goals, in setting up this weblog, was to be able to enter equations and such. This works very nicely for entries. Unfortunately, comment-authors are not so lucky. They don’t have access to the itex2MML Text Filter (or any other Text Filters, except the default one set blog-wide for all comments).

Wouldn’t it be cool if comment-authors had the choice of Text Filters to apply to their comments?

I thought so, too. So now they can!

If you submit a comment on this weblog, you’ll notice a new popup selector for a Text Filter to apply to your comment. You can choose whichever one you find most convenient, including the itex to MathML with parbreaks filter, which is my personal favourite.

Here’s how it’s done.

  1. If you’re using MySQL, you’ll have to add a column to store the text filter to apply to each comment.

    alter table mt_comment add column comment_convert_breaks varchar(30);
  2. You’ll need this plugin and, if you don’t already have it, the Compare plugin.
  3. Next, you’ll need to run this patch on your MovableType installation (patch < CommentTextFilters.patch). If you’re using ThreadedComments, use this version of the patch instead. Those were for MovableType 2.6x. MovableType 3.1x users should download either CommentTextFilters3.14.patch or ThreadedCommentTextFilters3.14.patch .
  4. Now, alter your Comment-Entry form to add

     <label for="convert_breaks">Text Filter:  </label>
       <select id="convert_breaks" name="convert_breaks">
     <MTTextFilters>
        <option value="<MTFilterKey>" <MTIfEqual a="[MTFilterKey]" b="[MTDefaultCommentFilter]">selected="selected" </MTIfEqual> > <MTFilterLabel> </option>
     </MTTextFilters>
       </select><br />

    and add the line

      <input type="hidden" name="convert_breaks" value="<$MTCommentPreviewTextFilter$>" />
    

    or, better yet, the selector

      <label for="convert_breaks">Text Filter: </label><br />
      <select name="convert_breaks" id="convert_breaks">
    <MTTextFilters>
          <option value="<MTFilterKey>"  <MTIfEqual a="[MTFilterKey]" b="[MTCommentPreviewTextFilter]">selected="selected"</MTIfEqual> ><MTFilterLabel></option>
    </MTTextFilters>
      </select><br />

    to the form in your Comment-Preview Template and your Comment-Error Template.

  5. If you’re using my Comment Validation setup and are using my itex2MML Text Filter, you’ll need to get an updated version of my patch to MTValidate.
  6. Finally, you may need to adjust the Sanitize specification for your blog. Comments are run through Sanitize, which removes all of the HTML elements or attributes that you do not specifically allow. If you want commenters to be able to post MathML content, using itex2MML, you need to enlarge this set. My Sanitize specification now reads

    div class id,bdo,* dir xml:lang title,span,p,br/,a href target,
    abbr,acronym,b,u,i,strong,em,ul,ol,li,dl,dt,dd,sup,tt,
    sub,pre,blockquote,code,math xmlns display,
    mo lspace rspace fence separator stretchy maxsize minsize,
    mi mathvariant,msub,msup,msubsup,mfrac linethickness,mn,
    mstyle scriptlevel mathvariant mathcolor mathbackground
    displaystyle,mtext,mspace width height depth,msqrt,
    mmultiscripts,mprescripts/,none/,mroot,mphantom,
    merror,mover,munder,munderover,maction actiontype
    other selection,mtable align columnalign rowalign
    equalrows equalcolumns columnspacing rowspacing
    columnlines rowlines frame,mrow xmlns:xlink xlink:type
    xlink:href,mtr rowalign columnalign,mtd rowspan 
    columnspan rowalign columnalign, mpadded width

    where everything in red is a MathML tag or attribute. Since this is longer than 255 characters, I had to change blog_sanitize_spec from varchar(255) to text in my MySQL database.

Update: I forgot to say that I’ve releases a new version of my itex2MML plugin. This one strips carriage-returns, as the (Unix-based) itex2MML converter expects new lines to be delimited by the linefeed character. You’ll definitely need the new version to use that text filter in comments.

Update (5/30/2003): Yuan-Chung Cheng has a nice article on daisy-chaining Text Filters, for even more options. As an example, I’ve added a Textile+itex2MML Filter to this blog.

Update (6/13/2003): A tweak to the CommentPreview template. Added the selection attribute for <maction> to the Sanitize spec. I need to think about the other attribute for <maction>, which is officially deprecated in MathML 2.0, but is still used by itex2MML.

Update (2/6/2005): Patches which work with MT 3.1x and a small tweak to the sanitize spec.

P.S.:In case you were wondering at my curious obsession with Comment Validation, this is the reason why. It’d be foolish to open up this blog to MathML comments without some serious bullet-proofing.

Posted by distler at May 19, 2003 12:47 PM

TrackBack URL for this Entry:   http://golem.ph.utexas.edu/cgi-bin/MT-3.0/dxy-tb.fcgi/165

11 Comments & 2 Trackbacks

Re: Text Filters for Comments

Just for fun, here’s a mathematical comment

(1) e x 2dx=π\int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi}

authored using the “itex to MathML with parbreaks” plugin.

Nifty, huh?

Posted by: Jacques Distler on May 19, 2003 1:07 PM | Permalink | Reply to this

Re: Text Filters for Comments

Hmmm…

▿⋅J+ρt=0

Holy crap, it works!

Well… actually, I laboriously crafted the markup for the equation by hand. (ducks and hides)

Posted by: Evan on May 19, 2003 8:05 PM | Permalink | Reply to this

Re: Text Filters for Comments

You are a masochist, aren’t you?

(1)J+ρt=0 &Del; \cdot J + \frac{&PartialD; \rho}{&PartialD; t} = 0

is best written as

\[
&Del; \cdot J + \frac{&PartialD; \rho}{&PartialD; t} = 0
\]

You should be able to write \partial instead of &PartialD; and \nabla instead of &Del;. The fact that you can’t (and, indeed that \partial gets translated into &partial;, which the W3C Validator says is incorrect) are bugs in itex2MML. I’ll report them to Paul Gartside.

Posted by: Jacques Distler on May 19, 2003 9:54 PM | Permalink | Reply to this

Re: Text Filters for Comments

I’ve updated itex2MML. So now \nabla \cdot J + \frac{\partial \rho}{\partial t} = 0 does just what you’d expect. (I also added \Del as an alias of \nabla.)

Posted by: Paul Gartside on May 20, 2003 9:41 AM | Permalink | Reply to this

Re: Text Filters for Comments

Quick work! Thanks, Paul.

But let’s not just tell the people; let’s show them:

(1)J+ρt=0 \nabla \cdot J + \frac{\partial \rho}{\partial t} = 0

Yup,

\[
\nabla \cdot J + \frac{\partial \rho}{\partial t} = 0
\]

works as it should!

I have updated my itexToMML package accordingly.

Posted by: Jacques Distler on May 20, 2003 10:00 AM | Permalink | Reply to this

Re: Text Filters for Comments

Just noticed as I was implementing this on a new home for my site…

In the patch you have a section in there, the first chuck of lib/MT/App/Comments.pm (line 65 of Comments.pm), that I believe is from your Validation check. (if not validated and attempt posting = IP Ban)

Thanks for the patches by the way!

Posted by: Eric on March 5, 2004 8:18 PM | Permalink | Reply to this

my bad!

Eeek!

My system is so hacked, it’s hard to keep the patches straight.

I removed that chunk because, as you say, it belongs to a piece of my comment-validation setup (one that I haven’t written up for public consumption; and it’s not even the current, much better version of that setup). It’s not part of the comment-text-filters setup.

Posted by: Jacques Distler on March 5, 2004 8:54 PM | Permalink | PGP Sig | Reply to this

Patch FIle and MT 3.x

Sorry for bothering you so much, but I am having trouble figuring out where lib/MT/App/Comments.pm is supposed to be modified. The CommentTextFilters.patch file is for MT 2.x I believe and does not work automatically with MT 3.x. It was easy to figure out the chamges in lib/MT/Comment.pm and lib/MT/Template/Context.pm but not Comments.pm. Some help would be appreciated.

Posted by: Zack on February 5, 2005 10:22 PM | Permalink | PGP Sig | Reply to this

Re: Patch FIle and MT 3.x

Here is the diff for my attempt to modify lib/MT/App/Comments.pm for the text filters. I am using MT 3.14.

--- Comments.pm Sat Feb  5 19:43:22 2005
+++ Comments.pm.new     Sat Feb  5 22:23:01 2005
@@ -440,6 +440,7 @@
     $comment->email(remove_html($email));
     $comment->url(MT::Util::is_valid_url($url, 'stringent'));
     $comment->text($q->param('text'));
+    $comment->convert_breaks($q->param('convert_breaks'));
     
     return ($comment, $commenter);
 }
@@ -857,6 +858,7 @@
         IfCommenterPending => $cmntr && ($cmntr->status($blog->id) == PENDING),
         IfNeedEmail => $blog->require_comment_emails,
     );
+    $ctx->stash('convert_breaks', $q->param('convert_breaks'));
     my $tmpl = ($q->param('arch')) ?
         (MT::Template->load({ type => 'individual',
                                         blog_id => $entry->blog_id })

It seems to me that the 2 lines of code added and 2 lines modified has changed to 2 lines added now.

I haven’t tested it out since I have no clue what I am doing other than looking hard at original code and the patch.

Posted by: Zack on February 6, 2005 12:34 AM | Permalink | PGP Sig | Reply to this

Re: Patch FIle and MT 3.x

See the updated patches in the main text above. But, yeah, that looks right to me.

Posted by: Jacques Distler on February 6, 2005 12:42 AM | Permalink | PGP Sig | Reply to this

Re: Patch FIle and MT 3.x

Thanks for the quick response.

Posted by: Zack on February 7, 2005 1:02 AM | Permalink | PGP Sig | Reply to this
Read the post Front-end and Back-end Changes
Weblog: Procrastination
Excerpt: There have been a lot of changes here recently, most of them on the back-end. Most of this work was related to having a bilingual (English and Urdu) blog along with MathML equations. This required valid XHTML 1.1 and serving...
Tracked: February 11, 2005 8:25 AM
Read the post Are You Being Served -- Part III
Weblog: Upon Reflection
Excerpt: In Part I, we discussed how to validate your web site and configure your server to send math-able web pages.
Tracked: October 5, 2005 2:57 PM

Post a New Comment