How do I remove CSS from a string?

user2270029

I've used the Sanitize Ruby gem with the following code:

result = Sanitize.clean(html)

It pulls the content from the page, but I still have this CSS in the sanitized result. How do I get rid of it so I just have the page text?

#fsb-social-bar { width: 100%; border-bottom: 1px solid #dbdbdb; border-top: 1px solid #dbdbdb; padding: 10px 0; margin: 0px 0 20px 0; float: left; background: #fff; position: relative; clear: both; } #fsb-social-bar a { border: 0px !important } #fsb-social-bar.fsb-fixed { position: fixed; top: -2px; z-index: 99999; } #fsb-social-bar .fsb-title { display: block; float: left; margin: 3px 20px 0 0; font-size: 16px; font-family: Arial, Helvetica, sans-serif; text-decoration: none; color: #333; } #fsb-social-bar .fsb-share-facebook { width: 120px; float: left; padding: 3px 0 2px; height: 25px; } #fsb-social-bar .fsb-share-facebook.fsb-hide-count { width: 44px; overflow: hidden; margin-right: 30px; } #fsb-social-bar .fsb-share-twitter { float: left; width: 135px; padding: 3px 0 2px; height: 25px; } #fsb-social-bar .fsb-share-twitter.fsb-hide-count { width: 61px; overflow: hidden; margin-right: 30px; } #fsb-social-bar .fsb-share-google { float: left; width: 105px; padding: 3px 0 2px; height: 25px; } #fsb-social-bar .fsb-share-google.fsb-hide-count { width: 33px; overflow: hidden; margin-right: 30px; } #fsb-social-bar .fsb-share-linkedin { float: left; width: 135px; padding: 3px 0 2px; height: 25px; } #fsb-social-bar .fsb-share-linkedin.fsb-hide-count { width: 61px; overflow: hidden; margin-right: 30px; } #fsb-social-bar .fsb-share-pinterest { float: left; width: 115px; padding: 3px 0 2px; height: 25px;} #fsb-social-bar .fsb-share-pinterest.fsb-hide-count { width: 43px; overflow: hidden; margin-right: 30px; } #fsb-social-bar .socialite { display: block; position: relative; background: url(http://www.example.net/wp-content/plugins/floating-social-bar/images/fsb-sprite.png) no-repeat scroll 0 0; } #fsb-social-bar .socialite-loaded { background: none !important; } #fsb-social-bar .fsb-service-title { display: none; } #fsb-social-bar a { color: #333; text-decoration: none; font-size: 12px; font-family: Arial, Helvetica, sans-serif; } #fsb-social-bar .fsb-twitter { width: 105px; height: 25px; background-position: -13px -10px; line-height: 25px; vertical-align: middle; } #fsb-social-bar .fsb-twitter .fsb-count { width: 30px; text-align: center; display: inline-block; margin: 0px 0 0 69px; color: #333; } #fsb-social-bar .fsb-google { width: 75px; height: 25px; background-position: -136px -10px; line-height: 25px; vertical-align: middle; } #fsb-social-bar .fsb-google .fsb-count { width: 30px; text-align: center; display: inline-block; margin: 0px 0 0 41px; color: #333; } #fsb-social-bar .fsb-google .socialite-button { margin: 0 !important; } #fsb-social-bar .fsb-share-google .socialite-loaded .socialite-button{padding: 2px 0 0} #fsb-social-bar .fsb-facebook { width: 89px; height: 25px; background-position: -231px -10px; line-height: 25px; vertical-align: middle; } #fsb-social-bar .fsb-facebook .fsb-count { width: 30px; text-align: center; display: inline-block; margin: 0px 0 0 52px; color: #333; } #fsb-social-bar .fsb-facebook .socialite-button { margin: 0 !important;} #fsb-social-bar .fsb-share-facebook .socialite-loaded .socialite-button {padding: 2px 0 0} #fsb-social-bar .fsb-linkedin { width: 105px; height: 25px; background-position: -347px -10px; line-height: 25px; vertical-align: middle; } #fsb-social-bar .fsb-linkedin .fsb-count { width: 30px; text-align: center; display: inline-block; margin: 0px 0 0 70px; color: #333; } #fsb-social-bar .fsb-linkedin .socialite-button { margin: 0 !important; } #fsb-social-bar .fsb-pinterest { width: 88px; height: 25px; background-position: -484px -10px; line-height: 25px; vertical-align: middle; } #fsb-social-bar .fsb-pinterest .fsb-count { width: 30px; text-align: center; display: inline-block; margin: 0px 0 0 50px; color: #333; } #fsb-social-bar .fsb-pinterest .socialite-button { margin: 0 !important; } #fsb-social-bar .fsb-clear { clear: both; } #fsb-social-bar .fsb-clear:after { clear:both; content:; display:block; height:0; line-height:0; overflow:auto; visibility:hidden; zoom:1; } @media (max-width: 768px) { #fsb-social-bar.fsb-fixed { position: relative !important; top: auto !important; } } Facebook2 Twitter1 Google+0 LinkedIn0 Pinterest0 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras at nisl auctor, dignissim odio vel, suscipit velit. Vivamus pretium velit quis sapien scelerisque ullamcorper. Vivamus ullamcorper lacus non magna suscipit laoreet. In hac habitasse platea dictumst. Nulla aliquam dolor nec neque auctor pretium. Nullam vitae enim nisl. In imperdiet lacinia nunc at congue. Aliquam posuere nulla vel ornare accumsan. Fusce vitae sapien et nulla fringilla congue quis eu tellus. Nunc vestibulum turpis eget convallis cursus. Integer ut sapien molestie odio interdum luctus. Vestibulum urna justo, sagittis ut sodales eu, rutrum a magna. Proin consequat convallis nibh vel semper. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Pellentesque eu purus quis massa lobortis eleifend.

The solution needs to work on not only this text, but any string that could happen to have CSS. Thanks for your help.

Farkhat Mikhalko

If your CSS code is inside a style tag, you can use this one:

Sanitize.clean(content, :remove_contents => ['script', 'style'])

Other solution is css_transformer.rb.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How Do I Remove A Vowel From String

From Dev

How do i remove chars from a string?

From Dev

How do I remove punctuaution from a string

From Dev

how do i remove a letter from string

From Dev

How do I remove a character from a string in a Unix shell script?

From Dev

How do I remove multiple offending characters from my string?

From Dev

How do I remove all occurrences of a specific char from a string?

From Dev

How do I remove \r\n from string in C#?

From Dev

How do I remove a character from a list or string in Erlang?

From Dev

How do I remove a string from an array in a mongodb document?

From Dev

How do I remove new line characters from a string?

From Dev

How do I remove part of a string from a specific character?

From Dev

How do I remove a character from a string in a Unix shell script?

From Dev

How do i remove all white spaces from a string?

From Dev

How do I remove \r\n from string in C#?

From Dev

How do I remove a character once from a string [python]?

From Dev

How do I remove the first n characters from a string in c?

From Dev

How do I remove a textline from string with javascript?

From Dev

How do I remove the last characters from a string?

From Dev

How do I remove a character from a string in c++?

From Dev

How do I remove a query string from the URL in Wordpress?

From Dev

How do I remove multiple characters in a string

From Dev

How do I remove unknown characters in a string?

From Dev

How do I remove unknown characters in a string?

From Dev

How do I remove specific input in string

From Dev

How do I remove certain words from a string, but only if they appear at the end of the string?

From Dev

How do I remove letters from a variable?

From Dev

How do I remove url from text

From Dev

How do I remove a value from Session?

Related Related

  1. 1

    How Do I Remove A Vowel From String

  2. 2

    How do i remove chars from a string?

  3. 3

    How do I remove punctuaution from a string

  4. 4

    how do i remove a letter from string

  5. 5

    How do I remove a character from a string in a Unix shell script?

  6. 6

    How do I remove multiple offending characters from my string?

  7. 7

    How do I remove all occurrences of a specific char from a string?

  8. 8

    How do I remove \r\n from string in C#?

  9. 9

    How do I remove a character from a list or string in Erlang?

  10. 10

    How do I remove a string from an array in a mongodb document?

  11. 11

    How do I remove new line characters from a string?

  12. 12

    How do I remove part of a string from a specific character?

  13. 13

    How do I remove a character from a string in a Unix shell script?

  14. 14

    How do i remove all white spaces from a string?

  15. 15

    How do I remove \r\n from string in C#?

  16. 16

    How do I remove a character once from a string [python]?

  17. 17

    How do I remove the first n characters from a string in c?

  18. 18

    How do I remove a textline from string with javascript?

  19. 19

    How do I remove the last characters from a string?

  20. 20

    How do I remove a character from a string in c++?

  21. 21

    How do I remove a query string from the URL in Wordpress?

  22. 22

    How do I remove multiple characters in a string

  23. 23

    How do I remove unknown characters in a string?

  24. 24

    How do I remove unknown characters in a string?

  25. 25

    How do I remove specific input in string

  26. 26

    How do I remove certain words from a string, but only if they appear at the end of the string?

  27. 27

    How do I remove letters from a variable?

  28. 28

    How do I remove url from text

  29. 29

    How do I remove a value from Session?

HotTag

Archive