From a316ac49a6934221b24ec58a6a7dc4c3b30ae1e8 Mon Sep 17 00:00:00 2001 From: Artem Yunusov Date: Mon, 14 Jul 2008 16:17:33 +0500 Subject: A lot of bug fixes. Handlig attributes added, new hr processing. Reformatted test suite for ElementTree output. --- markdown.py | 181 +-- tests/markdown-test/amps-and-angle-encoding.html | 30 +- tests/markdown-test/auto-links.html | 30 +- tests/markdown-test/backlash-escapes.html | 67 +- .../blockquotes-with-dode-blocks.html | 21 +- tests/markdown-test/hard-wrapped.html | 15 +- tests/markdown-test/horizontal-rules.html | 72 +- tests/markdown-test/inline-html-advanced.html | 17 +- tests/markdown-test/inline-html-comments.html | 23 +- tests/markdown-test/inline-html-simple.html | 101 +- tests/markdown-test/links-inline.html | 22 +- tests/markdown-test/links-reference.html | 32 +- tests/markdown-test/literal-quotes.html | 9 +- .../markdown-documentation-basics.html | 308 ++--- tests/markdown-test/markdown-syntax.html | 1280 +++++++++++--------- tests/markdown-test/nested-blockquotes.html | 14 +- .../markdown-test/ordered-and-unordered-list.html | 341 ++---- tests/markdown-test/strong-and-em-together.html | 23 +- tests/markdown-test/tabs.html | 46 +- tests/markdown-test/tidyness.html | 22 +- tests/misc/CRLF_line_ends.html | 7 +- tests/misc/adjacent-headers.html | 7 +- tests/misc/amp-in-url.html | 8 +- tests/misc/ampersand.html | 9 +- tests/misc/arabic.html | 44 +- tests/misc/attributes2.html | 16 +- tests/misc/bidi.html | 82 +- tests/misc/blank-block-quote.html | 10 +- tests/misc/blockquote-hr.html | 31 +- tests/misc/blockquote.html | 44 +- tests/misc/bold_links.html | 6 +- tests/misc/br.html | 17 +- tests/misc/bracket_re.html | 119 +- tests/misc/code-first-line.html | 6 +- tests/misc/comments.html | 15 +- tests/misc/div.html | 12 +- tests/misc/email.html | 5 +- tests/misc/funky-list.html | 34 +- tests/misc/h1.html | 8 +- tests/misc/hash.html | 23 +- tests/misc/headers.html | 13 +- tests/misc/hline.html | 7 +- tests/misc/html.html | 14 +- tests/misc/image-2.html | 15 +- tests/misc/image.html | 6 +- tests/misc/image_in_links.html | 7 +- tests/misc/inside_html.html | 6 +- tests/misc/japanese.html | 31 +- tests/misc/lazy-block-quote.html | 13 +- tests/misc/lists.html | 82 +- tests/misc/lists2.html | 13 +- tests/misc/lists3.html | 13 +- tests/misc/lists4.html | 25 +- tests/misc/lists5.html | 31 +- tests/misc/markup-inside-p.html | 26 +- tests/misc/mismatched-tags.html | 8 +- tests/misc/more_comments.html | 8 +- tests/misc/multi-line-tags.html | 12 +- tests/misc/multi-paragraph-block-quote.html | 16 +- tests/misc/multi-test.html | 44 +- tests/misc/multiline-comments.html | 22 +- tests/misc/normalize.html | 8 +- tests/misc/numeric-entity.html | 9 +- tests/misc/php.html | 17 +- tests/misc/pre.html | 13 +- tests/misc/russian.html | 15 +- tests/misc/some-test.html | 126 +- tests/misc/span.html | 15 +- tests/misc/strong-with-underscores.html | 5 +- tests/misc/stronintags.html | 14 +- tests/misc/tabs-in-lists.html | 91 +- tests/misc/two-spaces.html | 43 +- tests/misc/uche.html | 17 +- tests/misc/underscores.html | 23 +- tests/misc/url_spaces.html | 11 +- tests/safe_mode/inline-html-advanced.html | 13 +- tests/safe_mode/inline-html-comments.html | 20 +- tests/safe_mode/inline-html-simple.html | 97 +- tests/safe_mode/script_tags.html | 34 +- tests/safe_mode/unsafe_urls.html | 45 +- 80 files changed, 1871 insertions(+), 2314 deletions(-) diff --git a/markdown.py b/markdown.py index f3f2481..032e084 100644 --- a/markdown.py +++ b/markdown.py @@ -62,31 +62,25 @@ def message(level, text): def isstr(s): return isinstance(s, unicode) or isinstance(s, str) -'''try: - # running with lxml.etree - from lxml import etree +try: + # Python 2.5+ + import xml.etree.cElementTree as etree except ImportError: try: # Python 2.5+ - import xml.etree.cElementTree as etree + import xml.etree.ElementTree as etree except ImportError: try: - # Python 2.5+ - import xml.etree.ElementTree as etree + # normal cElementTree install + import cElementTree as etree except ImportError: try: - # normal cElementTree install - import cElementTree as etree + # normal ElementTree install + import elementtree.ElementTree as etree except ImportError: - try: - # normal ElementTree install - import elementtree.ElementTree as etree - except ImportError: - message(CRITICAL, - "Failed to import ElementTree from any known place") - sys.exit(1)''' - -import xml.etree.cElementTree as etree + message(CRITICAL, + "Failed to import ElementTree from any known place") + sys.exit(1) def indentETree(elem, level=0): @@ -110,7 +104,7 @@ def indentETree(elem, level=0): TAB_LENGTH = 4 # expand tabs to this many spaces ENABLE_ATTRIBUTES = True # @id = xyz -> <... id="xyz"> -SMART_EMPHASIS = 1 # this_or_that does not become thisorthat +SMART_EMPHASIS = True # this_or_that does not become thisorthat HTML_REMOVED_TEXT = "[HTML_REMOVED]" # text used instead of HTML in safe mode RTL_BIDI_RANGES = ( (u'\u0590', u'\u07FF'), @@ -184,6 +178,13 @@ def codepoint2name(code): else: return "%s#%d;" % (AND_SUBSTITUTE, code) +def handleAttributes(text, parent): + + def attributeCallback(match): + parent.set(match.group(1), match.group(2)) + + return RE.regExp['attr'].sub(attributeCallback, text) + """ ====================================================================== @@ -395,24 +396,27 @@ class LinePreprocessor(Preprocessor): for i in range(len(lines)): prefix = '' m = self.blockquote_re.search(lines[i]) - if m : prefix = m.group(0) + if m: + prefix = m.group(0) if self._isLine(lines[i][len(prefix):]): - lines[i] = prefix + self.stash.store("
", safe=True) + #lines[i] = prefix + self.stash.store("
", safe=True) + lines[i] = prefix + "___" return lines def _isLine(self, block): """Determine if a block should be replaced with an
""" - if block.startswith(" "): return 0 # a code block + if block.startswith(" "): + return False # a code block text = "".join([x for x in block if not x.isspace()]) if len(text) <= 2: - return 0 + return False for pattern in ['isline1', 'isline2', 'isline3']: m = RE.regExp[pattern].match(text) if (m and m.group(1)): - return 1 + return True else: - return 0 + return False LINE_PREPROCESSOR = LinePreprocessor() @@ -510,7 +514,7 @@ STRONG_EM_RE = r'\*\*\*(.*?|[^***]+?)\*\*\*' # ***strong*** if SMART_EMPHASIS: - EMPHASIS_2_RE = r'(? 1: # we also got a title - title = '"' + '"'.join(parts[1:]).strip() + title = ('"' + '"'.join(parts[1:]).strip())[1:-1] #title = dequote(title) #.replace('"', """) el.set("title", title) return el @@ -690,6 +693,7 @@ class LinkPattern (Pattern): class ImagePattern(LinkPattern): """ Return a NanoDom img Element from the given match. """ + def handleMatch(self, m): el = etree.Element("img") src_parts = m.group(9).split() @@ -699,27 +703,12 @@ class ImagePattern(LinkPattern): el.set('src', "") if len(src_parts) > 1: el.set('title', dequote(" ".join(src_parts[1:]))) - - # Need to be reimplemented - '''if ENABLE_ATTRIBUTES: - el.text = m.group(2) - truealt = text.value - el.childNodes.remove(text) - - self.attrRegExp.sub(self.attributeCallback, self.value) - - - text = doc.createTextNode(m.group(2)) - el.appendChild(text) - text.handleAttributes() - truealt = text.value - el.childNodes.remove(text) - - + + if ENABLE_ATTRIBUTES: + truealt = handleAttributes(m.group(2), el) else: - truealt = m.group(2)''' + truealt = m.group(2) - truealt = m.group(2) el.set('alt', truealt) return el @@ -737,6 +726,7 @@ class ReferencePattern(LinkPattern): if not self.references.has_key(id): # ignore undefined refs return None href, title = self.references[id] + text = m.group(2) return self.makeTag(href, title, text) @@ -746,6 +736,7 @@ class ReferencePattern(LinkPattern): el.set('href', self.sanatize_url(href)) if title: el.set('title', title) + el.text = text return el @@ -1130,6 +1121,7 @@ class CorePatterns: re.DOTALL) self.regExp['containsline'] = re.compile(r'^([-]*)$|^([=]*)$', re.M) + self.regExp['attr'] = re.compile("\{@([^\}]*)=([^\}]*)}") # {@id=123} RE = CorePatterns() @@ -1389,7 +1381,13 @@ class Markdown: if len(paragraph) and paragraph[0].startswith('#'): self._processHeader(parent_elem, paragraph) + + elif len(paragraph) and \ + RE.regExp["isline3"].match(paragraph[0]): + self._processHR(parent_elem) + lines = paragraph[1:] + lines + elif paragraph: self._processParagraph(parent_elem, paragraph, inList, looseList) @@ -1397,7 +1395,9 @@ class Markdown: if lines and not lines[0].strip(): lines = lines[1:] # skip the first (blank) line - + def _processHR(self, parent_elem): + hr = etree.SubElement(parent_elem, "hr") + def _processHeader(self, parent_elem, paragraph): m = RE.regExp['header'].match(paragraph[0]) if m: @@ -1410,10 +1410,6 @@ class Markdown: def _processParagraph(self, parent_elem, paragraph, inList, looseList): - #list = self._handleInline("\n".join(paragraph)) - - - if ( parent_elem.tag == 'li' and not (looseList or parent_elem.getchildren())): @@ -1426,13 +1422,21 @@ class Markdown: # Otherwise make a "p" element el = etree.SubElement(parent_elem, "p") - #el.appendChild(self.doc.createTextNode("\n".join(paragraph), "inline")) - inline = etree.SubElement(el, "inline") - inline.text = "\n".join(paragraph) + dump = [] - #for item in list: - #el.appendChild(item) - + # Searching for hr + for line in paragraph: + if RE.regExp["isline3"].match(line): + inline = etree.SubElement(el, "inline") + inline.text = "\n".join(dump) + etree.SubElement(el, "hr") + dump.clear() + else: + dump.append(line) + if dump: + text = "\n".join(dump) + inline = etree.SubElement(el, "inline") + inline.text = text def _processUList(self, parent_elem, lines, inList): self._processList(parent_elem, lines, inList, @@ -1673,15 +1677,22 @@ class Markdown: """ def linkText(text): - if result: - result[-1].tail = text - else: - parent.text = text + if text: + if result: + if result[-1].tail: + result[-1].tail += text + else: + result[-1].tail = text + else: + if parent.text: + parent.text += text + else: + parent.text = text result = [] prefix = self.inlineStash.prefix strartIndex = 0 - + while data: index = data.find(prefix, strartIndex) @@ -1693,13 +1704,12 @@ class Markdown: node = self.inlineStash.get(id) + if index > 0: + text = data[strartIndex:index] + linkText(text) if not isstr(node): # it's Element - - if index > 0: - text = data[strartIndex:index] - linkText(text) - + for child in [node] + node.getchildren(): if child.tail: @@ -1724,8 +1734,7 @@ class Markdown: else: text = data[strartIndex:].strip() - if text: - linkText(text) + linkText(text) data = "" return result @@ -1737,7 +1746,7 @@ class Markdown: Given a pattern name, this function checks if the line fits the pattern, creates the necessary elements, adds it to InlineStash, and returns string with placeholders, - instead of DOM elements. + instead of ElementTree elements. Keyword arguments: @@ -1772,19 +1781,18 @@ class Markdown: pholder = self.inlineStash.add(node, pattern.type()) return "%s%s%s" % (match.group(1), pholder, match.groups()[-1]), True - def _processTree(self, el): """ - Processing NanoDOM markdown tree, and applying inline patterns + Processing ElementTree, and applying inline patterns Keyword arguments: * el - parent element of Document. - Returns: NanoDOM Document object with applied inline patterns. + Returns: ElementTree object with applied inline patterns. """ - + stack = [el] while stack: currElement = stack.pop() @@ -1792,34 +1800,45 @@ class Markdown: for child in currElement.getchildren(): if child.tag == "inline": - + lst = self._processPlaceholders(self._handleInline( child.text), currElement) - + pos = currElement.getchildren().index(child) insertQueue.append((child, pos, lst)) else: stack.append(child) + for element, pos, lst in insertQueue: currElement.remove(element) + if currElement.text: + currElement.text = handleAttributes(currElement.text, + currElement) for newChild in lst: + # Processing attributes + if newChild.tail: + newChild.tail = handleAttributes(newChild.tail, + currElement) + if newChild.text: + newChild.text = handleAttributes(newChild.text, + newChild) currElement.insert(pos, newChild) pos += 1 def applyInlinePatterns(self, markdownTree): """ - Retrun NanoDOM markdown tree, with applied + Retrun ElementTree, with applied inline paterns Keyword arguments: - * markdownTree: NanoDOM Document object, reppresenting Markdown tree. + * markdownTree: ElementTree object, reppresenting Markdown tree. - Returns: NanoDOM Document object. + Returns: ElementTree object. """ @@ -1833,14 +1852,14 @@ class Markdown: def markdownToTree(self, source=None): """ - Retrun NanoDOM markdown tree, without applying + Retrun ElementTree, without applying inline paterns Keyword arguments: * source: An ascii or unicode string of Markdown formated text. - Returns: NanoDOM Document object. + Returns: ElementTree object. """ if source is not None: #Allow blank string self.source = source diff --git a/tests/markdown-test/amps-and-angle-encoding.html b/tests/markdown-test/amps-and-angle-encoding.html index 18df2c3..9c565e5 100644 --- a/tests/markdown-test/amps-and-angle-encoding.html +++ b/tests/markdown-test/amps-and-angle-encoding.html @@ -1,21 +1,9 @@ - -

AT&T has an ampersand in their name. -

-

AT&T is another way to write it. -

-

This & that. -

-

4 < 5. -

-

6 > 5. -

-

Here's a link with an ampersand in the URL. -

-

Here's a link with an amersand in the link text: AT&T. -

-

Here's an inline link. -

-

Here's an inline link. -

- - +

AT&T has an ampersand in their name.

+

AT&T is another way to write it.

+

This & that.

+

4 < 5.

+

6 > 5.

+

Here's a linkwith an ampersand in the URL.

+

Here's a link with an amersand in the link text: AT&T.

+

Here's an inline link.

+

Here's an inline link.

\ No newline at end of file diff --git a/tests/markdown-test/auto-links.html b/tests/markdown-test/auto-links.html index 976d22b..100db34 100644 --- a/tests/markdown-test/auto-links.html +++ b/tests/markdown-test/auto-links.html @@ -1,5 +1,4 @@ -

Link: http://example.com/. -

+

Link: http://example.com/.

Https link: https://example.com

Ftp link: ftp://example.com @@ -7,20 +6,19 @@

With an ampersand: http://example.com/?foo=1&bar=2

-

Blockquoted: http://example.com/ +

+

Blockquoted: http://example.com/

-

Auto-links should not occur here: <http://example.com/> +

+

Auto-links should not occur here: <http://example.com/>

-
or here: <http://example.com/>
-
+
+or here: <http://example.com/>
+
+
\ No newline at end of file diff --git a/tests/markdown-test/backlash-escapes.html b/tests/markdown-test/backlash-escapes.html index 77ecde7..f99082a 100644 --- a/tests/markdown-test/backlash-escapes.html +++ b/tests/markdown-test/backlash-escapes.html @@ -1,41 +1,23 @@ - -

These should all get escaped: -

-

Backslash: \ -

-

Backtick: ` -

-

Asterisk: * -

-

Underscore: _ -

-

Left brace: { -

-

Right brace: } -

-

Left bracket: [ -

-

Right bracket: ] -

-

Left paren: ( -

-

Right paren: ) -

-

Greater-than: > -

-

Hash: # -

-

Period: . -

-

Bang: ! -

-

Plus: + -

-

Minus: - -

-

These should not, because they occur within a code block: -

-
Backslash: \\
+

These should all get escaped:

+

Backslash: \

+

Backtick: `

+

Asterisk: *

+

Underscore: _

+

Left brace: {

+

Right brace: }

+

Left bracket: [

+

Right bracket: ]

+

Left paren: (

+

Right paren: )

+

Greater-than: >

+

Hash: #

+

Period: .

+

Bang: !

+

Plus: +

+

Minus: -

+

These should not, because they occur within a code block:

+
+Backslash: \\
 
 Backtick: \`
 
@@ -66,8 +48,9 @@ Bang: \!
 Plus: \+
 
 Minus: \-
-

Nor should these, which occur in code spans: -

+
+
+

Nor should these, which occur in code spans:

Backslash: \\

Backtick: \` @@ -99,6 +82,4 @@ Minus: \-

Plus: \+

Minus: \- -

- - +

\ No newline at end of file diff --git a/tests/markdown-test/blockquotes-with-dode-blocks.html b/tests/markdown-test/blockquotes-with-dode-blocks.html index 275749f..e7c79d9 100644 --- a/tests/markdown-test/blockquotes-with-dode-blocks.html +++ b/tests/markdown-test/blockquotes-with-dode-blocks.html @@ -1,13 +1,16 @@ - -

Example: -

-
sub status {
+
+

Example:

+
+sub status {
     print "working";
 }
-

Or: -

-
sub status {
+
+
+

Or:

+
+sub status {
     return "working";
 }
-
- +
+
+
\ No newline at end of file diff --git a/tests/markdown-test/hard-wrapped.html b/tests/markdown-test/hard-wrapped.html index 7d16a85..e28e900 100644 --- a/tests/markdown-test/hard-wrapped.html +++ b/tests/markdown-test/hard-wrapped.html @@ -1,12 +1,7 @@ -

In Markdown 1.0.0 and earlier. Version - 8. This line turns into a list item. - Because a hard-wrapped line in the - middle of a paragraph looked like a - list item. -

+8. This line turns into a list item. +Because a hard-wrapped line in the +middle of a paragraph looked like a +list item.

Here's one with a bullet. - * criminey. -

- - +* criminey.

\ No newline at end of file diff --git a/tests/markdown-test/horizontal-rules.html b/tests/markdown-test/horizontal-rules.html index 253e36a..98c9c90 100644 --- a/tests/markdown-test/horizontal-rules.html +++ b/tests/markdown-test/horizontal-rules.html @@ -1,63 +1,51 @@ - -

Dashes: -

+

Dashes:


-
-
-
- -
---
-

- +
+---
+
+

-
-
- -
- - -
-

Asterisks: -


- +
+- - -
+
+
+

Asterisks:


-
-
- -
***
-

-
- +
+***
+
+

-
- -
* * *
-

Underscores: -


-
- +
+* * *
+
+
+

Underscores:


-
- -
___
-

-
-
- +
+___
+
+

- -
_ _ _
-
- +
+
+
+
+_ _ _
+
+
diff --git a/tests/markdown-test/inline-html-advanced.html b/tests/markdown-test/inline-html-advanced.html index c72bebb..0f922e9 100644 --- a/tests/markdown-test/inline-html-advanced.html +++ b/tests/markdown-test/inline-html-advanced.html @@ -1,18 +1,11 @@ - -

Simple block on one line: -

-
foo
- -

And nested without indentation: -

-
+

Simple block on one line:

+

foo

+

And nested without indentation:

+

foo
bar
-
- - - +

\ No newline at end of file diff --git a/tests/markdown-test/inline-html-comments.html b/tests/markdown-test/inline-html-comments.html index a85c8b2..8b538d6 100644 --- a/tests/markdown-test/inline-html-comments.html +++ b/tests/markdown-test/inline-html-comments.html @@ -1,17 +1,8 @@ - -

Paragraph one. -

- - -

+

- -

Paragraph two. -

- - -

The end. -

- - +-->

+

Paragraph two.

+

+

The end.

\ No newline at end of file diff --git a/tests/markdown-test/inline-html-simple.html b/tests/markdown-test/inline-html-simple.html index b5b3f12..efb50dc 100644 --- a/tests/markdown-test/inline-html-simple.html +++ b/tests/markdown-test/inline-html-simple.html @@ -1,68 +1,53 @@ - -

Here's a simple block: -

-
+

Here's a simple block:

+

foo -
- -

This should be a code block, though: -

-
<div>
+

+

This should be a code block, though:

+
+<div>
     foo
 </div>
-

As should this: -

-
<div>foo</div>
-

Now, nested: -

-
+ + +

As should this:

+
+<div>foo</div>
+
+
+

Now, nested:

+

foo
-
- -

This should just be an HTML comment: -

- - -

Multiline: -

-

+

Multiline:

+

- -

Code block: -

-
<!-- Comment -->
-

Just plain comment, with trailing spaces on the line: -

- - -

Code: -

-
<hr />
-

Hr's: -

-
- -
- -
- -
- -
- -
- -
- -
- -
- - - +-->

+

Code block:

+
+<!-- Comment -->
+
+
+

Just plain comment, with trailing spaces on the line:

+

+

Code:

+
+<hr />
+
+
+

Hr's:

+


+


+


+


+


+


+


+


+


\ No newline at end of file diff --git a/tests/markdown-test/links-inline.html b/tests/markdown-test/links-inline.html index 5fb7073..e1aaf27 100644 --- a/tests/markdown-test/links-inline.html +++ b/tests/markdown-test/links-inline.html @@ -1,13 +1,9 @@ - -

Just a URL. -

-

URL and title. -

-

URL and title. -

-

URL and title. -

-

Empty. -

- - +

Just a URL.

+

+URL and title.

+

+URL and title.

+

+URL and title.

+

+Empty.

\ No newline at end of file diff --git a/tests/markdown-test/links-reference.html b/tests/markdown-test/links-reference.html index ad6438f..338aa22 100644 --- a/tests/markdown-test/links-reference.html +++ b/tests/markdown-test/links-reference.html @@ -1,20 +1,12 @@ - -

Foo bar. -

-

Foo bar. -

-

Foo bar. -

-

With embedded [brackets]. -

-

Indented once. -

-

Indented twice. -

-

Indented thrice. -

-

Indented [four][] times. -

-
[four]: /url
-
- +

Foo bar.

+

Foo bar.

+

Foo bar.

+

With embedded [brackets].

+

Indented once.

+

Indented twice.

+

Indented thrice.

+

Indented [four][] times.

+
+[four]: /url
+
+
\ No newline at end of file diff --git a/tests/markdown-test/literal-quotes.html b/tests/markdown-test/literal-quotes.html index 806b7f2..0342589 100644 --- a/tests/markdown-test/literal-quotes.html +++ b/tests/markdown-test/literal-quotes.html @@ -1,7 +1,2 @@ - -

Foo bar. -

-

Foo bar. -

- - +

Foo bar.

+

Foo bar.

\ No newline at end of file diff --git a/tests/markdown-test/markdown-documentation-basics.html b/tests/markdown-test/markdown-documentation-basics.html index 744e89d..9c5259f 100644 --- a/tests/markdown-test/markdown-documentation-basics.html +++ b/tests/markdown-test/markdown-documentation-basics.html @@ -1,47 +1,39 @@

Markdown: Basics

-

Getting the Gist of Markdown's Formatting Syntax

This page offers a brief overview of what it's like to use Markdown. - The syntax page provides complete, detailed documentation for - every feature, but Markdown should be very easy to pick up simply by - looking at a few examples of it in action. The examples on this page - are written in a before/after style, showing example syntax and the - HTML output produced by Markdown. -

-

It's also helpful to simply try Markdown out; the Dingus is a - web application that allows you type your own Markdown-formatted text - and translate it to XHTML. -

-

Note: This document is itself written using Markdown; you - can see the source for it by adding '.text' to the URL. -

- +The syntax pageprovides complete, detailed documentation for +every feature, but Markdown should be very easy to pick up simply by +looking at a few examples of it in action. The examples on this page +are written in a before/after style, showing example syntax and the +HTML output produced by Markdown.

+

It's also helpful to simply try Markdown out; the Dingusis a +web application that allows you type your own Markdown-formatted text +and translate it to XHTML.

+

+Note: This document is itself written using Markdown; you +can see the source for it by adding '.text' to the URL.

Paragraphs, Headers, Blockquotes

A paragraph is simply one or more consecutive lines of text, separated - by one or more blank lines. (A blank line is any line that looks like a - blank line -- a line containing nothing spaces or tabs is considered - blank.) Normal paragraphs should not be intended with spaces or tabs. -

+by one or more blank lines. (A blank line is any line that looks like a +blank line -- a line containing nothing spaces or tabs is considered +blank.) Normal paragraphs should not be intended with spaces or tabs.

Markdown offers two styles of headers: Setext and atx. - Setext-style headers for <h1> and <h2> are created by - "underlining" with equal signs (=) and hyphens (-), respectively. - To create an atx-style header, you put 1-6 hash marks (#) at the - beginning of the line -- the number of hashes equals the resulting - HTML header level. -

-

Blockquotes are indicated using email-style '>' angle brackets. -

-

Markdown: -

-
A First Level Header
+Setext-style headers for <h1> and <h2> are created by
+"underlining" with equal signs (=) and hyphens (-), respectively.
+To create an atx-style header, you put 1-6 hash marks (#) at the
+beginning of the line -- the number of hashes equals the resulting
+HTML header level.

+

Blockquotes are indicated using email-style '>' angle brackets.

+

Markdown:

+
+A First Level Header
 ====================
 
 A Second Level Header
@@ -61,9 +53,11 @@ dog's back.
 > This is the second paragraph in the blockquote.
 >
 > ## This is an H2 in a blockquote
-

Output: -

-
<h1>A First Level Header</h1>
+
+
+

Output:

+
+<h1>A First Level Header</h1>
 
 <h2>A Second Level Header</h2>
 
@@ -83,179 +77,221 @@ dog's back.</p>
 
     <h2>This is an H2 in a blockquote</h2>
 </blockquote>
-
+
+

Phrase Emphasis

-

Markdown uses asterisks and underscores to indicate spans of emphasis. -

-

Markdown: -

-
Some of these words *are emphasized*.
+

Markdown uses asterisks and underscores to indicate spans of emphasis.

+

Markdown:

+
+Some of these words *are emphasized*.
 Some of these words _are emphasized also_.
 
 Use two asterisks for **strong emphasis**.
 Or, if you prefer, __use two underscores instead__.
-

Output: -

-
<p>Some of these words <em>are emphasized</em>.
+
+
+

Output:

+
+<p>Some of these words <em>are emphasized</em>.
 Some of these words <em>are emphasized also</em>.</p>
 
 <p>Use two asterisks for <strong>strong emphasis</strong>.
 Or, if you prefer, <strong>use two underscores instead</strong>.</p>
-
+
+

Lists

Unordered (bulleted) lists use asterisks, pluses, and hyphens (*, - +, and -) as list markers. These three markers are - interchangable; this: -

-
*   Candy.
++, and -) as list markers. These three markers are
+interchangable; this:

+
+*   Candy.
 *   Gum.
 *   Booze.
-

this: -

-
+   Candy.
+
+
+

this:

+
++   Candy.
 +   Gum.
 +   Booze.
-

and this: -

-
-   Candy.
+
+
+

and this:

+
+-   Candy.
 -   Gum.
 -   Booze.
-

all produce the same output: -

-
<ul>
+
+
+

all produce the same output:

+
+<ul>
 <li>Candy.</li>
 <li>Gum.</li>
 <li>Booze.</li>
 </ul>
-

Ordered (numbered) lists use regular numbers, followed by periods, as - list markers: -

-
1.  Red
+
+
+

Ordered (numbered) lists use regular numbers, followed by periods, as +list markers:

+
+1.  Red
 2.  Green
 3.  Blue
-

Output: -

-
<ol>
+
+
+

Output:

+
+<ol>
 <li>Red</li>
 <li>Green</li>
 <li>Blue</li>
 </ol>
-

If you put blank lines between items, you'll get <p> tags for the - list item text. You can create multi-paragraph list items by indenting - the paragraphs by 4 spaces or 1 tab: -

-
*   A list item.
+
+
+

If you put blank lines between items, you'll get <p>tags for the +list item text. You can create multi-paragraph list items by indenting +the paragraphs by 4 spaces or 1 tab:

+
+*   A list item.
 
     With multiple paragraphs.
 
 *   Another item in the list.
-

Output: -

-
<ul>
+
+
+

Output:

+
+<ul>
 <li><p>A list item.</p>
 <p>With multiple paragraphs.</p></li>
 <li><p>Another item in the list.</p></li>
 </ul>
-
+
+

Links

Markdown supports two styles for creating links: inline and - reference. With both styles, you use square brackets to delimit the - text you want to turn into a link. -

+reference. With both styles, you use square brackets to delimit the +text you want to turn into a link.

Inline-style links use parentheses immediately after the link text. - For example: -

-
This is an [example link](http://example.com/).
-

Output: -

-
<p>This is an <a href="http://example.com/">
+For example:

+
+This is an [example link](http://example.com/).
+
+
+

Output:

+
+<p>This is an <a href="http://example.com/">
 example link</a>.</p>
-

Optionally, you may include a title attribute in the parentheses: -

-
This is an [example link](http://example.com/ "With a Title").
-

Output: -

-
<p>This is an <a href="http://example.com/" title="With a Title">
+
+
+

Optionally, you may include a title attribute in the parentheses:

+
+This is an [example link](http://example.com/ "With a Title").
+
+
+

Output:

+
+<p>This is an <a href="http://example.com/" title="With a Title">
 example link</a>.</p>
-

Reference-style links allow you to refer to your links by names, which - you define elsewhere in your document: -

-
I get 10 times more traffic from [Google][1] than from
+
+
+

Reference-style links allow you to refer to your links by names, which +you define elsewhere in your document:

+
+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"
-

Output: -

-
<p>I get 10 times more traffic from <a href="http://google.com/"
+
+
+

Output:

+
+<p>I get 10 times more traffic from <a href="http://google.com/"
 title="Google">Google</a> than from <a href="http://search.yahoo.com/"
 title="Yahoo Search">Yahoo</a> or <a href="http://search.msn.com/"
 title="MSN Search">MSN</a>.</p>
-

The title attribute is optional. Link names may contain letters, - numbers and spaces, but are not case sensitive: -

-
I start my morning with a cup of coffee and
+
+
+

The title attribute is optional. Link names may contain letters, +numbers and spaces, but are notcase sensitive:

+
+I start my morning with a cup of coffee and
 [The New York Times][NY Times].
 
 [ny times]: http://www.nytimes.com/
-

Output: -

-
<p>I start my morning with a cup of coffee and
+
+
+

Output:

+
+<p>I start my morning with a cup of coffee and
 <a href="http://www.nytimes.com/">The New York Times</a>.</p>
-
+
+

Images

-

Image syntax is very much like link syntax. -

-

Inline (titles are optional): -

-
![alt text](/path/to/img.jpg "Title")
-

Reference-style: -

-
![alt text][id]
+

Image syntax is very much like link syntax.

+

Inline (titles are optional):

+
+![alt text](/path/to/img.jpg "Title")
+
+
+

Reference-style:

+
+![alt text][id]
 
 [id]: /path/to/img.jpg "Title"
-

Both of the above examples produce the same output: -

-
<img src="/path/to/img.jpg" alt="alt text" title="Title" />
-
+
+
+

Both of the above examples produce the same output:

+
+<img src="/path/to/img.jpg" alt="alt text" title="Title" />
+
+

Code

In a regular paragraph, you can create code span by wrapping text in - backtick quotes. Any ampersands (&) and angle brackets (< or - >) will automatically be translated into HTML entities. This makes - it easy to use Markdown to write about HTML example code: -

-
I strongly recommend against using any `<blink>` tags.
+backtick quotes. Any ampersands (&) and angle brackets (< or
+>) will automatically be translated into HTML entities. This makes
+it easy to use Markdown to write about HTML example code:

+
+I strongly recommend against using any `<blink>` tags.
 
 I wish SmartyPants used named entities like `&mdash;`
 instead of decimal-encoded entites like `&#8212;`.
-

Output: -

-
<p>I strongly recommend against using any
+
+
+

Output:

+
+<p>I strongly recommend against using any
 <code>&lt;blink&gt;</code> tags.</p>
 
 <p>I wish SmartyPants used named entities like
 <code>&amp;mdash;</code> instead of decimal-encoded
 entites like <code>&amp;#8212;</code>.</p>
-

To specify an entire block of pre-formatted code, indent every line of - the block by 4 spaces or 1 tab. Just like with code spans, &, <, - and > characters will be escaped automatically. -

-

Markdown: -

-
If you want your page to validate under XHTML 1.0 Strict,
+
+
+

To specify an entire block of pre-formatted code, indent every line of +the block by 4 spaces or 1 tab. Just like with code spans, &, <, +and >characters will be escaped automatically.

+

Markdown:

+
+If you want your page to validate under XHTML 1.0 Strict,
 you've got to put paragraph tags in your blockquotes:
 
     <blockquote>
         <p>For example.</p>
     </blockquote>
-

Output: -

-
<p>If you want your page to validate under XHTML 1.0 Strict,
+
+
+

Output:

+
+<p>If you want your page to validate under XHTML 1.0 Strict,
 you've got to put paragraph tags in your blockquotes:</p>
 
 <pre><code>&lt;blockquote&gt;
     &lt;p&gt;For example.&lt;/p&gt;
 &lt;/blockquote&gt;
 </code></pre>
-
\ No newline at end of file +
+
diff --git a/tests/markdown-test/markdown-syntax.html b/tests/markdown-test/markdown-syntax.html index 40f9547..84fe3bd 100644 --- a/tests/markdown-test/markdown-syntax.html +++ b/tests/markdown-test/markdown-syntax.html @@ -1,128 +1,120 @@

Markdown: Syntax

-