# -*- coding: utf-8; -*- require 'spec_helper' describe TDiary::Style::GfmDiary do before do @diary = TDiary::Style::GfmDiary.new(Time.at( 1041346800 ), "TITLE", "") end describe '#append' do before do @source = <<-'EOF' # subTitle honbun ## subTitleH4 honbun ``` # comment in code block ``` EOF @diary.append(@source) end context 'HTML' do before do @html = <<-'EOF'
<%=section_enter_proc( Time.at( 1041346800 ) )%>

<%= subtitle_proc( Time.at( 1041346800 ), "subTitle" ) %>

honbun

subTitleH4

honbun

# comment in code block
<%=section_leave_proc( Time.at( 1041346800 ) )%>
EOF end it { @diary.to_html.should eq @html } end context 'CHTML' do before do @html = <<-'EOF' <%=section_enter_proc( Time.at( 1041346800 ) )%>

<%= subtitle_proc( Time.at( 1041346800 ), "subTitle" ) %>

honbun

subTitleH4

honbun

# comment in code block
<%=section_leave_proc( Time.at( 1041346800 ) )%> EOF end it { @diary.to_html({}, :CHTML).should eq @html } end context 'to_src' do it { @diary.to_src.should eq @source } end end describe '#replace' do before do source = <<-'EOF' # subTitle honbun ## subTitleH4 honbun EOF @diary.append(source) replaced = <<-'EOF' # replaceTitle replace ## replaceTitleH4 replace EOF @diary.replace(Time.at( 1041346800 ), "TITLE", replaced) @html = <<-'EOF'
<%=section_enter_proc( Time.at( 1041346800 ) )%>

<%= subtitle_proc( Time.at( 1041346800 ), "replaceTitle" ) %>

replace

replaceTitleH4

replace

<%=section_leave_proc( Time.at( 1041346800 ) )%>
EOF end it { @diary.to_html.should eq @html } end describe 'autolink' do before do source = <<-EOF # subTitle * http://www.google.com [google](https://www.google.com) http://www.google.com EOF @diary.append(source) @html = <<-EOF
<%=section_enter_proc( Time.at( 1041346800 ) )%>

<%= subtitle_proc( Time.at( 1041346800 ), "subTitle" ) %>

google

http://www.google.com

<%=section_leave_proc( Time.at( 1041346800 ) )%>
EOF end it { @diary.to_html.should eq @html } end describe 'auto imagelink' do before do source = <<-EOF # subTitle ![](http://www.google.com/logo.jpg) ![google](http://www.google.com/logo.jpg) EOF @diary.append(source) @html = <<-EOF
<%=section_enter_proc( Time.at( 1041346800 ) )%>

<%= subtitle_proc( Time.at( 1041346800 ), "subTitle" ) %>

google

<%=section_leave_proc( Time.at( 1041346800 ) )%>
EOF end it { @diary.to_html.should eq @html } end describe 'auto imagelink' do before do source = <<-EOF # subTitle Anchor EOF @diary.append(source) @html = <<-EOF
<%=section_enter_proc( Time.at( 1041346800 ) )%>

<%= subtitle_proc( Time.at( 1041346800 ), "subTitle" ) %>

Anchor

<%=section_leave_proc( Time.at( 1041346800 ) )%>
EOF end it { @diary.to_html.should eq @html } end describe 'url syntax with code blocks' do before do source = <<-'EOF' # subTitle ```ruby @foo ``` http://example.com is example.com EOF @diary.append(source) @html = <<-'EOF'
<%=section_enter_proc( Time.at( 1041346800 ) )%>

<%= subtitle_proc( Time.at( 1041346800 ), "subTitle" ) %>

@foo

http://example.com is example.com

<%=section_leave_proc( Time.at( 1041346800 ) )%>
EOF end it { @diary.to_html.should eq @html } end describe 'ignored url syntax with markdown anchor' do before do source = <<-'EOF' # subTitle [example](http://example.com) is example.com EOF @diary.append(source) @html = <<-'EOF'
<%=section_enter_proc( Time.at( 1041346800 ) )%>

<%= subtitle_proc( Time.at( 1041346800 ), "subTitle" ) %>

example is example.com

<%=section_leave_proc( Time.at( 1041346800 ) )%>
EOF end it { @diary.to_html.should eq @html } end describe 'plugin syntax' do before do source = <<-'EOF' # subTitle {{plugin 'val'}} {{plugin "val", 'val'}} EOF @diary.append(source) @html = <<-'EOF'
<%=section_enter_proc( Time.at( 1041346800 ) )%>

<%= subtitle_proc( Time.at( 1041346800 ), "subTitle" ) %>

<%=plugin 'val'%>

<%=plugin "val", 'val'%>

<%=section_leave_proc( Time.at( 1041346800 ) )%>
EOF end it { @diary.to_html.should eq @html } end describe 'plugin syntax with url args' do before do source = <<-'EOF' # subTitle {{plugin 'http://www.example.com/foo.html', "https://www.example.com/bar.html"}} EOF @diary.append(source) @html = <<-'EOF'
<%=section_enter_proc( Time.at( 1041346800 ) )%>

<%= subtitle_proc( Time.at( 1041346800 ), "subTitle" ) %>

<%=plugin 'http://www.example.com/foo.html', "https://www.example.com/bar.html"%>

<%=section_leave_proc( Time.at( 1041346800 ) )%>
EOF end it { @diary.to_html.should eq @html } end describe 'link to my plugin' do before do source = <<-'EOF' # subTitle [](20120101p01) [Link](20120101p01) EOF @diary.append(source) @html = <<-'EOF'
<%=section_enter_proc( Time.at( 1041346800 ) )%>

<%= subtitle_proc( Time.at( 1041346800 ), "subTitle" ) %>

<%=my "20120101p01", "20120101p01" %>

<%=my "20120101p01", "Link" %>

<%=section_leave_proc( Time.at( 1041346800 ) )%>
EOF end it { @diary.to_html.should eq @html } end describe 'code highlighting' do before do source = <<-'EOF' # subTitle ```ruby def class @foo = 'bar' end ``` EOF @diary.append(source) @html = <<-'EOF'
<%=section_enter_proc( Time.at( 1041346800 ) )%>

<%= subtitle_proc( Time.at( 1041346800 ), "subTitle" ) %>

 def class
   @foo = 'bar'
 end
<%=section_leave_proc( Time.at( 1041346800 ) )%>
EOF end it { @diary.to_html.should eq @html } end describe 'ignore emphasis' do before do source = <<-'EOF' # subTitle @a_matsuda is amatsuda {{isbn_left_image ''}} EOF @diary.append(source) @html = <<-'EOF'
<%=section_enter_proc( Time.at( 1041346800 ) )%>

<%= subtitle_proc( Time.at( 1041346800 ), "subTitle" ) %>

@a_matsuda is amatsuda

<%=isbn_left_image ''%>

<%=section_leave_proc( Time.at( 1041346800 ) )%>
EOF end it { @diary.to_html.should eq @html } end context 'twitter username' do describe 'in plain context' do before do source = <<-'EOF' # subTitle @a_matsuda is amatsuda EOF @diary.append(source) @html = <<-'EOF'
<%=section_enter_proc( Time.at( 1041346800 ) )%>

<%= subtitle_proc( Time.at( 1041346800 ), "subTitle" ) %>

@a_matsuda is amatsuda

<%=section_leave_proc( Time.at( 1041346800 ) )%>
EOF end it { @diary.to_html.should eq @html } end describe 'with
' do
			before do
				source = <<-'EOF'
# subTitle

    p :some_code

@a_matsuda is amatsuda
				EOF
				@diary.append(source)

				@html = <<-'EOF'
<%=section_enter_proc( Time.at( 1041346800 ) )%>

<%= subtitle_proc( Time.at( 1041346800 ), "subTitle" ) %>

p :some_code

@a_matsuda is amatsuda

<%=section_leave_proc( Time.at( 1041346800 ) )%>
EOF end it { @diary.to_html.should eq @html } end describe 'with ' do before do source = <<-'EOF' # subTitle `:some_code` @a_matsuda is amatsuda EOF @diary.append(source) @html = <<-'EOF'
<%=section_enter_proc( Time.at( 1041346800 ) )%>

<%= subtitle_proc( Time.at( 1041346800 ), "subTitle" ) %>

:some_code

@a_matsuda is amatsuda

<%=section_leave_proc( Time.at( 1041346800 ) )%>
EOF end it { @diary.to_html.should eq @html } end end context 'emoji' do describe 'in plain context' do before do source = <<-'EOF' # subTitle :sushi: は美味しい EOF @diary.append(source) @html = <<-'EOF'
<%=section_enter_proc( Time.at( 1041346800 ) )%>

<%= subtitle_proc( Time.at( 1041346800 ), "subTitle" ) %>

sushi は美味しい

<%=section_leave_proc( Time.at( 1041346800 ) )%>
EOF end it { @diary.to_html.should eq @html } end describe 'in (multiline)
' do
			before do
				source = <<-'EOF'
# subTitle

```
:sushi: は
美味しい
```
				EOF
				@diary.append(source)

				@html = <<-'EOF'
<%=section_enter_proc( Time.at( 1041346800 ) )%>

<%= subtitle_proc( Time.at( 1041346800 ), "subTitle" ) %>

:sushi: は
美味しい
<%=section_leave_proc( Time.at( 1041346800 ) )%>
EOF end it { @diary.to_html.should eq @html } end describe 'in ' do before do source = <<-'EOF' # subTitle `:sushi:` は美味しい EOF @diary.append(source) @html = <<-'EOF'
<%=section_enter_proc( Time.at( 1041346800 ) )%>

<%= subtitle_proc( Time.at( 1041346800 ), "subTitle" ) %>

:sushi: は美味しい

<%=section_leave_proc( Time.at( 1041346800 ) )%>
EOF end it { @diary.to_html.should eq @html } end describe 'in (with attribute)' do before do source = <<-'EOF' # subTitle :sushi: は美味しい EOF @diary.append(source) @html = <<-'EOF'
<%=section_enter_proc( Time.at( 1041346800 ) )%>

<%= subtitle_proc( Time.at( 1041346800 ), "subTitle" ) %>

:sushi: は美味しい

<%=section_leave_proc( Time.at( 1041346800 ) )%>
EOF end it { @diary.to_html.should eq @html } end end describe 'do not modify original string' do before do @orig_source = <<-'EOF' # subTitle {{fn 'テスト'}}" EOF @source = @orig_source.dup @diary.append(@source) @diary.to_html @section = nil @diary.each_section{|x| @section = x} end it { expect(@section.body).to eq("\n"+@orig_source.lines.to_a.last+"\n") } end describe 'stashes in pre, code, plugin' do before do source = <<-'EOF' # subTitle ``` ruby -e "puts \"hello, world.\"" ``` `ruby -e "puts \"hello, world.\""` {{plugin "\0", "\1", "\2"}} EOF @diary.append(source) @html = <<-'EOF'
<%=section_enter_proc( Time.at( 1041346800 ) )%>

<%= subtitle_proc( Time.at( 1041346800 ), "subTitle" ) %>

ruby -e "puts \"hello, world.\""

ruby -e "puts \"hello, world.\""

<%=plugin "\0", "\1", "\2"%>

<%=section_leave_proc( Time.at( 1041346800 ) )%>
EOF end it { @diary.to_html.should eq @html } end end # Local Variables: # mode: ruby # indent-tabs-mode: t # tab-width: 3 # ruby-indent-level: 3 # End: