forked from railsbridge/docs
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Highlight markdown syntax in .md files using Redcarpet+CodeRay
Currently, there are something like three ways we do syntax highlighting in this app: In .step files, you can have a 'source_code' step that specifies a language parameter. This makes a <pre class='code'> tag that contains the language name as ':::ruby', to be scooped out by Rack::Codehighlighter. In .deck.md files, you can use Github-flavored "```ruby" style 'fenced code blocks', which get parsed by redcarpet into <pre><code> blocks, which inexplicably and briefly have an '@@@ ruby' directive that is picked up by the Rack::Codehighlighter middleware. In .md files (as of this diff) you can do Github-flavored fenced code blocks, which are parsed in the original render time into <pre class='CodeRay'> blocks that have the real syntax highlighting. 'Fenced code blocks' produced in Markdown-aware erector functions (like 'message') don't seem to produce highlighted code. Will probably improve on this in a subsequent diff.
- Loading branch information
1 parent
7960229
commit 93322f7
Showing
9 changed files
with
141 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,27 @@ | ||
require 'erector' | ||
require 'doc_page' | ||
require 'redcarpet' | ||
require 'coderay' | ||
|
||
class HTMLwithCodeRay < Redcarpet::Render::HTML | ||
def block_code(code, language) | ||
if language | ||
"<pre class='CodeRay'>#{CodeRay.scan(code, language).html}</pre>" | ||
else | ||
"<pre class='CodeRay'>#{CodeRay.scan(code, :text).html}</pre>" | ||
end | ||
end | ||
end | ||
|
||
MarkdownRenderer = Redcarpet::Markdown.new( | ||
HTMLwithCodeRay, | ||
:autolink => true, | ||
:space_after_headers => true, | ||
:fenced_code_blocks => true | ||
) | ||
|
||
class MarkdownPage < DocPage | ||
def doc_content | ||
rawtext md2html(src) | ||
rawtext MarkdownRenderer.render(src) | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,94 @@ | ||
## HTML Skeleton | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Title</title> | ||
</head> | ||
<body> | ||
|
||
</body> | ||
</html> | ||
|
||
```html | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Title</title> | ||
</head> | ||
<body> | ||
|
||
</body> | ||
</html> | ||
``` | ||
|
||
## Headers | ||
<h1>Header</h1> | ||
<h2>Header</h2> | ||
<h2>Header</h2> | ||
<h4>Header</h4> | ||
<h5>Header</h5> | ||
<h6>Header</h6> | ||
```html | ||
<h1>Header</h1> | ||
<h2>Header</h2> | ||
<h2>Header</h2> | ||
<h4>Header</h4> | ||
<h5>Header</h5> | ||
<h6>Header</h6> | ||
``` | ||
|
||
## Paragraphs and more | ||
<p>Paragraph content.</p> | ||
<em>emphasized content, styled italic by default</em> | ||
<strong>strong content, styled bold by default</strong> | ||
```html | ||
<p>Paragraph content.</p> | ||
<em>emphasized content, styled italic by default</em> | ||
<strong>strong content, styled bold by default</strong> | ||
``` | ||
|
||
## Images | ||
<img src="name-of-my-image.png"> | ||
<img src="http://www.othersite.com/image-name.jpg"> | ||
```html | ||
<img src="name-of-my-image.png"> | ||
<img src="http://www.othersite.com/image-name.jpg"> | ||
``` | ||
|
||
## Links | ||
<a href="#anchor">Scroll to element on the current page with id "anchor"</a> | ||
<a href="my-other-page.html">Go to a page on my site</a> | ||
<a href="my-other-page.html" target="_blank">Open a new window for a page on my site</a> | ||
<a href="http://www.othersite.com/">Go to a page on some other site</a> | ||
<a href="http://www.othersite.com/" target="_blank">Open a new window for a page on some other site</a> | ||
```html | ||
<a href="#anchor">Scroll to element on the current page with id "anchor"</a> | ||
<a href="my-other-page.html">Go to a page on my site</a> | ||
<a href="my-other-page.html" target="_blank">Open a new window for a page on my site</a> | ||
<a href="http://www.othersite.com/">Go to a page on some other site</a> | ||
<a href="http://www.othersite.com/" target="_blank">Open a new window for a page on some other site</a> | ||
``` | ||
|
||
## Lists | ||
|
||
Lists can be ordered (styled with numbers by default) or unordered (styled with bullets by default). Both contain list items with the actual content of the list. | ||
|
||
<ol> | ||
<li>First list item</li> | ||
<li>Second list item</li> | ||
</ol> | ||
```html | ||
<ol> | ||
<li>First list item</li> | ||
<li>Second list item</li> | ||
</ol> | ||
|
||
<ul> | ||
<li>One list item</li> | ||
<li>Another list item</li> | ||
</ul> | ||
<ul> | ||
<li>One list item</li> | ||
<li>Another list item</li> | ||
</ul> | ||
``` | ||
|
||
Lists can be nested. | ||
|
||
```html | ||
<ul> | ||
<li>One list item | ||
<ul> | ||
<li>One list item | ||
<ul> | ||
<li>A list item nested under "One list item"</li> | ||
<li>Another nest list item</li> | ||
</ul> | ||
</li> | ||
<li>Another list item</li> | ||
<li>A list item nested under "One list item"</li> | ||
<li>Another nest list item</li> | ||
</ul> | ||
</li> | ||
<li>Another list item</li> | ||
</ul> | ||
``` | ||
|
||
## Containers | ||
|
||
Divs and spans are generic containers used to organize HTML. Often, they are given ids and classes so that they can be given specific styling. | ||
|
||
<div>The content in the div</div> | ||
<span>span content</span> | ||
```html | ||
<div>The content in the div</div> | ||
<span>span content</span> | ||
``` | ||
|
||
## Ids and Classes | ||
|
||
Ids and classes provide a way to use CSS to target specific element(s). Many tags can have the same class. Only one tag can have a particular id. Any tag can be gi | ||
an id and classes.</p> | ||
<tagname id="a-name-uniquely-identifying-this-element">content</tagname> | ||
<tagname class="one-class another-class">content</tagname> | ||
Ids and classes provide a way to use CSS to target specific element(s). Many tags can have the same class. Only one tag can have a particular id. Any tag can be given an id and classes. | ||
|
||
```html | ||
<tagname id="a-name-uniquely-identifying-this-element">content</tagname> | ||
<tagname class="one-class another-class">content</tagname> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
here = File.expand_path File.dirname(__FILE__) | ||
require "#{here}/spec_helper" | ||
|
||
require "markdown_page" | ||
|
||
describe MarkdownPage do | ||
|
||
it "renders markdown into html" do | ||
src = <<MARKDOWN | ||
# This is a heading | ||
## This is a subheading | ||
<h2>This text is preformatted and escaped</h2> | ||
```html | ||
This text is preformatted and ready to be <strong>syntax highlighted</strong> as HTML source. | ||
``` | ||
MARKDOWN | ||
|
||
page = MarkdownPage.new( | ||
src: src, | ||
site_name: "greetings", | ||
page_name: 'hello', | ||
doc_title: "Hello", | ||
doc_path: "/tmp/hello.step" | ||
) | ||
html_doc = Nokogiri.parse(page.to_html) | ||
main_html = html_doc.css(".main").first.serialize(:save_with => 0).chomp | ||
|
||
expected = <<HTML | ||
<div class="main"> | ||
<h1 class="doc_title">Hello</h1> | ||
<div class="doc"> | ||
<h1>This is a heading</h1> | ||
<h2>This is a subheading</h2> | ||
<pre class="CodeRay"><h2>This text is preformatted and escaped</h2>\n</pre> | ||
<pre class="CodeRay">This text is preformatted and ready to be <span class="tag"><strong></span>syntax highlighted<span class="tag"></strong></span> as HTML source.</pre> | ||
</div> | ||
</div> | ||
HTML | ||
|
||
assert_loosely_equal(main_html, expected) | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters