@@ 63,4 63,38 @@ there"
actual.should eq(expected)
end
+
+ it "should render code examples" do
+ input = "```ruby
+puts \"Hello\"
+puts \"World\"
+```"
+ expected = "```
+puts \"Hello\"
+puts \"World\"
+```"
+
+ actual = render_to_gmi(input)
+
+ actual.should eq(expected)
+ end
+
+ it "should render code examples with text around it" do
+ input = "This is a Ruby code example:
+```ruby
+puts \"Hello\"
+puts \"World\"
+```
+It does print hello world."
+ expected = "This is a Ruby code example:
+```
+puts \"Hello\"
+puts \"World\"
+```
+It does print hello world."
+
+ actual = render_to_gmi(input)
+
+ actual.should eq(expected)
+ end
end
@@ 24,6 24,11 @@ class GmiRenderer < Markd::Renderer
end
end
+ def add_newline_if_needed
+ @output_io << "\n" unless @is_newline
+ @is_newline = true
+ end
+
def list(node, entering)
raise "Not implemented"
end
@@ 41,7 46,8 @@ class GmiRenderer < Markd::Renderer
end
def code_block(node, entering)
- raise "Not implemented"
+ @output_io << "```\n" << node.text << "```\n"
+ @is_newline = true
end
def code(node, entering)
@@ 57,8 63,7 @@ class GmiRenderer < Markd::Renderer
end
def paragraph(node, entering)
- @output_io << "\n"
- @is_newline = true
+ add_newline_if_needed
end
def emphasis(node, entering)
@@ 66,8 71,7 @@ class GmiRenderer < Markd::Renderer
end
def soft_break(node, entering)
- @output_io << "\n"
- @is_newline = true
+ add_newline_if_needed
end
def line_break(node, entering)