Zelenka Zelenka - 9 months ago 58
Ruby Question

Escape a single quote sign in highcharts

I'm working on a Rails app and have a serie name "Helen's book" which is shown on the chart as Helen

s book.

I tried to use gsub method in the controller but it didn't work out:

@results[:data].each{|result| x[:result].gsub("'", "\\\\'")}

How to achieve a properly shown single quote sign?


It is 2016. Use UTF-8 proper typographic apostrophe

@results[:data].each do |result|
  x[:result].gsub(/(?<=\W)['"]/, "‘")
            .gsub(/['"](?=\W)/, "’")
            .gsub("'", "’")

#⇒ Helen’s book
#⇒ Book ‘Adventures’