chipplechipple

Blog - MT remove_html patch

Technology MT remove_html patch

Just fixed a little annoyance in my MovableType installation, and I realized it still exists in the most recent version (I still run the outdated 2.64 which has been serving me well), so I'm sharing it.

The remove_html global attribute removes anything that looks like a HTML element. This takes care of HTML comments that only contain text, but a commented out HTML element will result into something broken.
For example <!--Hello<br />World--> results in World-->.
This shows up in RSS feeds, etc.

I added a line to remove_html in Util.pm so that it strips out HTML comments first of all.
Here's my modified version.

sub remove_html {
    my($text) = @_;
    ## remove HTML comments
    $text =~ s/<!--.+?-->//gs;
    $text =~ s!<[^>]+>!!gs;
    $text =~ s!<!&lt;!gs;
    $text;
}

Posted on January 4, 2005 at 16:19 | Tweet |


Trackback


Comments RSS

Thanks for working this up and sharing it!

Posted by Sean on January 16, 2005 at 13:36


I'm glad if it helps!

Posted by Patrick on January 16, 2005 at 13:47



« The Nackens in Shibuya | Back to main page | Sonore »