rubychan / coderay

Fast and easy syntax highlighting for selected languages, written in Ruby.
http://coderay.rubychan.de/
Other
846 stars 115 forks source link

rendering javascript messing my view code #202

Closed vpereira closed 7 years ago

vpereira commented 7 years ago

Hi,

I'm using CodeRay to render different code bases and I noted that some how rendering javascript interfers with my layout. I'm callying CodeRay in my view like:

<%= raw CodeRay.scan(c,t).div(:line_numbers => :inline, :wrap=>:div) %>

where c is the code and t the results of CodeRay::FileType.fetch(filepath_text, :text)

I was not sure if it was happening some code execution, since I'm calling raw and therefore I'm not escaping the output from CodeRay.. but an alert box didn't pop-up when I tried it :)

Anyway, my rendered code looks like:

python, java, c, etc code being rendered:

screenshot_2017-01-06_09-30-08

javascript being rendered:

screenshot_2017-01-06_09-30-52

I'm using coderay 1.1.1

thanks!

korny commented 7 years ago

The JavaScript scanner is not different from any other scanner, and the div encoder should produce valid HTML. Can you give me more details? Check what CodeRay returns. Also, try line_numbers: :table.

vpereira commented 7 years ago

Hi, line_numbers as table didn't help.

HTML rendered java code: https://gist.github.com/vpereira/aa1ed682d57434d12ce97fd892c8b480

HTML rendered javascript code: https://gist.github.com/vpereira/32edd3e4aaffe9ee07f59d5e49c7b757

So I'm rendering both using the function as I sent, but the java (and all other languages.. i render php, sh, rb, etc) code renders the whole layout and somehow rendering javascript ignores the layout, as if the rendered js was interfering

vpereira commented 7 years ago

hm, it look like rails is understanding it as JS, because of the file extension.. hmpf

Started GET "/codestreams/Factory/packages/spacewalk/package_files/%2Fhome%2Fvpereira%2Fspacewalk%2Fprojects%2Fpython-gzipstream%2Fhtml%2Fepydoc.js" for 127.0.0.1 at 2017-01-09 10:01:19 +0100 Processing by PackageFilesController#show as JS

korny commented 7 years ago

So it seems this is not a CodeRay bug. Can I close it?

vpereira commented 7 years ago

yes, sorry about the noise. Coderay rules!