require 'spec_helper' describe Mastalk::Document do context 'Without mastalk syntax' do let(:context) { "###test\nwith markdown" } let(:expected) { "

test

\n

with markdown

\n" } subject { Mastalk::Document.new(context) } it 'kramdown behaviour with no tags' do expect(Mastalk::Document.new('test').to_html).to eq("

test

\n") end it 'converts to html' do expect(subject.to_html).to eq(expected) end context 'multiline' do let(:expected) { "

TEST

\n\n

with other stuff

\n\n" } let(:context) { "### TEST\r\n\r\nwith other stuff\r\n\r\n " } it 'converts to html' do expect(subject.to_html).to eq(expected) end end end subject { Mastalk::Document.new(source) } let(:expected) { "
test
\n" } context 'custom extension' do let(:source) { '$Etest$E' } it 'pre-processes custom tags' do subject.extension('$E') { |body| "
#{body}
" } expect(subject.to_html).to eq(expected) end context 'multi line' do let(:source) { '$Etest$E$Shello$FIN' } let(:expected) { "
test
\n
hello
\n" } it 'processes multi line' do subject.extension('$E') { |body| "
#{body}
" } subject.extension('$S', '$FIN') { |body| "
#{body}
" } expect(subject.to_html).to eq(expected) end end end context 'extension with start and stop' do let(:source) { '$STARTtest$END' } it 'pre-processes custom tags' do subject.extension('$START', '$END') { |body| "
#{body}
" } expect(subject.to_html).to eq(expected) end end context 'extension with other extensions inside' do let(:source) { "$why\n###header\nbody\n$why" } let(:expected) { "
\n

header

\n

body

\n\n
\n" } it 'parses nested structures' do expect(subject.to_html).to eq(expected) end end context 'with newline as end' do let(:source) { "$yes-no\n [y] yes [/y] \n [n] no [/n] \n $end $why\n###header\nbody\n$why" } let(:expected) do "\n

header

\n

body

\n\n
\n" end it 'pre-processes custom tags' do expect(subject.to_html).to eq(expected) end end context 'two matches after each other' do let(:source) { "$yes-no\n [y] **yes** [/y] \n $end $yes-no\ [n] **no** [/n] \n $end" } let(:expected) do "" end it 'pre-processes correctly' do expect(subject.to_html.gsub("\n", '')).to eq(expected) end end context 'two callouts after each other' do let(:source) { "$~callout\n ##yes ~$ $~callout\n ##yes ~$" } let(:expected) do "
\n

yes

\n\n
\n
\n

yes

\n\n
\n" end it 'pre-processes correctly' do expect(subject.to_html).to eq(expected) end end context 'ticks inside table' do let(:source) { "|table|header|\n|$yes-no [y] yes [/y] $end|here|" } let(:expected) do "\n \n \n \n \n \n \n \n \n \n \n
tableheader
  • yes
here
\n" end it 'outputs ticks inside a table' do expect(subject.to_html).to eq(expected) end end context 'bullets inside table' do let(:source) { "|table|header|\n|$bullet [%] yes [/%] $point|here|" } let(:expected) do "\n \n \n \n \n \n \n \n \n \n \n
tableheader
  • yes
here
\n" end it 'outputs a bullet list inside a table' do expect(subject.to_html).to eq(expected) end end context 'line breaks' do let(:source) { "@~ @~" } let(:expected) do "



\n" end it 'outputs a line break' do expect(subject.to_html).to eq(expected) end end context 'bright video' do let(:source) { "$~brightcove_video3739688349001~$" } it 'pre-processes correctly' do expect(subject.to_html).to match(/data-video-id\="3739688349001"/) end end context 'cost calculator' do let(:source) {"$~cost-calc1~$"} it 'pre-processes correctly' do expect(subject.to_html).to include('https://www.moneyadviceservice.org.uk/en/cost-calculator-builder/embed/calculators/1') end end context 'when youtube video' do let(:source) { '({oZ0_U108aZw})' } it 'outputs the youtube embed video' do expect(subject.to_html).to include('https://www.youtube.com/embed/oZ0_U108aZw') end end context 'block with media and content' do let(:source) { '$bl $bl_c Content bl_c$ $bl_m bl_m$ bl$' } let(:expected) do %(
\n
Content
\n
\n) end it 'outputs a block layout with media and content container blocks' do expect(subject.to_html).to eq(expected) end end context 'collapsable section' do let(:source) { '$- -$' } let(:expected) do %(
\n \n\n
\n) end it 'outputs a collapsible section block' do expect(subject.to_html).to eq(expected) end end context 'collapsable header' do let(:source) { '$= Content =$' } let(:expected) do %(
\n \n
\n) end it 'outputs a collapsible header' do expect(subject.to_html).to eq(expected) end end end