googlearchive / code-prettify

An embeddable script that makes source-code snippets in HTML prettier.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Ruby] Magic global variables like $` confuse highlighter

chronodm opened this issue · comments

(Note: possibly similar to #209? Depends on whether the $ or the backtick is the problem.)

Ruby uses dollar-backtick ($`) to indicate the left context of a regular expression. A line like this one from the Rails source confuses the highlighter:

parent_name = name =~ /::[^:]+\Z/ ? $`.freeze : nil

To reproduce, create the following HTML file and open it in Chrome:

<html>
  <head>
    <title>Pretty</title>
    <script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>
  </head>
  <body>
    <pre class="prettyprint">
  def parent_name
    if defined?(@parent_name)
      @parent_name
    else
      parent_name = name =~ /::[^:]+\Z/ ? $`.freeze : nil
      @parent_name = parent_name unless frozen?
      parent_name
    end
  end      
    </pre>
  </body>
</html>    

Everything after the backtick appears to be treated as a string:

screen shot 2018-11-20 at 10 50 18 am