# -*- coding: utf-8; -*- require 'spec_helper' require 'tdiary' require 'misc/style/gfm/gfm_style' describe TDiary::GfmDiary do before do @diary = TDiary::GfmDiary.new(Time.at( 1041346800 ), "TITLE", "") end describe '#append' do before do @source = <<-'EOF' # subTitle honbun ## subTitleH4 honbun 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

<%=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

<%=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 '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 describe 'emoji' 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 # Local Variables: # mode: ruby # indent-tabs-mode: t # tab-width: 3 # ruby-indent-level: 3 # End: