summaryrefslogtreecommitdiffstats
path: root/Lib/formatter.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/formatter.py')
-rw-r--r--Lib/formatter.py27
1 files changed, 15 insertions, 12 deletions
diff --git a/Lib/formatter.py b/Lib/formatter.py
index 0266379..c192e20 100644
--- a/Lib/formatter.py
+++ b/Lib/formatter.py
@@ -10,7 +10,7 @@ AS_IS = None
class NullFormatter:
- def __init__(self): pass
+ def __init__(self, writer): pass
def end_paragraph(self, blankline): pass
def add_line_break(self): pass
def add_hor_rule(self, abswidth=None, percentwidth=1.0,
@@ -33,6 +33,11 @@ class NullFormatter:
class AbstractFormatter:
+ # Space handling policy: blank spaces at the boundary between elements
+ # are handled by the outermost context. "Literal" data is not checked
+ # to determine context, so spaces in literal data are handled directly
+ # in all circumstances.
+
def __init__(self, writer):
self.writer = writer # Output device
self.align = None # Current alignment
@@ -162,7 +167,8 @@ class AbstractFormatter:
def add_literal_data(self, data):
if not data: return
- # Caller is expected to cause flush_softspace() if needed.
+ if self.softspace:
+ self.writer.send_flowing_data(" ")
self.hard_break = data[-1:] == '\n'
self.nospace = self.para_end = self.softspace = \
self.parskip = self.have_label = 0
@@ -170,8 +176,9 @@ class AbstractFormatter:
def flush_softspace(self):
if self.softspace:
- self.hard_break = self.nospace = self.para_end = self.parskip = \
+ self.hard_break = self.para_end = self.parskip = \
self.have_label = self.softspace = 0
+ self.nospace = 1
self.writer.send_flowing_data(' ')
def push_alignment(self, align):
@@ -194,7 +201,8 @@ class AbstractFormatter:
def push_font(self, (size, i, b, tt)):
if self.softspace:
- self.hard_break = self.nospace = self.para_end = self.softspace = 0
+ self.hard_break = self.para_end = self.softspace = 0
+ self.nospace = 1
self.writer.send_flowing_data(' ')
if self.font_stack:
csize, ci, cb, ctt = self.font_stack[-1]
@@ -207,9 +215,6 @@ class AbstractFormatter:
self.writer.new_font(font)
def pop_font(self):
- if self.softspace:
- self.hard_break = self.nospace = self.para_end = self.softspace = 0
- self.writer.send_flowing_data(' ')
if self.font_stack:
del self.font_stack[-1]
if self.font_stack:
@@ -241,22 +246,20 @@ class AbstractFormatter:
def push_style(self, *styles):
if self.softspace:
- self.hard_break = self.nospace = self.para_end = self.softspace = 0
+ self.hard_break = self.para_end = self.softspace = 0
+ self.nospace = 1
self.writer.send_flowing_data(' ')
for style in styles:
self.style_stack.append(style)
self.writer.new_styles(tuple(self.style_stack))
def pop_style(self, n=1):
- if self.softspace:
- self.hard_break = self.nospace = self.para_end = self.softspace = 0
- self.writer.send_flowing_data(' ')
del self.style_stack[-n:]
self.writer.new_styles(tuple(self.style_stack))
def assert_line_data(self, flag=1):
self.nospace = self.hard_break = not flag
- self.para_end = self.have_label = 0
+ self.para_end = self.parskip = self.have_label = 0
class NullWriter: