sanitize_msword 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/sanitize_msword.rb +38 -0
- data/spec/sanitize_msword_spec.rb +10 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7eb80e324e4faa2fdbe4098cd3ec15c6a7de81de
|
4
|
+
data.tar.gz: bf1fda5bf8ef592763dc3f297e0312d531960c55
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6f979263e7d905d7c94451b4c952b96e73fb0c9e2ac2573d74cc7264b22835ebea21a5d9fe11ebe7ab23edd731eeac7c286f00abd594d19dd28b33a9dc146314
|
7
|
+
data.tar.gz: 8028f0a3f0a2f668ce860f2ba5efb9bc11d1f72ff3c7bbd47fa40b44306828e1d24e095b66a2df714a4c8b9d1ab21c65afbff3f804309cd847417c53fb2d080d
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class String
|
2
|
+
def sanitize_word_html
|
3
|
+
gsub!(/\n|\r| class=(")?Mso[a-zA-Z]+(")?/){""}
|
4
|
+
gsub!(/<!--(.*?)-->/){""}
|
5
|
+
gsub!(/<!\[(.*?)\]>/){""}
|
6
|
+
gsub!(/<(\/)*(meta|link|div|span|\\?xml:|st1:|o:|font)(.*?)>/){""}
|
7
|
+
gsub!(/�/){""}
|
8
|
+
["style", "script", "applet", "embed", "noframes", "noscript"].map{|i| self.gsub!(/<#{i}.*?#{i}(.*?)>/){""} }
|
9
|
+
["style", "start"].map{|i| self.gsub!(/\s#{i}=\"(.*?)\"/){""} }
|
10
|
+
gsub!(/�/){'"'}
|
11
|
+
gsub!(/�/){'"'}
|
12
|
+
gsub!(/\s\s+/){""}
|
13
|
+
gsub!(/<p><\/p>/){""}
|
14
|
+
gsub!(/<\/h1><\/h1>/){""}
|
15
|
+
gsub!(/<\/h2><\/h2>/){""}
|
16
|
+
gsub!(/<\/h3><\/h3>/){""}
|
17
|
+
gsub!(/<\/h4><\/h4>/){""}
|
18
|
+
gsub!(/<\/h5><\/h5>/){""}
|
19
|
+
gsub!(/<\/h6><\/h6>/){""}
|
20
|
+
gsub!(/(<\/h[0-9]>)/){"#{$1}\n"}
|
21
|
+
gsub!(/(<h[0-9]>)/){" #{$1}"}
|
22
|
+
gsub!(/(<p>)/){" #{$1}"}
|
23
|
+
gsub!(/(<\/p>)/){"#{$1}\n"}
|
24
|
+
gsub!(/(<html>)/){"#{$1}\n"}
|
25
|
+
gsub!(/(<\/html>)/){"#{$1}\n"}
|
26
|
+
gsub!(/(<head>)/){"\n#{$1}\n"}
|
27
|
+
gsub!(/(<\/head>)/){"#{$1}\n"}
|
28
|
+
gsub!(/(<\/title>)/){"#{$1}\n"}
|
29
|
+
gsub!(/(<body>)/){"#{$1}\n"}
|
30
|
+
gsub!(/(<\/body>)/){"#{$1}\n"}
|
31
|
+
gsub!(/(<\/li>)/){"#{$1}\n"}
|
32
|
+
gsub!(/(<\/ul>)/){"#{$1}\n"}
|
33
|
+
gsub!(/(<ul>)/){"#{$1}\n"}
|
34
|
+
gsub!(/(<\/table>)/){"#{$1}\n"}
|
35
|
+
gsub!(/(<br(.*?)>)/){"#{$1}\n"}
|
36
|
+
self
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'sanitize_msword'
|
2
|
+
|
3
|
+
describe 'Dirty msword text' do
|
4
|
+
let(:dirty_html_example) {'<p class="MsoListParagraph">Some text</p>'}
|
5
|
+
|
6
|
+
it "should be cleared of the word special html" do
|
7
|
+
expect(dirty_html_example.sanitize_word_html).to match(/(?>(?!Mso[a-zA-Z]))/)
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sanitize_msword
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tatiana Podymova, Vladimir Suvorov, Igor Dranichnikov, Igor Lemeshkin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-14 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email: podymovat@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/sanitize_msword.rb
|
20
|
+
- spec/sanitize_msword_spec.rb
|
21
|
+
homepage: ''
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 2.4.5
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: Clean MS Word html
|
45
|
+
test_files:
|
46
|
+
- spec/sanitize_msword_spec.rb
|