import unittest, string from pymarkdown import Markdown, sub class PyMarkDownTestCase(unittest.TestCase): def setUp(self): pass def testH1(self): text = """ asdf ==== """ html = """
Foo |
This is a regular paragraph.
Foo |
This is another regular paragraph.
""" self.assertEquals(Markdown(text), html) def testHTMLEntities1(self): # & in URLs text = """asdf""" html = """ """ self.assertEquals(Markdown(text), html) def testHTMLEntities2(self): # Real entities (©) text = """©""" html = """©
""" self.assertEquals(Markdown(text), html) def testHTMLEntities3(self): # Normal & outside any magic text = """AT&T""" html = """AT&T
""" self.assertEquals(Markdown(text), html) def testHTMLLessThan(self): text = """4 < 5""" html = """4 < 5
""" self.assertEquals(Markdown(text), html) def testParagraphBreak(self): text = """This is a paragraph. This is another, long, long, long, long, long, long, long, long, long paragraph. It will have a break at the end of this line. ASDF ASDF The previous line ends with two spaces and should therefore have a br element And then another paragraph """ html = """This is a paragraph.
This is another, long, long, long, long, long, long, long, long, long
paragraph. It will have a break at the end of this line. ASDF ASDF
The previous line ends with two spaces and should therefore have a br
element
And then another paragraph
""" self.assertEquals(Markdown(text), html) def testBlockQuote1(self): text = """> This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet, > consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. > Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus. > > Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse > id sem consectetuer libero luctus adipiscing.""" html = """""" self.assertEquals(Markdown(text), html) def testBlockQuote2(self): text = """ > This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus. > Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse id sem consectetuer libero luctus adipiscing. """ html = """This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse id sem consectetuer libero luctus adipiscing.
""" self.assertEquals(Markdown(text), html) def testNestedBlockQuote1(self): text = """ > This is the first level of quoting. > > > This is nested blockquote. > > Back to the first level. """ html = """This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse id sem consectetuer libero luctus adipiscing.
""" self.assertEquals(Markdown(text), html) def testNestedBlockQuote1(self): text = """ > ## This is a header. > > 1. This is the first list item. > 2. This is the second list item. > > Here's some example code: > > return shell_exec("echo $input | $markdown_script"); """ html = """This is the first level of quoting.
This is nested blockquote.
Back to the first level.
""" self.assertEquals(Markdown(text), html) def testUnorderedList1(self): text = """ * Red * Green * Blue """ html = """This is a header.
- This is the first list item.
- This is the second list item.
Here's some example code:
return shell_exec("echo $input | $markdown_script");
Bird
Magic
This is a list item with two paragraphs. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus. Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
Suspendisse id sem consectetuer libero luctus adipiscing.
This is a list item with two paragraphs.
This is the second paragraph in the list item. You're only required to indent the first line. Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Another item in the same list.
A list item with a blockquote:
This is a blockquote inside a list item.
"""
html = """
A list item with a code block:
<code goes here>
"""
self.assertEquals(Markdown(text), html)
def testAccidentalOrderedList(self):
text = """1986. What a great season."""
html = """
- What a great season.
"""
self.assertEquals(Markdown(text), html)
def testAccidentalOrderedListFixed(self):
text = """1986\. What a great season."""
html = """1986. What a great season.
"""
self.assertEquals(Markdown(text), html)
def testCodeBlock(self):
text = """This is a normal paragraph:
This is a code block.
"""
html = """This is a normal paragraph:
This is a code block.
"""
self.assertEquals(Markdown(text), html)
def testCodeBlockIndentation(self):
text = """Here is an example of AppleScript:
tell application "Foo"
beep
end tell
"""
html = """Here is an example of AppleScript:
tell application "Foo"
beep
end tell
"""
self.assertEquals(Markdown(text), html)
def testCodeBlockEntities(self):
text = """ """
html = """<div class="footer">
© 2004 Foo Corporation
</div>
"""
self.assertEquals(Markdown(text), html)
def testHorisontalRule1(self):
text = """* * *"""
html = """
"""
self.assertEquals(Markdown(text), html)
def testHorisontalRule2(self):
text = """***"""
html = """
"""
self.assertEquals(Markdown(text), html)
def testHorisontalRule3(self):
text = """*****"""
html = """
"""
self.assertEquals(Markdown(text), html)
def testHorisontalRule4(self):
text = """- - -"""
html = """
"""
self.assertEquals(Markdown(text), html)
def testHorisontalRule5(self):
text = """---------------------------------------"""
html = """
"""
self.assertEquals(Markdown(text), html)
def testHorisontalRule6(self):
text = """_ _ _"""
html = """
"""
self.assertEquals(Markdown(text), html)
def testInlineLinkWithTitle(self):
text = """This is [an example](http://example.com/ "Title") inline link."""
html = """This is an example inline link.
"""
self.assertEquals(Markdown(text), html)
def testInlineLink(self):
text = """[This link](http://example.net/) has no title attribute."""
html = """This link has no title attribute.
"""
self.assertEquals(Markdown(text), html)
def testInlineRelativeLink(self):
text = """See my [About](/about/) page for details."""
html = """See my About page for details.
"""
self.assertEquals(Markdown(text), html)
def testReferenceLink(self):
text = """This is [an example][id] reference-style link.
[id]: http://example.com/ "Optional Title Here"
"""
html = """This is an example reference-style link.
"""
self.assertEquals(Markdown(text), html)
def testReferenceLinkWithSpace(self):
text = """This is [an example] [id] reference-style link.
[id]: http://example.com/ "Optional Title Here"
"""
html = """This is an example reference-style link.
"""
self.assertEquals(Markdown(text), html)
def testReferenceLinkWithBrackets(self):
text = """This is [an example][id] reference-style link.
[id]: "Optional Title Here"
"""
html = """This is an example reference-style link.
"""
self.assertEquals(Markdown(text), html)
def testReferenceLinkWithBrokenLine(self):
text = """This is [an example][id] reference-style link.
[id]: http://example.com/longish/path/to/resource/here
"Optional Title Here"
"""
html = """This is an example reference-style link.
"""
self.assertEquals(Markdown(text), html)
def testReferenceLinkCaseSensitivity(self):
text = """[link text][a]
[link text][A]
[a]: http://example.com
"""
html = """
"""
self.assertEquals(Markdown(text), html)
def testReferenceLinkImplicitName(self):
text = """[Google][]
[Google]: http://google.com/
"""
html = """
"""
self.assertEquals(Markdown(text), html)
def testReferenceLinkImplicitNameWithSpace(self):
text = """[Daring Fireball][]
[Daring Fireball]: http://daringfireball.net/
"""
html = """
"""
self.assertEquals(Markdown(text), html)
def testReferenceLinkInAction(self):
text = """I get 10 times more traffic from [Google] [1] than from
[Yahoo] [2] or [MSN] [3].
[1]: http://google.com/ "Google"
[2]: http://search.yahoo.com/ "Yahoo Search"
[3]: http://search.msn.com/ "MSN Search"
"""
html = """I get 10 times more traffic from Google than from
Yahoo or MSN.
"""
self.assertEquals(Markdown(text), html)
def testReferenceLinkImplicitNamesInAction(self):
text = """I get 10 times more traffic from [Google][] than from
[Yahoo][] or [MSN][].
[google]: http://google.com/ "Google"
[yahoo]: http://search.yahoo.com/ "Yahoo Search"
[msn]: http://search.msn.com/ "MSN Search"
"""
html = """I get 10 times more traffic from Google than from
Yahoo or MSN.
"""
self.assertEquals(Markdown(text), html)
def testLinkInAction(self):
text = """I get 10 times more traffic from [Google](http://google.com/ "Google")
than from [Yahoo](http://search.yahoo.com/ "Yahoo Search") or
[MSN](http://search.msn.com/ "MSN Search").
"""
html = """I get 10 times more traffic from Google
than from Yahoo or
MSN.
"""
self.assertEquals(Markdown(text), html)
def testEmphasis1(self):
text = """*single asterisks*"""
html = """single asterisks
"""
self.assertEquals(Markdown(text), html)
def testEmphasis2(self):
text = """_single underscores_"""
html = """single underscores
"""
self.assertEquals(Markdown(text), html)
def testStrong1(self):
text = """**double asterisks**"""
html = """double asterisks
"""
self.assertEquals(Markdown(text), html)
def testEmphasis2(self):
text = """__double underscores__"""
html = """double underscores
"""
self.assertEquals(Markdown(text), html)
def testEmphasisMiddleOfWord(self):
text = """un*fucking*believable"""
html = """unfuckingbelievable
"""
self.assertEquals(Markdown(text), html)
def testEmphasisEscaped(self):
text = """\*this text is surrounded by literal asterisks\*"""
html = """*this text is surrounded by literal asterisks*
"""
self.assertEquals(Markdown(text), html)
def testEmphasisSpacesAround(self):
text = """foo * this text is surrounded by literal asterisks with spaces * """
html = """foo * this text is surrounded by literal asterisks with spaces *
"""
self.assertEquals(Markdown(text), html)
def testInlineCode(self):
text = """Use the `printf()` function."""
html = """Use the printf()
function.
"""
self.assertEquals(Markdown(text), html)
def testInlineCodeLiteralBacktick(self):
text = """``There is a literal backtick (`) here.``"""
html = """There is a literal backtick (`) here.
"""
self.assertEquals(Markdown(text), html)
def testInlineCodeLiteralBacktickSpaces(self):
text = """A single backtick in a code span: `` ` ``"""
html = """A single backtick in a code span: `
"""
self.assertEquals(Markdown(text), html)
def testInlineCodeBacktickDelimitedInside(self):
text = """A backtick-delimited string in a code span: `` `foo` ``"""
html = """A backtick-delimited string in a code span: `foo`
"""
self.assertEquals(Markdown(text), html)
def testInlineCodeHTMLEncode(self):
text = """Please don't use any `