EzDevInfo.com

coderay

Fast and easy syntax highlighting for selected languages, written in Ruby. CodeRay

Coderay in RefineryCMS Blog

I am using Rails 3.2.19 and RefineryCMS Blog 2.1.0

I want to use CodeRay. I have followed Ryan's RailsCasts: http://railscasts.com/episodes/207-syntax-highlighting to get it installed. In my gem file is:

gem 'coderay'
gem 'RedCloth'

I am lost at this point:

<%= textilize(coderay(@article.post)) %>

The error I am getting is:

undefined method 'post'

I am not fully sure where all the Blog's methods are:


Source: (StackOverflow)

Is it possible to use CodeRay in github pages?

I'm using Jekyll-Bootstrap now. In my local environment, I can enable CodeRay in jekyll's _config.yml and use it in my posts without any problem. But the same code cannot work on github.

My _config.yml (jekyll-bootstrap configs are omitted):

# Use kramdown as markdown parser engine.
markdown:      kramdown
markdown_ext:  markdown,mkd,mkdn,md
textile_ext:   textile

kramdown:
  auto_ids: true
  footnote_nr: 1
  entity_output: as_char
  toc_levels: 1..6
  smart_quotes: lsquo,rsquo,ldquo,rdquo
  use_coderay: true

  coderay:
    coderay_wrap: div
    coderay_line_numbers: nil
    coderay_tab_width: 4
    coderay_bold_every: 10
    coderay_css: class

Source: (StackOverflow)

Advertisements

Syntax highlighting with CodeRay and Markdown (RDiscount) in a Rails 3 application

I'm trying to add some syntax highlighting to my blog that currently uses RDiscount. I am converting the Markdown to HTML with RDiscount then parsing the HTML code blocks with CodeRay to add syntax highlighting. This is what I have so far:

class Post < ActiveRecord::Base
  before_save :render_body

  def render_body
    self.rendered_body = coderay(markdown(self.body))
  end

  def markdown(text)
    RDiscount.new(text).to_html
  end

  def coderay(text)
    text.gsub(/\<code( lang="(.+?)")?\>(.+?)\<\/code\>/m) do
      CodeRay.scan($3, $2).div(:css => :class)
    end
  end
end

And in my view:

<%= raw @post.rendered_body %>

Using this markdown:

<code lang="ruby">
def function(param1, param2)
  puts param1
    param2.each do |a|
      a.hello :world
    end
end
</code>

The result is that the code blocks are being wrapped twice.

<pre>
<div class="CodeRay">
<div class="code">
<pre>
def function(param1, param2)
  puts param1
  param2.each do |a|
    a.hello :world
  end
end
</pre>
</div>
</div>
</pre>

What should I do instead?


Source: (StackOverflow)

How to select a different theme/style for CodeRay syntax highlighting Ruby code?

I'm having difficulty figuring out how to select a different theme/style for syntax highlighting of Ruby code using the CodeRay gem, the default is OK but i wonder if there's anything else on offer? i can't seem to find them.

Thanks


Source: (StackOverflow)

coderay solarized

How I can add solarized-dark colors to coderay ?

I'm thinking about tweaking the alpha.rb file, but not sure which css class definitions substitute with which color code.

Any better ideas ? Maybe there exist some out of the box solution ? Found also this but not sure how to make usage of it.


Source: (StackOverflow)

CodeRay stylesheet

require 'coderay'
puts CodeRay.scan('puts "Hello, world!"', :ruby).page

This code will print full HTML page with CSS(classes).

I may print only colored code using CodeRay.scan('puts "Hello, world!"', :ruby).div
How can I print only CSS part?

There is stylesheet method in CodeRay::Encoders::HTML::Output, but how can I call it?


Source: (StackOverflow)

How do I get Haml to stop from evaluating #{var} values inside
  tags?

I'm using CodeRay and Haml to do syntax highlighting on some pages, and I write a lot of Ruby code. The problem is when I have something like this:

%pre
  %code.language-ruby
    :preserve
      def hello(name)
        puts "Hello #{name}!" 
      end

I keep getting errors because Haml keeps trying to evaluate the name variable inside the string, the #{var} syntax is a pretty common idiom in Ruby code and there aremany places where it is used, but I cannot use syntax highlighting of those codes because Haml wants to evaluate those variables inside the string.

Is there a way to tell Haml to not do that in some places?


Source: (StackOverflow)

CodeRay throws error in Rails console

I'm running Rails 4 and whenever I try running anything in the rails console, I get the following error:

2.0.0 (main):0 > User.first
CodeRay::Scanners::Scanner::ScanError:

***ERROR in scanner.rb:333:in `raise_inspect': no implicit conversion of Array into String (after  tokens)

tokens:


current line: 1  column: 5  pos: 4
matched: nil  state: "Error in CodeRay::Scanners::Ruby#scan_tokens, initial state was: :initial"
bol?: false,  eos?: false


surrounding code:

nil ~~ ".first"

ERROR

from /Users/silasjmatson/.gem/ruby/2.0.0/gems/coderay-1.1.0/lib/coderay/encoders/terminal.rb:145:in `text_token'

2.0.0 (main):0 >

My Gemfile.lock is like so:

GIT
  remote: git://github.com/gregbell/active_admin.git
  revision: abb3d454d3a6cb0852be6e7aa4c289ba83e1a966
  branch: master
  specs:
    activeadmin (1.0.0.pre)
      arbre (~> 1.0)
      bourbon
      coffee-rails
      devise (~> 3.0)
      formtastic (~> 2.3.0.rc2)
      inherited_resources (~> 1.3)
      jquery-rails
      jquery-ui-rails
      kaminari (~> 0.13)
      rails (>= 3.2, < 4.1)
      ransack (~> 1.0)
      sass-rails

PATH
  remote: components/api
  specs:
    api (01.0)
      rest-client

PATH
  remote: components/data_models
  specs:
    data_models (0.0.1)
      carrierwave
      fog
      mini_magick
      rails (~> 4.0.0)
      unf

PATH
  remote: components/store
  specs:
    store (0.0.1)
      activemerchant
      coffee-rails (~> 4.0.0)
      compass-blueprint
      compass-rails (~> 2.0.alpha.0)
      country_select
      crummy
      devise (~> 3.1.0)
      devise-async
      geocoder
      heroku-deflater
      jquery-rails
      rails (~> 4.0.1)
      sass-rails (~> 4.0.0)
      sidekiq
      sidekiq-failures
      simple_form
      sinatra
      slim-rails (~> 2.0.1)
      turbolinks
      uglifier (>= 1.3.0)

GEM
  remote: http://rubygems.org/
  specs:
    actionmailer (4.0.1)
      actionpack (= 4.0.1)
      mail (~> 2.5.4)
    actionpack (4.0.1)
      activesupport (= 4.0.1)
      builder (~> 3.1.0)
      erubis (~> 2.7.0)
      rack (~> 1.5.2)
      rack-test (~> 0.6.2)
    active_utils (2.0.1)
      activesupport (>= 2.3.11)
      i18n
    activemerchant (1.42.2)
      active_utils (~> 2.0, >= 2.0.1)
      activesupport (>= 2.3.14, < 5.0.0)
      builder (>= 2.1.2, < 4.0.0)
      i18n (~> 0.5)
      json (~> 1.7)
      money (< 7.0.0)
      nokogiri (~> 1.4)
    activemodel (4.0.1)
      activesupport (= 4.0.1)
      builder (~> 3.1.0)
    activerecord (4.0.1)
      activemodel (= 4.0.1)
      activerecord-deprecated_finders (~> 1.0.2)
      activesupport (= 4.0.1)
      arel (~> 4.0.0)
    activerecord-deprecated_finders (1.0.3)
    activesupport (4.0.1)
      i18n (~> 0.6, >= 0.6.4)
      minitest (~> 4.2)
      multi_json (~> 1.3)
      thread_safe (~> 0.1)
      tzinfo (~> 0.3.37)
    addressable (2.3.5)
    arbre (1.0.1)
      activesupport (>= 3.0.0)
    arel (4.0.1)
    asset_sync (1.0.0)
      activemodel
      fog (>= 1.8.0)
    atomic (1.1.14)
    bcrypt-ruby (3.1.2)
    better_errors (1.0.1)
      coderay (>= 1.0.0)
      erubis (>= 2.6.6)
    binding_of_caller (0.7.2)
      debug_inspector (>= 0.0.1)
    bourbon (3.1.8)
      sass (>= 3.2.0)
      thor
    builder (3.1.4)
    callsite (0.0.11)
    carrierwave (0.9.0)
      activemodel (>= 3.2.0)
      activesupport (>= 3.2.0)
      json (>= 1.7)
    celluloid (0.15.2)
      timers (~> 1.1.0)
    charlock_holmes (0.6.9.4)
    chunky_png (1.2.9)
    coderay (1.1.0)
    coffee-rails (4.0.1)
      coffee-script (>= 2.2.0)
      railties (>= 4.0.0, < 5.0)
    coffee-script (2.2.0)
      coffee-script-source
      execjs
    coffee-script-source (1.6.3)
    compass (0.12.2)
      chunky_png (~> 1.2)
      fssm (>= 0.2.7)
      sass (~> 3.1)
    compass-blueprint (0.0.1)
      compass
    compass-rails (2.0.alpha.0)
      compass (>= 0.12.2, < 0.14)
    connection_pool (1.1.0)
    country_select (1.2.0)
    crack (0.4.1)
      safe_yaml (~> 0.9.0)
    crummy (1.8.0)
    dalli (2.6.4)
    debug_inspector (0.0.2)
    devise (3.1.2)
      bcrypt-ruby (~> 3.0)
      orm_adapter (~> 0.1)
      railties (>= 3.2.6, < 5)
      thread_safe (~> 0.1)
      warden (~> 1.2.3)
    devise-async (0.8.0)
      devise (>= 2.2, < 3.2)
    diff-lcs (1.2.5)
    docile (1.1.0)
    dotenv (0.9.0)
    erubis (2.7.0)
    excon (0.28.0)
    execjs (2.0.2)
    factory_girl (4.3.0)
      activesupport (>= 3.0.0)
    factory_girl_rails (4.3.0)
      factory_girl (~> 4.3.0)
      railties (>= 3.0.0)
    ffi (1.9.3)
    figaro (0.7.0)
      bundler (~> 1.0)
      rails (>= 3, < 5)
    fog (1.18.0)
      builder
      excon (~> 0.28.0)
      formatador (~> 0.2.0)
      mime-types
      multi_json (~> 1.0)
      net-scp (~> 1.1)
      net-ssh (>= 2.1.3)
      nokogiri (~> 1.5)
      ruby-hmac
    foreman (0.63.0)
      dotenv (>= 0.7)
      thor (>= 0.13.6)
    formatador (0.2.4)
    formtastic (2.3.0.rc2)
      actionpack (>= 3.0)
    fssm (0.2.10)
    fuubar (1.2.1)
      rspec (~> 2.0)
      rspec-instafail (~> 0.2.0)
      ruby-progressbar (~> 1.0)
    geocoder (1.1.8)
    growl (1.0.3)
    guard (2.2.4)
      formatador (>= 0.2.4)
      listen (~> 2.1)
      lumberjack (~> 1.0)
      pry (>= 0.9.12)
      thor (>= 0.18.1)
    guard-rspec (4.0.4)
      guard (>= 2.1.1)
      rspec (~> 2.14)
    has_scope (0.6.0.rc)
      actionpack (>= 3.2, < 5)
      activesupport (>= 3.2, < 5)
    heroku-deflater (0.5.2)
      rack (>= 1.4.5)
    hike (1.2.3)
    i18n (0.6.5)
    inherited_resources (1.4.1)
      has_scope (~> 0.6.0.rc)
      responders (~> 1.0.0.rc)
    jquery-rails (3.0.4)
      railties (>= 3.0, < 5.0)
      thor (>= 0.14, < 2.0)
    jquery-ui-rails (4.1.0)
      railties (>= 3.1.0)
    json (1.8.1)
    kaminari (0.14.1)
      actionpack (>= 3.0.0)
      activesupport (>= 3.0.0)
    listen (2.2.0)
      celluloid (>= 0.15.2)
      rb-fsevent (>= 0.9.3)
      rb-inotify (>= 0.9)
    lockfile (2.1.0)
    lumberjack (1.0.4)
    mail (2.5.4)
      mime-types (~> 1.16)
      treetop (~> 1.4.8)
    meta_request (0.2.8)
      callsite
      rack-contrib
      railties
    method_source (0.8.2)
    mime-types (1.25)
    mini_magick (3.6.0)
      subexec (~> 0.2.1)
    mini_portile (0.5.2)
    minitest (4.7.5)
    money (6.0.0)
      i18n (~> 0.6.4)
    multi_json (1.8.2)
    net-scp (1.1.2)
      net-ssh (>= 2.6.5)
    net-ssh (2.7.0)
    nokogiri (1.6.0)
      mini_portile (~> 0.5.0)
    orm_adapter (0.5.0)
    pg (0.17.0)
    polyamorous (0.6.4)
      activerecord (>= 3.0)
    polyglot (0.3.3)
    pry (0.9.12.3)
      coderay (~> 1.0)
      method_source (~> 0.8)
      slop (~> 3.4)
    pry-rails (0.3.2)
      pry (>= 0.9.10)
    puma (2.6.0)
      rack (>= 1.1, < 2.0)
    rack (1.5.2)
    rack-contrib (1.1.0)
      rack (>= 0.9.1)
    rack-protection (1.5.1)
      rack
    rack-test (0.6.2)
      rack (>= 1.0)
    rails (4.0.1)
      actionmailer (= 4.0.1)
      actionpack (= 4.0.1)
      activerecord (= 4.0.1)
      activesupport (= 4.0.1)
      bundler (>= 1.3.0, < 2.0)
      railties (= 4.0.1)
      sprockets-rails (~> 2.0.0)
    rails_12factor (0.0.2)
      rails_serve_static_assets
      rails_stdout_logging
    rails_serve_static_assets (0.0.1)
    rails_stdout_logging (0.0.3)
    railties (4.0.1)
      actionpack (= 4.0.1)
      activesupport (= 4.0.1)
      rake (>= 0.8.7)
      thor (>= 0.18.1, < 2.0)
    rake (10.1.0)
    ransack (1.1.0)
      actionpack (>= 3.0)
      activerecord (>= 3.0)
      polyamorous (~> 0.6.0)
    rb-fsevent (0.9.3)
    rb-inotify (0.9.2)
      ffi (>= 0.5.0)
    rb-readline (0.5.0)
    rdoc (3.12.2)
      json (~> 1.4)
    redis (3.0.6)
    redis-namespace (1.3.2)
      redis (~> 3.0.4)
    responders (1.0.0)
      railties (>= 3.2, < 5)
    rest-client (1.6.7)
      mime-types (>= 1.16)
    rspec (2.14.1)
      rspec-core (~> 2.14.0)
      rspec-expectations (~> 2.14.0)
      rspec-mocks (~> 2.14.0)
    rspec-core (2.14.7)
    rspec-expectations (2.14.4)
      diff-lcs (>= 1.1.3, < 2.0)
    rspec-instafail (0.2.4)
    rspec-mocks (2.14.4)
    rspec-rails (2.14.0)
      actionpack (>= 3.0)
      activesupport (>= 3.0)
      railties (>= 3.0)
      rspec-core (~> 2.14.0)
      rspec-expectations (~> 2.14.0)
      rspec-mocks (~> 2.14.0)
    ruby-hmac (0.4.0)
    ruby-progressbar (1.2.0)
    safe_yaml (0.9.7)
    sass (3.2.12)
    sass-rails (4.0.1)
      railties (>= 4.0.0, < 5.0)
      sass (>= 3.1.10)
      sprockets-rails (~> 2.0.0)
    sdoc (0.3.20)
      json (>= 1.1.3)
      rdoc (~> 3.10)
    sidekiq (2.16.1)
      celluloid (>= 0.15.2)
      connection_pool (>= 1.0.0)
      json
      redis (>= 3.0.4)
      redis-namespace (>= 1.3.1)
    sidekiq-failures (0.2.2)
      sidekiq (>= 2.9.0)
    simple_form (3.0.0)
      actionpack (>= 4.0.0, < 4.1)
      activemodel (>= 4.0.0, < 4.1)
    simplecov (0.8.1)
      docile (~> 1.1.0)
      lockfile (>= 2.1.0)
      multi_json
      simplecov-html (~> 0.8.0)
    simplecov-html (0.8.0)
    sinatra (1.4.4)
      rack (~> 1.4)
      rack-protection (~> 1.4)
      tilt (~> 1.3, >= 1.3.4)
    slim (2.0.2)
      temple (~> 0.6.6)
      tilt (>= 1.3.3, < 2.1)
    slim-rails (2.0.3)
      actionpack (>= 3.0, < 4.1)
      activesupport (>= 3.0, < 4.1)
      railties (>= 3.0, < 4.1)
      slim (~> 2.0)
    slop (3.4.7)
    sprockets (2.10.0)
      hike (~> 1.2)
      multi_json (~> 1.0)
      rack (~> 1.0)
      tilt (~> 1.1, != 1.3.0)
    sprockets-rails (2.0.1)
      actionpack (>= 3.0)
      activesupport (>= 3.0)
      sprockets (~> 2.8)
    sqlite3 (1.3.8)
    subexec (0.2.3)
    temple (0.6.7)
    thor (0.18.1)
    thread_safe (0.1.3)
      atomic
    tilt (1.4.1)
    timers (1.1.0)
    treetop (1.4.15)
      polyglot
      polyglot (>= 0.3.1)
    turbolinks (1.3.1)
      coffee-rails
    tzinfo (0.3.38)
    uglifier (2.3.1)
      execjs (>= 0.3.0)
      json (>= 1.8.0)
    unf (0.1.3)
      unf_ext
    unf_ext (0.0.6)
    vcr (2.7.0)
    warden (1.2.3)
      rack (>= 1.0)
    webmock (1.16.0)
      addressable (>= 2.2.7)
      crack (>= 0.3.2)

PLATFORMS
  ruby

DEPENDENCIES
  activeadmin!
  api!
  asset_sync
  better_errors
  binding_of_caller
  charlock_holmes
  coderay (~> 1.1.0)
  dalli
  data_models!
  factory_girl_rails
  figaro
  foreman
  fuubar
  growl
  guard
  guard-rspec
  jquery-rails
  meta_request
  pg
  pry-rails
  puma
  rails (= 4.0.1)
  rails_12factor
  rb-readline (~> 0.5.0)
  redis
  rspec-rails
  sdoc
  sidekiq
  simplecov
  sqlite3
  store!
  uglifier (>= 1.3.0)
  vcr
  webmock

Any Help?


Source: (StackOverflow)

Coderay renders actual ruby code

I have RedCloth with Coderay installed to highlight my code pasted in my blog.

If I paste some code like this:

 CodeRay.scan(
"set_meta_tags :og => {
        :title => @blog.title,
        :type => 'article',
        :url => current_url,
        :image => @blog.blog_images.first.image.url,
        :article => {:published_time => @blog.created_at.to_time.iso8601,
                     :modified_time => @blog.updated_at.to_time.iso8601,
                     :author => 'Name',
                     :section => @blog.categories.first.name,
                     :tags => @blog.categories.map(&:name).join(', ')
        }}",
:ruby).div(:css => :class)

I got this

set_meta_tags :og => {

        :title => blog</span>.title,
        <span class="symbol">:type</span> =&gt; <span class="string"><span class="delimiter">'</span><span class="content">article</span><span class="delimiter">'</span></span>,
        <span class="symbol">:url</span> =&gt; current_url,
        <span class="symbol">:image</span> =&gt; <span class="instance-variable">blog.blog_images.first.image.url,

        :article => {:published_time => blog</span>.created_at.to_time.iso8601,
                     <span class="symbol">:modified_time</span> =&gt; <span class="instance-variable">blog.updated_at.to_time.iso8601,

                     :author => ‘Name’,

                     :section => blog</span>.categories.first.name,
                     <span class="symbol">:tags</span> =&gt; <span class="instance-variable">blog.categories.map(&:name).join(‘, ’)

        }}

How can I get rid of that?

Many thanks


Source: (StackOverflow)

syntax highlighting with coderay, asciidoctor not working

I have asciidoctor markdown like so, as described here http://asciidoctor.org/docs/asciidoc-syntax-quick-reference/#source-code

:source-highlighter: coderay
:coderay-css: class
:stylesheet: coderay_railscasts.css.scss

[source,ruby]
.app.rb
----
require 'sinatra'

get '/hi' do
  "Hello World!"
end
----

But my output in the browser isn't highlighted at all. The classes haven't been applied either.

My web developer tools output looks like so: As you can see, there are no classes applied to the text that should be, according to the documentation

<div class="listingblock">

    <div class="title"></div>
    <div class="content">
        <pre class="highlight">
            <code class="language-ruby" data-lang="ruby">

                require 'sinatra'

                get '/hi' do
                  "Hello World!"
                end

            </code>
        </pre>
    </div>

</div>

So it seems it has failed to apply classes, which may be failing to communicate with coderay, or failing to find the right settings, etc.

I've seen this asciidoctor FAQ http://asciidoctor.org/docs/faq/ explaining how you have to tweak some settings, but I it applies when generating html documents from the asciidoctor markdown, not what I'm doing - which is saving markdown text in a database, and having that text get parsed when retrieved. That faq question also seems to assume a file structure and framework that is not rails. So it doesn't seem to apply to my case.

I am at a loss because I have the correct syntax and settings, but unsure where it is failing, without any means currently to debug or examine where anything is missing or incorrect.

This issue seems to be the exact behavior I'm getting. https://github.com/asciidoctor/asciidoctor/issues/947


Source: (StackOverflow)

Recarpet no pre tag and language on rails 4

I've tried to implement CodeRay gem into RedCarpet gem for language syntax, and I just saw that Redcarpet isn't showing any pre tags (with and without CodeRay). I have tried to add a space newline between code and language, tried other methods, but nothing. Everything else is working fine with RedCarpet. For example: when I write \``` ruby(enter) ruby_code it should covert to ruby syntax highlight, instead it just prints the same thing I entered. In console log there aren't any pre class="ruby tags, just <code>ruby</code>. Hope that I explained myself. I'm using rails 4.1.8. application_helper.rb:

class CodeRayify < Redcarpet::Render::HTML
 def block_code(code, language)
   CodeRay.scan(code, language).div(:line_numbers => :table)
 end
end

def markdown(text)

    coderayified = CodeRayify.new(
    filter_html: true, 
    hard_wrap: true)

    options = {
    link_attributes: { rel: 'nofollow', target: "_blank" },
    space_after_headers: true,
    prettify:        true,
    fenced_code_blocks: true,
    autolink:           true,
    no_intra_emphasis: true,
    superscript:        true,
    highlight: true,
    strikethrough: true,
    quote: true,
    no_images: false,
    superscript: true,
    footnotes: true,
    tables: true
    }

   markdown = Redcarpet::Markdown.new(coderayified, options)
   markdown.render(text).html_safe
end

In views => show.html.erb:

<%= markdown(@post.body) %>

Source: (StackOverflow)

CodeRay style messed up - how to fix

I'm trying to use CodeRay in my project and it seems to be working, however the style and formatting seems to be messed:

Coderay messed up code

Note that I'm using CodeRay in conjunction with Markdown (Redcarpet). I've added both gems in my gemfile and in the app/helpers/application_helper.rb I've added the following:

class CodeRayify < Redcarpet::Render::HTML
    def block_code(code, language)
        CodeRay.scan(code, language).div(:line_numbers => :inline)
    end
end

def markdown(text)
    coderayified = CodeRayify.new(:filter_html => true, :hard_wrap => true)

    language ||= :plaintext

    options = {
        :fenced_code_blocks => true,
        :no_intra_emphasis => false,
        :autolink => true,
        :strikethrough => true,
        :lax_html_blocks => true,
        :superscript => true
    }

    markdown_to_html = Redcarpet::Markdown.new(coderayified, options)
    markdown_to_html.render(text).html_safe
end

Which does work as you can see by the screenshot attached. The problem is the formatting though. Any ideas?


Source: (StackOverflow)

Trying to get user api key on Redmine

for a project i use Redmine and PHP together. I can send some data to php but when i try to add one more data i get internal server error. The problem is that i do not know and exactly code implementation of Ruby and Redmine, although i am a beginner on ruby. Here is the deal;

<%= button_to l(:button_draw), 'some.php?xta='"#{@issue.id}", :class => 'buttons' %>

I can sent the issue id to php with code above but when i try to send current user api key, i stuck at internal error.(most probably because of a syntax error)

I tried;

<%= button_to l(:button_draw), 'some.php?xta='"#{@issue.id}&atx", {:key => User.current.api_key}, :class => 'buttons' %>
<%= button_to l(:button_draw), 'some.php?xta='"#{@issue.id}&atx", :key => User.current.api_key, :class => 'buttons' %>
<%= button_to l(:button_draw), ('some.php?xta='"#{@issue.id}&atx"(:key => User.current.api_key), :class => 'buttons' %>

and some other versions of this but no luck. As you can figure i am able to get api key with following codes;

<%= h(User.current.api_key) %>
<%= button_to l(:button_offer1), {:key => User.current.api_key}, :class => 'buttons'%>

However, my aim is to send api key and issue id to php together. Your help is much appreciated.


Source: (StackOverflow)

Combine Coderay Syntaxes with Redcarpet

I need to highlight a code diff in markdown using Coderay and Redcarpet. Is there a way to combine multiple syntaxes?

For example, if it's a ruby diff, it should be highlighted both as ruby and as a diff code.

For now I'm using this code:

class CodeRayify < Redcarpet::Render::HTML
  def block_code(code, language)
    CodeRay.scan(code, language).div(:line_numbers => :table)
  end
end

def markdown(text)
  @coderayified ||= CodeRayify.new(:filter_html => true,
                           :hard_wrap => true)

  options = {
    :fenced_code_blocks => true,
    :no_intra_emphasis => true,
    :autolink => true,
    :strikethrough => true,
    :lax_html_blocks => true,
    :superscript => true
  } 

  @markdown_to_html = Redcarpet::Markdown.new(@coderayified, options)
  @markdown_to_html.render(text).html_safe
end

and in the view I call:

<%= markdown @model.markdown_text %>

Thanks in advance


Source: (StackOverflow)

Octopress kramdown generate error for tags with ':'

I want to use kramdown tags with ':' in them, ie. {:toc}

and coderay code blocks

{:lang="javascript"}

in my Octopress blog but I keep getting this error when running

rake generate:

    [my user dir]/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/psych.rb:203:in 
    `parse': (<unknown>): could not find expected ':' 
    while scanning a simple key at line 8 column 1 (Psych::SyntaxError)

I have installed the kramdown and coderay gems and made the following changes to my _config.yml:

     markdown: kramdown
     kramdown:
         auto_ids: true
         use_coderay: true`
           coderay:
             coderay_line_numbers: nil
             coderay_css: class`

My blogpost toc code looks like this:

    ---
    layout: page
    title: "resources"
    date: 2013-06-06 10:45
    comments: true
    sharing: true
    footer: true
    categories: [3D UI, css, CSS3D, HTML5, javaScript, three.js, 
    smart tv, grunt, jQuery, node.js, bootstrap, css,
    responsive design, api, learning, backbone.js, knockout.js]
    ---
    #Resources
    {:toc}
    ## **Performance and Caching**
     * [Varnish](https://www.varnish-cache.org/)
    {:toc}
    ## **SmartTV**
     * [Samsung Development Guide](http://www.samsungdforum.com/Guide/)
     * [Basic SmartTV Node App Server](https://github.com/rposbo/basic-smart-tv-app-server)
    {:toc} [ .. snip .. ]

the codeblock code looks like this:

    `renderer = new THREE.CSS3DRenderer();
    renderer.setSize(window.innerWidth, window.innerHeight);
    renderer.domElement.style.position = 'absolute';

    document.getElementById('video_container').appendChild(renderer.domElement);`
    {:lang="javascript"}

I followed this post on adding the coderay scss

Without the : tags the site generates fine.

What am I missing?

Any help would be appreciated!


Source: (StackOverflow)