Skip to content

Instantly share code, notes, and snippets.

View blackmambahk's full-sized avatar

robert.edgar blackmambahk

  • Hong Kong SAR China
View GitHub Profile
@honza
honza / strip.js
Created August 3, 2011 14:30
Strip MS Word formatting in javascript
// Source: http://www.1stclassmedia.co.uk/developers/clean-ms-word-formatting.php
function CleanWordHTML( str )
{
str = str.replace(/<o:p>\s*<\/o:p>/g, "") ;
str = str.replace(/<o:p>.*?<\/o:p>/g, "&nbsp;") ;
str = str.replace( /\s*mso-[^:]+:[^;"]+;?/gi, "" ) ;
str = str.replace( /\s*MARGIN: 0cm 0cm 0pt\s*;/gi, "" ) ;
str = str.replace( /\s*MARGIN: 0cm 0cm 0pt\s*"/gi, "\"" ) ;
str = str.replace( /\s*TEXT-INDENT: 0cm\s*;/gi, "" ) ;