Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Nanoc Markdown/CodeRay plugin
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Rob Emerson  
View profile  
 More options May 5 2008, 5:41 am
From: Rob Emerson <goo...@remerson.plus.com>
Date: Mon, 5 May 2008 02:41:11 -0700 (PDT)
Local: Mon, May 5 2008 5:41 am
Subject: Nanoc Markdown/CodeRay plugin
Hi,

I've written a small Nanoc plugin that filters output via CodeRay.

I write my code segments in Markdown. This filter finds the resulting
<pre><code> blocks generated by Bluecloth and filters them via
CodeRay.

Hope this is useful to someone.

Cheers,

Rob

#
# This is a small filter that searches for <pre><code>...</code></pre>
blocks inside the
# given document and rams the block through CodeRay. This should allow
you to get nice
# syntax highlighted code from straight Markdown (I tested via txt
files through Bluecloth).
#
# Some caveats:
#
# - The <pre><code> block is automatically wrapped in a <div
class="CodeRay"> by this filter.
# - I've defaulted to C below; current this is hardwired.
# - You'll need to add suitable CSS for CodeRay somewhere; this isn't
inlined/generated.
#
# Needs Gems:
#
# - Hpricot
# - CodeRay
#
class CoderayFilter < Nanoc::Filter

  identifier :coderay

  def run(content)
    nanoc_require 'hpricot'
    nanoc_require 'coderay'

    doc = Hpricot(content)

    blocks = doc.search('pre > code').map do |block|

      # CodeRay will re-escape, leading to a mess as the content is
already escaped.
      # Need to therefore unescape first.
      code = codify(html_unescape(block.inner_html), :c)

      block.inner_html = code

    end

    # Crusty; wrap in div.
    doc.to_s.gsub('<pre><code>', '<div
class="CodeRay"><pre><code>').gsub('</code></pre>', '<</code></pre></
div>')

  end

  private

   def html_unescape(a_string)
     a_string.gsub('&amp;', '&').gsub('&lt;', '<').gsub('&gt;',
'>').gsub('&quot;', '"')
   end

   def codify(str, lang)
     %{#{CodeRay.scan(str, lang).html}}
   end

end


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rob Emerson  
View profile  
 More options May 16 2008, 4:34 pm
From: Rob Emerson <goo...@remerson.plus.com>
Date: Fri, 16 May 2008 13:34:28 -0700 (PDT)
Local: Fri, May 16 2008 4:34 pm
Subject: Re: Nanoc Markdown/CodeRay plugin
Wrote this up on my (new! nanoc!) site, if anyone's interested:

http://www.remerson.plus.com/articles/nanoc-coderay/


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google