Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove extra newline from before list <pre> blocks

My crowded-pre fix broke <pre> blocks in lists:

  $ diff -u preformatted_in_list.md preformatted_in_list-module_output.md
  --- preformatted_in_list.md
  +++ preformatted_in_list-module_output.md
  @@ -1,5 +1,6 @@
     * Run this command:

  +
           ls -l *.html

     * ?

There is a fair amount of trailing whitespace in html2text output, and
I'm not sure where it all comes from.  This patch removes the extra
newline (fixing the test), but it also tweaks the amount of trailing
whitespace in the expected blank line (probably not a problem).
  • Loading branch information...
commit eb09b6df46f6f409d18d8eae46feed0c6182af19 1 parent cc02194
@wking wking authored
Showing with 9 additions and 3 deletions.
  1. +8 −2 html2text.py
  2. +1 −1  test/preformatted_in_list.md
View
10 html2text.py
@@ -593,7 +593,6 @@ def o(self, data, puredata=0, force=0):
if self.startpre:
#self.out(" :") #TODO: not output when already one there
- self.startpre = 0
if not data.startswith("\n"): # <pre>stuff...
data = "\n" + data
@@ -601,11 +600,18 @@ def o(self, data, puredata=0, force=0):
if not (force and data and data[0] == ">") and self.blockquote: bq += " "
if self.pre:
- bq += " "
+ if not self.list:
+ bq += " "
+ #else: list content is already partially indented
for i in xrange(len(self.list)):
bq += " "
data = data.replace("\n", "\n"+bq)
+ if self.startpre:
+ self.startpre = 0
+ if self.list:
+ data = data.lstrip("\n") # use existing initial indentation
+
if self.start:
self.space = 0
self.p_p = 0
View
2  test/preformatted_in_list.md
@@ -1,5 +1,5 @@
* Run this command:
-
+
ls -l *.html
* ?
Please sign in to comment.
Something went wrong with that request. Please try again.