Zelenka Zelenka - 5 months ago 14
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?

Answer

It is 2016. Use UTF-8 proper typographic apostrophe

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

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