Skip to content

Commit 0ad2050

Browse files
Merge pull request rails#50179 from akhilgkrishnan/improve-documentation-for-highlight
Improve documentation for highlight text helper [skip ci]
2 parents 41edc5a + 204d86b commit 0ad2050

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

actionview/lib/action_view/helpers/text_helper.rb

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,26 @@ def truncate(text, options = {}, &block)
130130
end
131131
end
132132

133-
# Highlights one or more +phrases+ everywhere in +text+ by inserting it into
134-
# a <tt>:highlighter</tt> string. The highlighter can be specialized by passing <tt>:highlighter</tt>
135-
# as a single-quoted string with <tt>\1</tt> where the phrase is to be inserted (defaults to
136-
# <tt>"<mark>\1</mark>"</tt>) or passing a block that receives each matched term. By default +text+
137-
# is sanitized to prevent possible XSS attacks. If the input is trustworthy, passing false
138-
# for <tt>:sanitize</tt> will turn sanitizing off.
133+
# Highlights occurrences of +phrases+ in +text+ by formatting them with a
134+
# highlighter string. +phrases+ can be one or more strings or regular
135+
# expressions. The result will be marked HTML safe. By default, +text+ is
136+
# sanitized before highlighting to prevent possible XSS attacks.
137+
#
138+
# If a block is specified, it will be used instead of the highlighter
139+
# string. Each occurrence of a phrase will be passed to the block, and its
140+
# return value will be inserted into the final result.
141+
#
142+
# ==== Options
143+
#
144+
# [+:highlighter+]
145+
# The highlighter string. Uses <tt>\1</tt> as the placeholder for a
146+
# phrase, similar to +String#sub+. Defaults to <tt>"<mark>\1</mark>"</tt>.
147+
# This option is ignored if a block is specified.
148+
#
149+
# [+:sanitize+]
150+
# Whether to sanitize +text+ before highlighting. Defaults to true.
151+
#
152+
# ==== Examples
139153
#
140154
# highlight('You searched for: rails', 'rails')
141155
# # => "You searched for: <mark>rails</mark>"

0 commit comments

Comments
 (0)