From: Holger Schurig Date: Fri, 16 Apr 2010 08:36:43 +0000 (+0200) Subject: read_markdown.py: upgrade to 1.0.1.16 X-Git-Url: https://oss.titaniummirror.com/gitweb?p=webber.git;a=commitdiff_plain;h=2a68c3cda765bb760f472843ff16c47e7df7f9cb read_markdown.py: upgrade to 1.0.1.16 --- diff --git a/plugins/read_markdown.py b/plugins/read_markdown.py index 35b8a46..fead97e 100644 --- a/plugins/read_markdown.py +++ b/plugins/read_markdown.py @@ -5,7 +5,7 @@ from webber import * # Copyright (c) 2007-2008 ActiveState Corp. # License: MIT (http://www.opensource.org/licenses/mit-license.php) # -# I used version 1.0.1.15, but deleted: +# I used version 1.0.1.16, but deleted: # * file-vars (emacs-style settings inside the file) # * Standardize line endings # * call to _do_links() @@ -942,10 +942,10 @@ class Markdown(object): _list_item_re = re.compile(r''' (\n)? # leading line = \1 (^[ \t]*) # leading whitespace = \2 - (%s) [ \t]+ # list marker = \3 + (?P%s) [ \t]+ # list marker = \3 ((?:.+?) # list item text = \4 (\n{1,2})) # eols = \5 - (?= \n* (\Z | \2 (%s) [ \t]+)) + (?= \n* (\Z | \2 (?P%s) [ \t]+)) ''' % (_marker_any, _marker_any), re.M | re.X | re.S) @@ -1191,15 +1191,35 @@ class Markdown(object): text = text.strip('\n') # Wrap

tags. - grafs = re.split(r"\n{2,}", text) - for i, graf in enumerate(grafs): + grafs = [] + for i, graf in enumerate(re.split(r"\n{2,}", text)): if graf in self.html_blocks: # Unhashify HTML blocks - grafs[i] = self.html_blocks[graf] + grafs.append(self.html_blocks[graf]) else: + cuddled_list = None + if "cuddled-lists" in self.extras: + # Need to put back trailing '\n' for `_list_item_re` + # match at the end of the paragraph. + li = self._list_item_re.search(graf + '\n') + # Two of the same list marker in this paragraph: a likely + # candidate for a list cuddled to preceding paragraph + # text (issue 33). Note the `[-1]` is a quick way to + # consider numeric bullets (e.g. "1." and "2.") to be + # equal. + if (li and li.group("next_marker") + and li.group("marker")[-1] == li.group("next_marker")[-1]): + start = li.start() + cuddled_list = self._do_lists(graf[start:]).rstrip("\n") + assert cuddled_list.startswith("

    ") or cuddled_list.startswith("
      ") + graf = graf[:start] + # Wrap

      tags. graf = self._run_span_gamut(graf) - grafs[i] = "

      " + graf.lstrip(" \t") + "

      " + grafs.append("

      " + graf.lstrip(" \t") + "

      ") + + if cuddled_list: + grafs.append(cuddled_list) return "\n\n".join(grafs)