~michalr/blog2gmi

c6f0e6714fff7cc1a3b873902d8b61c5ff6ebe11 — Michał Rudowicz 3 years ago e4ad857
Blockquote support
2 files changed, 57 insertions(+), 2 deletions(-)

M spec/gmi_renderer_spec.cr
M src/gmi_renderer.cr
M spec/gmi_renderer_spec.cr => spec/gmi_renderer_spec.cr +53 -1
@@ 156,7 156,7 @@ there hello"
    actual.should eq(expected)
  end

  it "should render ordered lists as unrodered" do
  it "should render ordered lists as unordered" do
    input = "1. First element
2. Second element
3. Third element"


@@ 168,4 168,56 @@ there hello"

    actual.should eq(expected)
  end

  it "should render blockquotes" do
    input = "> hello
> world"
    expected = "> hello
> world"

    actual = render_to_gmi(input)

    actual.should eq(expected)
  end

  it "should render blockquotes with formatted text inside" do
    input = "> hello *world* **strong** [link](http://example.com/)
> world `pre` ![Image of Yaktocat](https://octodex.github.com/images/yaktocat.png) and other stuff"
    expected = "> hello *world* **strong** link[1]
> world `pre`
=> https://octodex.github.com/images/yaktocat.png Image of Yaktocat
> and other stuff

## Links

=> http://example.com/ 1"

    actual = render_to_gmi(input)

    actual.should eq(expected)
  end

  it "should render blockquotes with formatted text inside with normal content around it" do
    input = "this is normal *content* all right
> hello *world* **strong** [link](http://example.com/)
> world `pre` ![Image of Yaktocat](https://octodex.github.com/images/yaktocat.png) and other stuff
this is quote too

but this is not"
    expected = "this is normal *content* all right
> hello *world* **strong** link[1]
> world `pre`
=> https://octodex.github.com/images/yaktocat.png Image of Yaktocat
> and other stuff
> this is quote too
but this is not

## Links

=> http://example.com/ 1"

    actual = render_to_gmi(input)

    actual.should eq(expected)
  end
end

M src/gmi_renderer.cr => src/gmi_renderer.cr +4 -1
@@ 13,6 13,7 @@ class GmiRenderer < Markd::Renderer
    @output_io = String::Builder.new
    @last_output = "\n"
    @is_newline = false
    @is_blockquote = false
  end

  def heading(node, entering)


@@ 38,7 39,7 @@ class GmiRenderer < Markd::Renderer
  end

  def block_quote(node, entering)
    raise "Not implemented"
    @is_blockquote = entering
  end

  def thematic_break(node, entering)


@@ 109,6 110,8 @@ class GmiRenderer < Markd::Renderer
  def text(node, entering)
    actual_text = node.text
    actual_text = node.text.lstrip if @is_newline
    @output_io << "> " if (@is_blockquote && @is_newline)

    @is_newline = false

    @output_io << actual_text