Ruby TextHelper highlight method with Regexp -
i'm trying highlight every digit sequence in text using highlight method. can achieve passing array of numbers, way each number highlighted individually. i'd highlight whole sequence.
is possible use highlight regexp? i'm receiving following error:
highlight(text,/\d+/) can't convert regexp string
thanks
unfortunately not! can use source of highlight method inspiration write own helper need.
def highlight_digits(text) # based on actionview::helpers::texthelper#highlight highlighter = '<strong class="highlight">\1</strong>' matcher = /(\d+)(?!(?:[^<]*?)(?:["'])[^<>]*>)/ text.gsub(matcher, highlighter).html_safe end if feel comfortable, can propose patch rails include feature!
Comments
Post a Comment