# encoding: UTF-8 require "spec_helper" describe "RedCloth::Formatters::Plain" do it "simple test" do RedCloth.new("p. this is *simple* _test_").to_plain.should == "this is simple test" end describe "Writing Paragraph Text" do describe "Simple paragraphs" do it "implicit" do input = "This is a paragraph.\n\nThis is another paragraph" output = "This is a paragraph.\nThis is another paragraph" RedCloth.new(input).to_plain.should == output end it "explicit" do input = "p. This is one paragraph.\n\np. This is another." output = "This is one paragraph.\nThis is another." RedCloth.new(input).to_plain.should == output end end describe "Line breaks" do it "implicit" do input = "Roses are red,\nViolets are blue,\nI'd like a sandwich;\nPerhaps even two." RedCloth.new(input).to_plain.should == input end it "in tags" do input = "
\nMirror mirror\non the wall...\n" output = "\nMirror mirror\non the wall...\n" RedCloth.new(input).to_plain.should == output end end describe "Curly quotes" do it "quotations" do input = "\"I said, 'hold the mayo' twice!\"" RedCloth.new(input).to_plain.should == input end it "apostrophes" do input = "We went to Steven's mother's house for a party." RedCloth.new(input).to_plain.should == input end end describe "Dashes" do it "single and double hyphens" do input = "I could be happy--fantastically happy--on twenty-one thousand a year if I only had to work 9 am - 1 pm." output = "I could be happy-fantastically happy-on twenty-one thousand a year if I only had to work 9 am - 1 pm." RedCloth.new(input).to_plain.should == output end it "between words" do input = "June - July 1967" RedCloth.new(input).to_plain.should == input end it "em dashes" do input = "Please use the em dash closed--or open if you must -- but I prefer it closed." output = "Please use the em dash closed-or open if you must - but I prefer it closed." RedCloth.new(input).to_plain.should == output end end describe "Ellipses" do it "tree periods" do input = "He thought and thought ... and then thought some more." RedCloth.new(input).to_plain.should == input end it "in conjunction with spaces and other punctuation" do input = "Four score and seven years ago our fathers brought forth...a new nation...dedicated to the proposition that all men are created equal...." RedCloth.new(input).to_plain.should == input end end describe "Dimension sign" do it "lowercase letter x" do input = "4 x 4 = 16" RedCloth.new(input).to_plain.should == input end it "to represent feet and inches" do input = "My office measures 5' x 5'6\"." RedCloth.new(input).to_plain.should == input end it "spaces are optional" do input = "4x4=16" RedCloth.new(input).to_plain.should == input end end it "Registered, trademark, and copyright symbols" do input = "RegisteredTrademark(r), Trademark(tm), and Copyright (c) 2008" output = "RegisteredTrademark®, Trademark™, and Copyright © 2008" RedCloth.new(input).to_plain.should == output end it "Acronyms" do input = "The EPA(Environmental Protection Agency) is measuring GHG(greenhouse gas) emissions." RedCloth.new(input).to_plain.should == input end it "Uppercase" do input = "Many NASDAQ companies are ISO certified." RedCloth.new(input).to_plain.should == input end end describe "Page Layout" do it "Headings" do input = "h1. This is a Heading 1\n\nThis might be an introductory paragraph on the general topic.\n\nh2. Heading 2 gets more specific\n\nNow we're getting into the details." output = "This is a Heading 1\nThis might be an introductory paragraph on the general topic.\nHeading 2 gets more specific\nNow we're getting into the details." RedCloth.new(input).to_plain.should == output end describe "Block quotations" do it "long quotations" do input = "Even Mr. Sedaris, a noted luddite, has finally succumbed to doing his writing on a computer. The Internet, however, remains an idiotic trifle:\n\n" input += "bq. I've never seen the Internet. I don't have email. I just enjoy lying on the couch and reading a magazine. When people say, \"You should visit my Web page,\" I'm always perplexed by it. Why? What do you do there?\n\n" input += "Haven't we all pondered that at one time or another?" output = "Even Mr. Sedaris, a noted luddite, has finally succumbed to doing his writing on a computer. The Internet, however, remains an idiotic trifle:\n" output += "I've never seen the Internet. I don't have email. I just enjoy lying on the couch and reading a magazine. When people say, \"You should visit my Web page,\" I'm always perplexed by it. Why? What do you do there?\n" output += "Haven't we all pondered that at one time or another?" RedCloth.new(input).to_plain.should == output end it "citation URL immediately following the period" do input = "A standard Lorem Ipsum passage has been used since the 1500s:\n\n" input += "bq.:http://www.lipsum.com/ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." output = "A standard Lorem Ipsum passage has been used since the 1500s:\n" output += "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." RedCloth.new(input).to_plain.should == output end it "more than one paragraph" do input = "bq.. This is one paragraph.\n\n" input += "Another paragraph, also part of the quote.\n\n" input += "p. A normal paragraph ends the quote." output = "This is one paragraph.\n" output += "Another paragraph, also part of the quote.\n" output += "A normal paragraph ends the quote." RedCloth.new(input).to_plain.should == output end end it "Bullet lists" do input = "Textile has several advantages over HTML:\n\n" input += "* It's easier on the eyes\n" input += "* You don't have to write all those HTML tags\n" input += "** By not writing the tags yourself, you're less likely to make coding mistakes\n" input += "** It requires fewer keystrokes\n" input += "*** You don't wear out the keys on your keyboard as fast\n" input += "*** You won't wear out your fingers as fast\n" input += "* You can write it much quicker" output = "Textile has several advantages over HTML:\n" output += "- It's easier on the eyes\n" output += "- You don't have to write all those HTML tags\n" output += " - By not writing the tags yourself, you're less likely to make coding mistakes\n" output += " - It requires fewer keystrokes\n" output += " - You don't wear out the keys on your keyboard as fast\n" output += " - You won't wear out your fingers as fast\n" output += "- You can write it much quicker" RedCloth.new(input).to_plain.should == output end it "Numbered lists" do input = "How to make a PB&J:\n\n" input += "# Gather bread, peanut butter, and jelly\n" input += "# Slice the bread if necessary\n" input += "# Assemble the sandwich\n" input += "## Spread peanut butter on one slice of bread\n" input += "## Put jelly on another slice\n" input += "## Put the two slices together\n" input += "# Enjoy" output = "How to make a PB&J:\n" output += "- Gather bread, peanut butter, and jelly\n" output += "- Slice the bread if necessary\n" output += "- Assemble the sandwich\n" output += " - Spread peanut butter on one slice of bread\n" output += " - Put jelly on another slice\n" output += " - Put the two slices together\n" output += "- Enjoy" RedCloth.new(input).to_plain.should == output end it "Mixed nested lists" do input = "Three reasons to walk to work:\n\n" input += "# It saves fuel\n" input += "# It's good for your health\n" input += "** Walking burns calories\n" input += "** Time outside means lower stress\n" input += "# It's good for the environment" output = "Three reasons to walk to work:\n" output += "- It saves fuel\n" output += "- It's good for your health\n" output += " - Walking burns calories\n" output += " - Time outside means lower stress\n" output += "- It's good for the environment" RedCloth.new(input).to_plain.should == output end it "Definition lists" do input = "- coffee := Hot and black\n" input += "- tea := Also hot, but a little less black\n" input += "- milk :=\n" input += "Nourishing beverage for baby cows.\n\n" input += "Cold drink that goes great with cookies. =:" output = "coffee:\n Hot and black\n" output += "tea:\n Also hot, but a little less black\n" output += "milk:\n Nourishing beverage for baby cows.\n" output += "Cold drink that goes great with cookies." RedCloth.new(input).to_plain.should == output end it "Footnotes" do input = "42.7% of all statistics are made up on the spot.[1]\n\n" input += "fn1. \"Dr. Katz\":http://en.wikiquote.org/wiki/Steven_Wright" output = "42.7% of all statistics are made up on the spot." RedCloth.new(input).to_plain.should == output end describe "Tables" do it "simple" do input = "|_. name|_. age|\n" input += "|Walter|5|\n" input += "|Florence|6|" RedCloth.new(input).to_plain.should == "" end it "cellspan" do input = "|{background:#ddd}. Cell with background|Normal|\n" input += "|\2. Cell spanning 2 columns|\n" input += "|/2. Cell spanning 2 rows|one|\n" input += "|two|\n" input += "|>. Right-aligned cell|<. Left-aligned cell|" RedCloth.new(input).to_plain.should == "" end it "with attributes" do input = "table(#prices).\n" input += "|Adults|$5|\n" input += "|Children|$2|" RedCloth.new(input).to_plain.should == "" end end it "Divisions" do input = "div. A simple div." output = "A simple div." RedCloth.new(input).to_plain.should == output end end describe "Phrase modifiers" do it "Strong importance" do input = "Don't *ever* pull this lever." output = "Don't ever pull this lever." RedCloth.new(input).to_plain.should == output end it "Stress emphasis" do input = "You didn't actually _believe_ her, did you?" output = "You didn't actually believe her, did you?" RedCloth.new(input).to_plain.should == output end it "Stylistic offset" do input = "Search results for **Textile**:\n\n" input += "h4. [\"**Textile** (markup language) - Wikipedia\":http://en.wikipedia.org/wiki/Textile_(markup_language)]\n\n" input += "**Textile** is a lightweight markup language originally developed by Dean Allen and billed as a \"humane Web text generator\". **Textile** converts its marked-up text ..." output = "Search results for Textile:\n" output += "Textile (markup language) - Wikipedia