diff options
author | Guido van Rossum <guido@python.org> | 1996-08-26 16:19:23 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1996-08-26 16:19:23 (GMT) |
commit | 8e44991b34d44038c50dcd6dc0ef806a82c1daa4 (patch) | |
tree | 8c9afdf7da558270e69d3adf1d8c5c58a0a5619f | |
parent | f8abb38737e0490ef3fe59bc908285fa85bb9470 (diff) | |
download | cpython-8e44991b34d44038c50dcd6dc0ef806a82c1daa4.zip cpython-8e44991b34d44038c50dcd6dc0ef806a82c1daa4.tar.gz cpython-8e44991b34d44038c50dcd6dc0ef806a82c1daa4.tar.bz2 |
Three sets of changes from Grail:
date: 1996/08/14 17:27:21; author: fdrake; state: Exp; lines: +11 -9
(formatter.py): Establish a consistent space-handling policy, so that all
spaces are handled by the outermost context in which they might be
considered. (I.e., softspaces at element boundaries migrate
outwards.)
For instance: "<A> <IMG> </A>" becomes " <A><IMG></A> ".
This avoids some of those nasty underlined spaces around images. It
does not affect spaces *between* images within an anchor.
date: 1996/08/01 17:02:09; author: fdrake; state: Exp; lines: +3 -2
(formatter.py): Added required parameter to the NullFormatter class; this
was omitted by accident.
Made AbstractFormatter.add_literal_data() handle preceeding softspace
correctly instead of expecting the caller to do it.
date: 1996/07/23 22:18:56; author: fdrake; state: Exp; lines: +1 -1
(formatter.py): Correct assert_line_data() to update all internal conditions;
This now handles headers with only image content immediately followed
by anything.
-rw-r--r-- | Lib/formatter.py | 27 |
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: |