Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8e44991

Browse files
committed
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.
1 parent f8abb38 commit 8e44991

1 file changed

Lines changed: 15 additions & 12 deletions

File tree

Lib/formatter.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
class NullFormatter:
1212

13-
def __init__(self): pass
13+
def __init__(self, writer): pass
1414
def end_paragraph(self, blankline): pass
1515
def add_line_break(self): pass
1616
def add_hor_rule(self, abswidth=None, percentwidth=1.0,
@@ -33,6 +33,11 @@ def assert_line_data(self, flag=1): pass
3333

3434
class AbstractFormatter:
3535

36+
# Space handling policy: blank spaces at the boundary between elements
37+
# are handled by the outermost context. "Literal" data is not checked
38+
# to determine context, so spaces in literal data are handled directly
39+
# in all circumstances.
40+
3641
def __init__(self, writer):
3742
self.writer = writer # Output device
3843
self.align = None # Current alignment
@@ -162,16 +167,18 @@ def add_flowing_data(self, data,
162167

163168
def add_literal_data(self, data):
164169
if not data: return
165-
# Caller is expected to cause flush_softspace() if needed.
170+
if self.softspace:
171+
self.writer.send_flowing_data(" ")
166172
self.hard_break = data[-1:] == '\n'
167173
self.nospace = self.para_end = self.softspace = \
168174
self.parskip = self.have_label = 0
169175
self.writer.send_literal_data(data)
170176

171177
def flush_softspace(self):
172178
if self.softspace:
173-
self.hard_break = self.nospace = self.para_end = self.parskip = \
179+
self.hard_break = self.para_end = self.parskip = \
174180
self.have_label = self.softspace = 0
181+
self.nospace = 1
175182
self.writer.send_flowing_data(' ')
176183

177184
def push_alignment(self, align):
@@ -194,7 +201,8 @@ def pop_alignment(self):
194201

195202
def push_font(self, (size, i, b, tt)):
196203
if self.softspace:
197-
self.hard_break = self.nospace = self.para_end = self.softspace = 0
204+
self.hard_break = self.para_end = self.softspace = 0
205+
self.nospace = 1
198206
self.writer.send_flowing_data(' ')
199207
if self.font_stack:
200208
csize, ci, cb, ctt = self.font_stack[-1]
@@ -207,9 +215,6 @@ def push_font(self, (size, i, b, tt)):
207215
self.writer.new_font(font)
208216

209217
def pop_font(self):
210-
if self.softspace:
211-
self.hard_break = self.nospace = self.para_end = self.softspace = 0
212-
self.writer.send_flowing_data(' ')
213218
if self.font_stack:
214219
del self.font_stack[-1]
215220
if self.font_stack:
@@ -241,22 +246,20 @@ def set_spacing(self, spacing):
241246

242247
def push_style(self, *styles):
243248
if self.softspace:
244-
self.hard_break = self.nospace = self.para_end = self.softspace = 0
249+
self.hard_break = self.para_end = self.softspace = 0
250+
self.nospace = 1
245251
self.writer.send_flowing_data(' ')
246252
for style in styles:
247253
self.style_stack.append(style)
248254
self.writer.new_styles(tuple(self.style_stack))
249255

250256
def pop_style(self, n=1):
251-
if self.softspace:
252-
self.hard_break = self.nospace = self.para_end = self.softspace = 0
253-
self.writer.send_flowing_data(' ')
254257
del self.style_stack[-n:]
255258
self.writer.new_styles(tuple(self.style_stack))
256259

257260
def assert_line_data(self, flag=1):
258261
self.nospace = self.hard_break = not flag
259-
self.para_end = self.have_label = 0
262+
self.para_end = self.parskip = self.have_label = 0
260263

261264

262265
class NullWriter:

0 commit comments

Comments
 (0)