# -*- encoding: utf-8 -*- require File.dirname(__FILE__) + '/spec_helper.rb' require File.dirname(__FILE__) + '/../lib/nora_mark' require 'nokogiri' require File.dirname(__FILE__) + '/nokogiri_test_helper.rb' describe NoraMark::Document do describe 'parse' do it 'generate valid xhtml' do text = 'some text' noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title') xhtml = Nokogiri::XML::Document.parse(noramark.html[0]) expect(xhtml.root.name).to eq('html') expect(xhtml.root.namespaces['xmlns']) .to eq('http://www.w3.org/1999/xhtml') expect(xhtml.root['xml:lang']) .to eq('ja') expect(xhtml.root.element_children[0].name).to eq 'head' expect(xhtml.root.at_xpath('xmlns:head/xmlns:title').text) .to eq('the title') expect(xhtml.root.element_children[1].name).to eq 'body' end describe 'implicit markup' do it 'convert simple paragraph' do text = "ここから、パラグラフがはじまります。\n「二行目です。」\n三行目です。\n\n\n ここから、次のパラグラフです。" noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title') converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children.size).to eq 2 expect(body.element_children[0].selector_and_children) .to eq( ['div.pgroup', ['p', 'ここから、パラグラフがはじまります。'], ['p.noindent', '「二行目です。」'], ['p', '三行目です。'] ] ) expect(body.element_children[1].selector_and_children) .to eq( ['div.pgroup', ['p', 'ここから、次のパラグラフです。']] ) end it 'convert simple paragraph with BOM' do text = "\uFEFFここから、パラグラフがはじまります。\n「二行目です。」\n三行目です。\n\n\n ここから、次のパラグラフです。" noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title') converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children.size).to eq 2 expect(body.element_children[0].selector_and_children) .to eq( ['div.pgroup', ['p', 'ここから、パラグラフがはじまります。'], ['p.noindent', '「二行目です。」'], ['p', '三行目です。'] ] ) expect(body.element_children[1].selector_and_children) .to eq( ['div.pgroup', ['p', 'ここから、次のパラグラフです。']] ) end it 'convert simple paragraph in english mode' do text = "paragraph begins.\n2nd line.\n 3rd line.\n\n\n next paragraph." noramark = NoraMark::Document.parse(text, lang: 'en', title: 'the title') converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children.size).to eq 2 expect(body.element_children[0].selector_and_children) .to eq( ['p', 'paragraph begins.', ['br', ''], '2nd line.', ['br', ''], '3rd line.' ] ) expect(body.element_children[1].selector_and_children) .to eq( ['p', 'next paragraph.'] ) end it 'convert simple paragraph in english mode specified in frontmatter' do text = "---\nlang: en\ntitle: the title\n---\n\n\n\nparagraph begins.\n2nd line.\n 3rd line.\n\n\n next paragraph." noramark = NoraMark::Document.parse(text) converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children.size).to eq 2 expect(body.element_children[0].selector_and_children) .to eq( ['p', 'paragraph begins.', ['br', ''], '2nd line.', ['br', ''], '3rd line.' ] ) expect(body.element_children[1].selector_and_children) .to eq( ['p', 'next paragraph.'] ) end it 'convert simple paragraph in japanese mode, but paragraph mode is default' do text = "paragraph begins.\n2nd line.\n 3rd line.\n\n\n next paragraph." noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title', paragraph_style: :default) converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children.size).to eq 2 expect(body.element_children[0].selector_and_children) .to eq( ['p', 'paragraph begins.', ['br', ''], '2nd line.', ['br', ''], '3rd line.' ] ) expect(body.element_children[1].selector_and_children) .to eq( ['p', 'next paragraph.'] ) end it 'convert simple paragraph in japanese mode, but paragraph mode is default (using frontmatter)' do text = "---\nlang: ja\ntitle: the title\nparagraph_style: default\n---\nparagraph begins.\n2nd line.\n 3rd line.\n\n\n next paragraph." noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title', paragraph_styl: :default) converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children.size).to eq 2 expect(body.element_children[0].selector_and_children) .to eq( ['p', 'paragraph begins.', ['br', ''], '2nd line.', ['br', ''], '3rd line.' ] ) expect(body.element_children[1].selector_and_children) .to eq( ['p', 'next paragraph.'] ) end end describe 'attribute handling' do it 'accept data- named parameter as attributes' do noramark = NoraMark::Document.parse('[span[data-type:foobar]{lorem ipsum}]') converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children[0].selector_and_children) .to eq( ['p', ["span[data-type='foobar']", 'lorem ipsum']] ) end end describe 'divs and hN headers' do it 'parse paragraph with header' do text = "h1: タイトルです。\r\nここから、パラグラフがはじまります。\n\nh2.column:ふたつめの見出しです。\n ここから、次のパラグラフです。\nh3.third.foo: クラスが複数ある見出しです" noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title') converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children.size).to eq 5 expect(body.element_children[0].a).to eq ['h1', 'タイトルです。'] expect(body.element_children[1].selector_and_children) .to eq( ['div.pgroup', ['p', 'ここから、パラグラフがはじまります。'] ] ) expect(body.element_children[2].a).to eq ['h2.column', 'ふたつめの見出しです。'] expect(body.element_children[3].selector_and_children) .to eq( ['div.pgroup', ['p', 'ここから、次のパラグラフです。'] ] ) expect(body.element_children[4].a).to eq ['h3.third.foo', 'クラスが複数ある見出しです'] end it 'parse div and paragraph' do text = "d {\n1st line. \n}" noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the document title') converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children[0].selector_and_children) .to eq( ['div', ['div.pgroup', ['p', '1st line.'] ] ] ) end it 'parse div without pgroup' do text = "d('wo-pgroup') {\n1st line. \n}" noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title') converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children[0].selector_and_children) .to eq( ['div', ['p', '1st line.'] ] ) end it 'parse nested div without pgroup' do text = "d(wo-pgroup) {\nd {\nnested.\n} \n}" noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title') converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children[0].selector_and_children) .to eq( ['div', ['div', ['p', 'nested.'] ] ] ) end it 'handle divs with empty lines' do text = "\n\n\nd('wo-pgroup') {\n\n\n1st line. \n\n\n}\n\n\nd {\n 2nd div.\n}" noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title') converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children[0].selector_and_children) .to eq( ['div', ['p', '1st line.'] ]) expect(body.element_children[1].selector_and_children) .to eq( ['div', ['div.pgroup', ['p', '2nd div.']] ] ) end it 'parse nested div without pgroup and with pgroup' do text = "d(wo-pgroup) {\nd {\nnested.\n} \n}\n\nd {\nin pgroup\n}" noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title') converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children[0].selector_and_children) .to eq( ['div', ['div', ['p', 'nested.'] ] ]) expect(body.element_children[1].selector_and_children) .to eq( ['div', ['div.pgroup', ['p', 'in pgroup'] ] ]) end it 'parse div with class' do text = "d.preface-one {\n h1: title.\n}" noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title') converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children[0].selector_and_children) .to eq( ['div.preface-one', ['h1', 'title.'] ] ) end it 'parse div with id and class' do text = "d#thecontents.preface-one {\nh1: title.\n}" noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title') converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children[0].selector_and_children(remove_id: false)) .to eq( ['div#thecontents.preface-one', ['h1#heading_index_1', 'title.'] ] ) end it 'parse nested div' do text = "d.preface {\n outer div. \n d.nested {\n nested!\n}\nouter div again.\n}" noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title') converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children[0].selector_and_children) .to eq( ['div.preface', ['div.pgroup', ['p', 'outer div.'] ], ['div.nested', ['div.pgroup', ['p', 'nested!'] ] ], ['div.pgroup', ['p', 'outer div again.'] ], ] ) end end describe 'article and section' do it 'parse article' do text = "art {\n in the article.\n}" noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title') converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children[0].selector_and_children) .to eq( ['article', ['div.pgroup', ['p', 'in the article.'] ] ] ) end it 'parse article with other notation' do text = "arti {\n in the article.\n}" noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title') converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children[0].selector_and_children) .to eq( ['article', ['div.pgroup', ['p', 'in the article.'] ] ] ) end it 'parse article with yet anther notation' do text = "article {\n in the article.\n}" noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title') converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children[0].selector_and_children) .to eq( ['article', ['div.pgroup', ['p', 'in the article.'] ] ] ) end it 'parse section ' do text = "art {\nsec {\n section in the article. \n}\n}" noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title') converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children[0].selector_and_children) .to eq( ['article', ['section', ['div.pgroup', ['p', 'section in the article.'] ] ] ] ) end it 'parse section with other notation' do text = "art {\nsect {\n section in the article. \n}\n}" noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title') converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children[0].selector_and_children) .to eq( ['article', ['section', ['div.pgroup', ['p', 'section in the article.'] ] ] ] ) end it 'parse section with yet other notation' do text = "art {\nsection {\n section in the article. \n}\n}" noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title') converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children[0].selector_and_children) .to eq( ['article', ['section', ['div.pgroup', ['p', 'section in the article.'] ] ] ] ) end end describe 'other block command' do it 'handle block image' do text = "this is normal line.\nimage(./image1.jpg, \"alt text\"): caption text" noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title') converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children[0].selector_and_children) .to eq( ['div.pgroup', ['p', 'this is normal line.'] ] ) expect(body.element_children[1].selector_and_children) .to eq( ['figure.img-wrap', ["img[src='./image1.jpg'][alt='alt text']", ''], ['figcaption', 'caption text'] ] ) end it 'handle block image with before caption' do text = "this is normal line.\nimage(./image1.jpg, alt text)[caption_before: 'true']: caption text" noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title') converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children[0].selector_and_children) .to eq( ['div.pgroup', ['p', 'this is normal line.'] ] ) expect(body.element_children[1].selector_and_children) .to eq( ['figure.img-wrap', ['figcaption', 'caption text'], ["img[src='./image1.jpg'][alt='alt text']", ''] ] ) end it 'handle block image without caption' do text = "this is normal line.\nimage(./image1.jpg, alt text):" noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title') converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children[0].selector_and_children) .to eq( ['div.pgroup', ['p', 'this is normal line.'] ] ) expect(body.element_children[1].selector_and_children) .to eq( ['figure.img-wrap', ["img[src='./image1.jpg'][alt='alt text']", ''] ] ) end it 'handle page change article' do text = "this is start.\nnewpage:\n---\ntitle: page changed\n---\n\nthis is second page.\nnewpage:\nand the third." noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title') converted = noramark.html expect(converted.size).to eq 3 body1 = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body1.element_children[0].selector_and_children) .to eq( ['div.pgroup', ['p', 'this is start.'] ] ) head2 = Nokogiri::XML::Document.parse(converted[1]).root.at_xpath('xmlns:head') expect(head2.element_children[0].a).to eq ['title', 'page changed'] body2 = Nokogiri::XML::Document.parse(converted[1]).root.at_xpath('xmlns:body') expect(body2.element_children[0].selector_and_children) .to eq( ['div.pgroup', ['p', 'this is second page.'] ] ) head3 = Nokogiri::XML::Document.parse(converted[2]).root.at_xpath('xmlns:head') expect(head3.element_children[0].a).to eq ['title', 'the title'] body3 = Nokogiri::XML::Document.parse(converted[2]).root.at_xpath('xmlns:body') expect(body3.element_children[0].selector_and_children) .to eq( ['div.pgroup', ['p', 'and the third.'] ] ) end it 'handle stylesheets' do text = "d.styled {\n this is styled document.\n}" noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the document title', stylesheets: ['reset.css', 'mystyle.css']) converted = noramark.html head = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:head') expect(head.element_children[0].a).to eq ['title', 'the document title'] expect(head.element_children[1].a).to eq ["link[rel='stylesheet'][type='text/css'][href='reset.css']", ''] expect(head.element_children[2].a).to eq ["link[rel='stylesheet'][type='text/css'][href='mystyle.css']", ''] end it 'handle custom paragraph' do text = "this is normal line.\np.custom: this text is in custom class." noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title') converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children[0].selector_and_children) .to eq( ['div.pgroup', ['p', 'this is normal line.'], ['p.custom', 'this text is in custom class.'] ] ) end it 'handle any block' do text = "this is normal line.\ncite {\n this block should be in cite. \n}" noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title') converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children[0].selector_and_children) .to eq( ['div.pgroup', ['p', 'this is normal line.'] ] ) expect(body.element_children[1].selector_and_children) .to eq( ['cite', ['div.pgroup', ['p', 'this block should be in cite.'] ] ] ) end it 'convert h1 in article after title' do text = "---\nstylesheets: css/default.css\ntitle: foo\n---\narticle.atogaki {\n\nh1: あとがき。\n\natogaki\n}" noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title') converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children[0].selector_and_children) .to eq( ["article.atogaki", ["h1", "あとがき。"], ["div.pgroup", ["p", "atogaki"]]] ) end end describe 'inline' do it 'handle link' do text = " link to [link(http://github.com/skoji/noramark){noramark repository}]. \ncan you see this?" noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title') converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children[0].selector_and_children) .to eq( ['div.pgroup', ['p', 'link to ', ["a[href='http://github.com/skoji/noramark']", 'noramark repository'], '.' ], ['p', 'can you see this?'] ] ) end it 'handle link with l' do text = "link to [l(http://github.com/skoji/noramark){noramark repository}]. \ncan you see this?" noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title') converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children[0].selector_and_children) .to eq( ['div.pgroup', ['p', 'link to ', ["a[href='http://github.com/skoji/noramark']", 'noramark repository'], '.' ], ['p', 'can you see this?'] ] ) end it 'handle span' do text = "p.custom: this text is in [sp.keyword{custom}] class." noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title') converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children[0].selector_and_children) .to eq( ['div.pgroup', ['p.custom', 'this text is in ', ['span.keyword', 'custom'], ' class.' ]] ) end it 'handle inline image' do text = "simple image [img(./image1.jpg, alt)]." noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title') converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children[0].selector_and_children) .to eq( ['div.pgroup', ['p', 'simple image ', ["img[src='./image1.jpg'][alt='alt']", ''], '.']] ) end it 'handle any inline' do text = "should be [strong{marked as strong}]." noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title') converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children[0].selector_and_children) .to eq( ['div.pgroup', ['p', 'should be ', ['strong', 'marked as strong'],'.']] ) end it 'convert inline command within line block' do text = "h1: [tcy{20}]縦中横タイトル" noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title') converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children[0].selector_and_children).to eq ['h1', ['span.tcy', '20'], '縦中横タイトル'] end it 'handle ruby' do text = "[ruby(とんぼ){蜻蛉}]の[ruby(めがね){眼鏡}]はみずいろめがね" noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title') converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children[0].selector_and_children).to eq ['div.pgroup', ['p', ['ruby', '蜻蛉', ['rp','('],['rt','とんぼ'],['rp', ')']], 'の', ['ruby', '眼鏡', ['rp','('],['rt','めがね'],['rp', ')']], 'はみずいろめがね']] end it 'handle tatechuyoko' do text = "[tcy{10}]年前のことだった" noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title') converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children[0].selector_and_children) .to eq( ['div.pgroup', ['p', ['span.tcy', '10'], '年前のことだった'] ]) end it 'handle code inline' do text = "`this is inside code and [s{will not parsed}]`. you see?" noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title') converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children[0].selector_and_children) .to eq( ['div.pgroup', ['p', ['code', 'this is inside code and [s{will not parsed}]'], '. you see?'] ]) end it 'handle code escaped inline' do text = "\\`this is not inside code and [strong{will be parsed}]\\`. you see?" noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title') converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children[0].selector_and_children) .to eq( ['div.pgroup', ['p', '`this is not inside code and ', ['strong', 'will be parsed'], '`. you see?'] ]) end it 'handle code inline (long format)' do text = "[code.the-class{this is inside code and `backquote will not be parsed`}]. you see?" noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title') converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children[0].selector_and_children) .to eq( ['div.pgroup', ['p', ['code.the-class', 'this is inside code and `backquote will not be parsed`'], '. you see?'] ]) end it 'handle non-escaped inline' do text = "the text following will not be escaped: [noescape{©}]" noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title') converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children[0].selector_and_children) .to eq( ['div.pgroup', ['p', 'the text following will not be escaped: ©'] ]) end end describe 'list' do it 'handle ordered list ' do text = "this is normal line.\n1. for the 1st.\n2. secondly, blah.\n3. and last...\nthe ordered list ends." noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title') converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children.size).to eq 3 expect(body.element_children[0].selector_and_children) .to eq( ['div.pgroup', ['p', 'this is normal line.'] ]) expect(body.element_children[1].selector_and_children) .to eq( ['ol', ['li', 'for the 1st.'], ['li', 'secondly, blah.'], ['li', 'and last...'] ]) expect(body.element_children[2].selector_and_children) .to eq( ['div.pgroup', ['p', 'the ordered list ends.'] ]) end it 'handle unordered list ' do text = "this is normal line.\n* for the 1st.\n* secondly, blah.\n* and last...\nthe ordered list ends." noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title') converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children.size).to eq 3 expect(body.element_children[0].selector_and_children) .to eq( ['div.pgroup', ['p', 'this is normal line.'] ]) expect(body.element_children[1].selector_and_children) .to eq( ['ul', ['li', 'for the 1st.'], ['li', 'secondly, blah.'], ['li', 'and last...'] ]) expect(body.element_children[2].selector_and_children) .to eq( ['div.pgroup', ['p', 'the ordered list ends.'] ]) end it 'handle nested unordered list ' do text = "this is normal line.\n* for the 1st.\n** nested.\n* and last...\nthe ordered list ends." noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title') converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children.size).to eq 3 expect(body.element_children[0].selector_and_children) .to eq( ['div.pgroup', ['p', 'this is normal line.'] ]) expect(body.element_children[1].selector_and_children) .to eq( ['ul', ['li', 'for the 1st.', ['ul', ['li', 'nested.']]], ['li', 'and last...'] ]) expect(body.element_children[2].selector_and_children) .to eq( ['div.pgroup', ['p', 'the ordered list ends.'] ]) end it 'handle definition list ' do text = "this is normal line.\n;: 1st : this is the first definition\n;: 2nd : blah :blah.\n;: 3rd: this term is the last.\nthe list ends." noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title') converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children.size).to eq 3 expect(body.element_children[0].selector_and_children) .to eq( ['div.pgroup', ['p', 'this is normal line.'] ]) expect(body.element_children[1].selector_and_children) .to eq( ['dl', ['dt', '1st'],['dd', 'this is the first definition'], ['dt', '2nd'],['dd', 'blah :blah.'], ['dt', '3rd'],['dd', 'this term is the last.'], ]) expect(body.element_children[2].selector_and_children) .to eq( ['div.pgroup', ['p', 'the list ends.'] ]) end it 'handle long definition list ' do text = "this is normal line.\n;: 1st {\n this is the first definition\n}\n;: 2nd { \nblah :blah.\n}\n;: 3rd{\n this term is the last.\n}\nthe list ends." noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title') converted = noramark.html body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body') expect(body.element_children.size).to eq 3 expect(body.element_children[0].selector_and_children) .to eq( ['div.pgroup', ['p', 'this is normal line.'] ]) expect(body.element_children[1].selector_and_children) .to eq( ['dl', ['dt', '1st'],['dd', ['div.pgroup', ['p', 'this is the first definition']]], ['dt', '2nd'],['dd', ['div.pgroup', ['p', 'blah :blah.']]], ['dt', '3rd'],['dd', ['div.pgroup', ['p', 'this term is the last.']]] ]) expect(body.element_children[2].selector_and_children) .to eq( ['div.pgroup', ['p', 'the list ends.'] ]) end it 'escape html in definition list' do text = ";:definition