diff --git a/bristlecode.rb b/bristlecode.rb index b8f8a43..935cdee 100644 --- a/bristlecode.rb +++ b/bristlecode.rb @@ -17,6 +17,8 @@ module Bristlecode rule(:bold_close) { str('[/b]') | str('[/B]') | eof } rule(:bold) { bold_open >> children.as(:bold) >> bold_close } + rule(:linebreak) { str('[br]').as(:br) } + rule(:italic_open) { str('[i]') | str('[I]') } rule(:italic_close) { str('[/i]') | str('[/I]') | eof } rule(:italic) { italic_open >> children.as(:italic) >> italic_close } @@ -28,11 +30,11 @@ module Bristlecode rule(:url) { simple_url.as(:url) } rule(:eof) { any.absent? } - rule(:tag) { bold | italic | url } + rule(:tag) { bold | italic | url | linebreak } rule(:elem) { text.as(:text) | tag } rule(:tag_open) { bold_open | italic_open | url_open } rule(:tag_close) { bold_close | italic_close | url_close } - rule(:tag_delim) { tag_open | tag_close } + rule(:tag_delim) { tag_open | tag_close | linebreak } rule(:text) { (tag_delim.absent? >> any).repeat(1) } rule(:children) { space? >> elem.repeat } @@ -46,6 +48,7 @@ module Bristlecode rule(text: simple(:text)) { Text.new(text) } rule(doc: subtree(:doc)) { Doc.new(doc) } rule(url: subtree(:url)) { Url.new(url) } + rule(br: simple(:br)) { Linebreak.new } end class Doc @@ -118,4 +121,10 @@ module Bristlecode "#{title}" end end + + class Linebreak + def to_html + "
" + end + end end diff --git a/spec/bristlecode/parser_spec.rb b/spec/bristlecode/parser_spec.rb index 5e2199d..1f45cc0 100644 --- a/spec/bristlecode/parser_spec.rb +++ b/spec/bristlecode/parser_spec.rb @@ -61,6 +61,10 @@ module Bristlecode output = 'x[b]y[/b]z' expect(to_html(input)).to eq(output) end + + it 'renders a linebreak' do + expect(to_html('[br]')).to eq('
') + end end describe Parser do @@ -163,5 +167,11 @@ module Bristlecode expect(parser.url).not_to parse('[url]x[url]y[/url]z[/url]') end end + + describe '#linebreak' do + it 'does its thing' do + expect(parser.linebreak).to parse('[br]') + end + end end end