@@ -86,6 +86,9 @@ safe_list_sanitizer.sanitize(@article.body, scrubber: ArticleScrubber.new)
86
86
87
87
# safe list sanitizer can also sanitize css
88
88
safe_list_sanitizer.sanitize_css(' background-color: #000;' )
89
+
90
+ # fully prune nodes from the tree instead of stripping tags and leaving inner content
91
+ safe_list_sanitizer = Rails ::Html ::SafeListSanitizer .new (prune: true )
89
92
```
90
93
91
94
### Scrubbers
@@ -107,6 +110,24 @@ html_fragment.scrub!(scrubber)
107
110
html_fragment.to_s # => "<a></a>"
108
111
```
109
112
113
+ By default, inner content is left, but it can be removed as well.
114
+
115
+ ``` ruby
116
+ scrubber = Rails ::Html ::PermitScrubber .new
117
+ scrubber.tags = [' a' ]
118
+
119
+ html_fragment = Loofah .fragment(' <a><span>text</span></a>' )
120
+ html_fragment.scrub!(scrubber)
121
+ html_fragment.to_s # => "<a>text</a>"
122
+
123
+ scrubber = Rails ::Html ::PermitScrubber .new (prune: true )
124
+ scrubber.tags = [' a' ]
125
+
126
+ html_fragment = Loofah .fragment(' <a><span>text</span></a>' )
127
+ html_fragment.scrub!(scrubber)
128
+ html_fragment.to_s # => "<a></a>"
129
+ ```
130
+
110
131
#### ` Rails::Html::TargetScrubber `
111
132
112
133
Where ` PermitScrubber ` picks out tags and attributes to permit in sanitization,
@@ -124,6 +145,23 @@ html_fragment.scrub!(scrubber)
124
145
html_fragment.to_s # => "<a></a>"
125
146
```
126
147
148
+ Similarly to ` PermitScrubber ` , nodes can be fully pruned.
149
+
150
+ ``` ruby
151
+ scrubber = Rails ::Html ::TargetScrubber .new
152
+ scrubber.tags = [' span' ]
153
+
154
+ html_fragment = Loofah .fragment(' <a><span>text</span></a>' )
155
+ html_fragment.scrub!(scrubber)
156
+ html_fragment.to_s # => "<a>text</a>"
157
+
158
+ scrubber = Rails ::Html ::TargetScrubber .new (prune: true )
159
+ scrubber.tags = [' span' ]
160
+
161
+ html_fragment = Loofah .fragment(' <a><span>text</span></a>' )
162
+ html_fragment.scrub!(scrubber)
163
+ html_fragment.to_s # => "<a></a>"
164
+ ```
127
165
#### Custom Scrubbers
128
166
129
167
You can also create custom scrubbers in your application if you want to.
0 commit comments