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.
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);
- You’ll need this plugin and, if you don’t already have it, the Compare plugin.
- 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 . 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.
- 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.
Finally, you may need to adjust the
Sanitize
specification for your blog. Comments are run throughSanitize
, 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. MySanitize
specification now readsdiv 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
fromvarchar(255)
totext
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.
Re: Text Filters for Comments
Just for fun, here’s a mathematical comment
authored using the “itex to MathML with parbreaks” plugin.
Nifty, huh?