MCPcopy Create free account
hub / github.com/aaronsw/html2text / o

Method o

html2text.py:363–428  ·  view source on GitHub ↗
(self, data, puredata=0, force=0)

Source from the content-addressed store, hash-verified

361 def p(self): self.p_p = 2
362
363 def o(self, data, puredata=0, force=0):
364 if self.abbr_data is not None: self.abbr_data += data
365
366 if not self.quiet:
367 if puredata and not self.pre:
368 data = re.sub('\s+', ' ', data)
369 if data and data[0] == ' ':
370 self.space = 1
371 data = data[1:]
372 if not data and not force: return
373
374 if self.startpre:
375 #self.out(" :") #TODO: not output when already one there
376 self.startpre = 0
377
378 bq = (">" * self.blockquote)
379 if not (force and data and data[0] == ">") and self.blockquote: bq += " "
380
381 if self.pre:
382 bq += " "
383 data = data.replace("\n", "\n"+bq)
384
385 if self.start:
386 self.space = 0
387 self.p_p = 0
388 self.start = 0
389
390 if force == 'end':
391 # It's the end.
392 self.p_p = 0
393 self.out("\n")
394 self.space = 0
395
396
397 if self.p_p:
398 self.out(('\n'+bq)*self.p_p)
399 self.space = 0
400
401 if self.space:
402 if not self.lastWasNL: self.out(' ')
403 self.space = 0
404
405 if self.a and ((self.p_p == 2 and LINKS_EACH_PARAGRAPH) or force == "end"):
406 if force == "end": self.out("\n")
407
408 newa = []
409 for link in self.a:
410 if self.outcount > link['outcount']:
411 self.out(" ["+ str(link['count']) +"]: " + urlparse.urljoin(self.baseurl, link['href']))
412 if has_key(link, 'title'): self.out(" ("+link['title']+")")
413 self.out("\n")
414 else:
415 newa.append(link)
416
417 if self.a != newa: self.out("\n") # Don't need an extra line when nothing was done.
418
419 self.a = newa
420

Callers 5

closeMethod · 0.95
handle_charrefMethod · 0.95
handle_entityrefMethod · 0.95
handle_tagMethod · 0.95
handle_dataMethod · 0.95

Calls 1

has_keyFunction · 0.85

Tested by

no test coverage detected