Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/sanitize_msword.rb

Instance Method Summary collapse

Instance Method Details

#sanitize_word_htmlObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/sanitize_msword.rb', line 2

def sanitize_word_html
  #gsub!(/\n|\r| class=(")?Mso[a-zA-Z]+(")?/){""}
  #gsub!(/\&lt\;/){"<"}
  #gsub!(/\&gt\;/){">"}
  #gsub!(/\&nbsp\;/){" "}
  #gsub!(/<!--(.*?)-->/){""}
  #gsub!(/<!\[(.*?)\]>/){""}
  #gsub!(/<(\/)*(meta|link|div|span|\\?xml:|st1:|o:|font)(.*?)>/){""}
  #gsub!(/�/){""}
  #["style", "applet", "embed", "noframes", "noscript"].map{|i| gsub!(/<#{i}.*?#{i}(.*?)>/){""} }
  #["style", "start"].map{|i| gsub!(/\s#{i}=\"(.*?)\"/){""} }
  #gsub!(/�/){'"'}
  #gsub!(/(<script>)/){"&ltscript&gt"}
  #gsub!(/(<\/script>)/){"&lt/script&gt"}
  #gsub!(/�/){'"'}
  #gsub!(/\s\s+/){""}
  #gsub!(/<p><\/p>/){""}
  #gsub!(/<\/h1><\/h1>/){""}
  #gsub!(/<\/h2><\/h2>/){""}
  #gsub!(/<\/h3><\/h3>/){""}
  #gsub!(/<\/h4><\/h4>/){""}
  #gsub!(/<\/h5><\/h5>/){""}
  #gsub!(/<\/h6><\/h6>/){""}
  #gsub!(/(<\/h[0-9]>)/){"#{$1}\n"}
  #gsub!(/(<h[0-9]>)/){" #{$1}"}
  #gsub!(/(<p>)/){" #{$1}"}
  #gsub!(/(<\/p>)/){"#{$1}\n"}
  #gsub!(/(<html>)/){"#{$1}\n"}
  #gsub!(/(<\/html>)/){"#{$1}\n"}
  #gsub!(/(<head>)/){"\n#{$1}\n"}
  #gsub!(/(<\/head>)/){"#{$1}\n"}
  #gsub!(/(<\/title>)/){"#{$1}\n"}
  #gsub!(/(<body>)/){"#{$1}\n"}
  #gsub!(/(<\/body>)/){"#{$1}\n"}    
  #gsub!(/(<\/li>)/){"#{$1}\n"}
  #gsub!(/(<\/ul>)/){"#{$1}\n"}
  #gsub!(/(<ul>)/){"#{$1}\n"}
  #gsub!(/(<\/table>)/){"#{$1}\n"}
  #gsub!(/(<br(.*?)>)/){"#{$1}\n"}
  #self


  gsub!(/\n|\r| class=(")?Mso[a-zA-Z]+(")?/){""}
  gsub!(/\&lt\;/){"<"}
  gsub!(/\&gt\;/){">"}
  gsub!(/<!--(.*?)-->/){""}
  gsub!(/<!\[(.*?)\]>/){" "}
  gsub!(/<(\/)*(meta|link|div|span|\\?xml:|st1:|o:|font)(.*?)>/){""}
  gsub!(//){""}
  ["style", "script", "applet", "embed", "noframes", "noscript"].map{|i| gsub!(/<#{i}.*?#{i}(.*?)>/){""} }
  ["style", "start"].map{|i| gsub!(/\s#{i}=\"(.*?)\"/){""} }
  gsub!(//){'"'}
  gsub!(//){'"'}
  gsub!(/\s\s+/){""}
  gsub!(/<p><\/p>/){""}
  gsub!(/<\/h1><\/h1>/){""}
  gsub!(/<\/h2><\/h2>/){""}
  gsub!(/<\/h3><\/h3>/){""}
  gsub!(/<\/h4><\/h4>/){""}
  gsub!(/<\/h5><\/h5>/){""}
  gsub!(/<\/h6><\/h6>/){""}
  gsub!(/(<\/h[0-9]>)/){"#{$1}\n"}
  gsub!(/(<h[0-9]>)/){" #{$1}"}
  gsub!(/(<p>)/){" #{$1}"}
  gsub!(/(<\/p>)/){"#{$1}\n"}
  gsub!(/(<html>)/){"#{$1}\n"}
  gsub!(/(<\/html>)/){"#{$1}\n"}
  gsub!(/(<head>)/){"\n#{$1}\n"}
  gsub!(/(<\/head>)/){"#{$1}\n"}
  gsub!(/(<\/title>)/){"#{$1}\n"}
  gsub!(/(<body>)/){"#{$1}\n"}
  gsub!(/(<\/body>)/){"#{$1}\n"}    
  gsub!(/(<\/li>)/){"#{$1}\n"}
  gsub!(/(<\/ul>)/){"#{$1}\n"}
  gsub!(/(<ul>)/){"#{$1}\n"}
  gsub!(/(<\/table>)/){"#{$1}\n"}
  gsub!(/(<br(.*?)>)/){"#{$1}\n"}     
  self    
end