def write_text(self, *args, **kwargs): #------------------------------------------------------------- # RawTextRfcWriter override # # We should be able to handle mostly all of the nroff commands by # intercepting the alignment and indentation arguments #------------------------------------------------------------- # Store buffer position for paging information if 'buf' in kwargs: buffer = kwargs["buf"] else: buffer = self.buf par = [] kwargs["buf"] = par begin = len(buffer) leading_blankline = kwargs.get("leading_blankline", False) if self.in_list and not leading_blankline and len( buffer) and not buffer[-1].startswith('.sp'): self.write_nroff('.br') RawTextRfcWriter.write_text(self, *args, **kwargs) # Escape as needed for i in range(len(par)): par[i] = par[i].strip() if par[i] and par[i][0] in nroff_linestart_meta: par[i] = nroff_escape_linestart(par[i]) # Handle alignment/indentation align = kwargs.get('align', 'left') indent = kwargs.get('indent', 0) sub_indent = kwargs.get('sub_indent', 0) bullet = kwargs.get('bullet', '') if align == 'center': self.write_nroff('.ce %s' % len([x for x in par if x != ""]), buf=buffer) else: # Use bullet for indentation if sub not specified full_indent = sub_indent and indent + sub_indent or indent + len( bullet) self._indent(full_indent, buf=buffer) if bullet and len(bullet.strip()) > 0: # Bullet line: title just uses base indent self.write_nroff('.ti %s' % indent, buf=buffer) mark = len(buffer) # Write to buffer buffer.extend(par) # Page break information end = len(buffer) if buffer == self.buf: self._set_break_hint(end - mark, 'txt', begin) """
def write_heading(self, text, bullet='', autoAnchor=None, anchor=None, level=1): # Store the line number of this heading with its unique anchor, # to later create paging info begin = len(self.buf) self.heading_marks[begin] = autoAnchor RawTextRfcWriter.write_heading(self, text, bullet=bullet, \ autoAnchor=autoAnchor, anchor=anchor, level=level) # Reserve room for a blankline and some lines of section content # text, in order to prevent orphan headings # orphanlines = self.get_numeric_pi('sectionorphan', default=self.orphan_limit + 2) end = len(self.buf) nr = len([ l for l in self.buf[begin:end] if l and l[0] in nroff_linestart_meta ]) needed = end - begin - nr + orphanlines self._set_break_hint(needed, "raw", begin)
def write_text(self, *args, **kwargs): #------------------------------------------------------------- # RawTextRfcWriter override # # We should be able to handle mostly all of the nroff commands by # intercepting the alignment and indentation arguments #------------------------------------------------------------- # Store buffer position for paging information if 'buf' in kwargs: buffer = kwargs["buf"] else: buffer = self.buf par = [] kwargs["buf"] = par begin = len(buffer) leading_blankline = kwargs.get("leading_blankline", False) if self.in_list and not leading_blankline and len(buffer) and not buffer[-1].startswith('.sp'): self.write_nroff('.br') RawTextRfcWriter.write_text(self, *args, **kwargs) # Escape as needed for i in range(len(par)): par[i] = par[i].strip() if par[i] and par[i][0] in nroff_linestart_meta: par[i] = nroff_escape_linestart(par[i]) # Handle alignment/indentation align = kwargs.get('align', 'left') indent = kwargs.get('indent', 0) sub_indent = kwargs.get('sub_indent', 0) bullet = kwargs.get('bullet', '') if align == 'center': self.write_nroff('.ce %s' % len([x for x in par if x != ""]), buf=buffer) else: # Use bullet for indentation if sub not specified full_indent = sub_indent and indent + sub_indent or indent + len(bullet) self._indent(full_indent, buf=buffer) if bullet and len(bullet.strip()) > 0: # Bullet line: title just uses base indent self.write_nroff('.ti %s' % indent, buf=buffer) mark = len(buffer) # Write to buffer buffer.extend(par) # Page break information end = len(buffer) if buffer == self.buf: self._set_break_hint(end - mark, 'txt', begin) """
def write_heading(self, text, bullet='', autoAnchor=None, anchor=None, \ level=1): # Store the line number of this heading with its unique anchor, # to later create paging info begin = len(self.buf) self.heading_marks[begin] = autoAnchor RawTextRfcWriter.write_heading(self, text, bullet=bullet, \ autoAnchor=autoAnchor, anchor=anchor, \ level=level) # Reserve room for a blankline and some lines of section content # text, in order to prevent orphan headings end = len(self.buf) + self.pis["sectionorphan"] self._set_break_hint(end-begin, 'raw', begin)
def write_heading(self, text, bullet='', autoAnchor=None, anchor=None, \ level=1): # Store the line number of this heading with its unique anchor, # to later create paging info begin = len(self.buf) self.heading_marks[begin] = autoAnchor RawTextRfcWriter.write_heading(self, text, bullet=bullet, \ autoAnchor=autoAnchor, anchor=anchor, \ level=level) # Reserve room for a blankline and some lines of section content # text, in order to prevent orphan headings end = len(self.buf) + self.pis["sectionorphan"] self._set_break_hint(end - begin, 'raw', begin)
def __init__(self, xmlrfc, width=72, quiet=False, verbose=False, date=datetime.date.today(), omit_headers=False): RawTextRfcWriter.__init__(self, xmlrfc, width=width, quiet=quiet, \ verbose=verbose, date=date) self.left_header = '' self.center_header = '' self.right_header = '' self.left_footer = '' self.center_footer = '' self.break_hints = {} self.heading_marks = {} self.paged_toc_marker = 0 self.page_line = 0 self.omit_headers = omit_headers
def write_heading(self, text, bullet='', autoAnchor=None, anchor=None, level=1): # Store the line number of this heading with its unique anchor, # to later create paging info begin = len(self.buf) self.heading_marks[begin] = autoAnchor RawTextRfcWriter.write_heading(self, text, bullet=bullet, \ autoAnchor=autoAnchor, anchor=anchor, level=level) # Reserve room for a blankline and some lines of section content # text, in order to prevent orphan headings end = len(self.buf) nr = len([ l for l in self.buf[begin:end] if l and l[0] in nroff_linestart_meta]) self._set_break_hint(end - begin - nr + int(self.pis["sectionorphan"]), "raw", begin)
def pre_rendering(self): """ Prepares the header and footer information """ # Raw textwriters preprocessing will replace unicode with safe ascii RawTextRfcWriter.pre_rendering(self) # Discard hints and marks from indexing pass self.break_hints = {} self.heading_marks = {} if self.pis['private']: self.left_header = '' elif self.draft: self.left_header = 'Internet-Draft' else: self.left_header = 'RFC %s' % self.r.attrib.get('number', '') title = self.r.find('front/title') if title is not None: self.center_header = title.attrib.get('abbrev', title.text) date = self.r.find('front/date') if date is not None: month = date.attrib.get('month', '') year = date.attrib.get('year', '') self.right_header = month + ' ' + year authors = self.r.findall('front/author') surnames = [ a.attrib.get('surname') for a in authors if a.attrib.get('surname', None) ] if len(surnames) == 1: self.left_footer = surnames[0] elif len(surnames) == 2: self.left_footer = '%s & %s' % ( surnames[0], surnames[1], ) elif len(surnames) > 2: self.left_footer = '%s, et al.' % surnames[0] if self.draft: self.center_footer = 'Expires %s' % self.expire_string else: self.center_footer = self.boilerplate.get( self.r.attrib.get('category', ''), '(Category') # Check for PI override self.center_footer = self.pis.get('footer', self.center_footer) self.left_header = self.pis.get('header', self.left_header)
def pre_rendering(self): """ Prepares the header and footer information """ # Raw textwriters preprocessing will replace unicode with safe ascii RawTextRfcWriter.pre_rendering(self) # Discard hints and marks from indexing pass self.break_hints = {} self.heading_marks = {} if self.pis['private']: self.left_header = '' elif self.draft: self.left_header = 'Internet-Draft' else: self.left_header = 'RFC %s' % self.r.attrib.get('number', '') title = self.r.find('front/title') if title is not None: self.center_header = title.attrib.get('abbrev', title.text) date = self.r.find('front/date') if date is not None: month = date.attrib.get('month', '') year = date.attrib.get('year', '') self.right_header = month + ' ' + year authors = self.r.findall('front/author') surnames = [ a.attrib.get('surname') for a in authors if a.attrib.get('surname', None) ] if len(surnames) == 1: self.left_footer = surnames[0] elif len(surnames) == 2: self.left_footer = '%s & %s' % (surnames[0], surnames[1],) elif len(surnames) > 2: self.left_footer = '%s, et al.' % surnames[0] if self.draft: self.center_footer = 'Expires %s' % self.expire_string else: self.center_footer = self.boilerplate.get( self.r.attrib.get('category', ''), '(Category') # Check for PI override self.center_footer = self.pis.get('footer', self.center_footer) self.left_header = self.pis.get('header', self.left_header)
def __init__(self, xmlrfc, width=72, quiet=None, options=default_options, date=datetime.date.today(), omit_headers=False): if not quiet is None: options.quiet = quiet RawTextRfcWriter.__init__(self, xmlrfc, options=options, date=date) self.left_header = '' self.center_header = '' self.right_header = '' self.left_footer = '' self.center_footer = '' self.break_hints = {} self.heading_marks = {} self.paged_toc_marker = 0 self.page_line = 0 self.omit_headers = omit_headers self.page_end_blank_lines = 2 # Don't permit less than this many lines of a broken paragrah at the # top of a page: self.widow_limit = self.get_numeric_pi('widowlimit', default=2) # Don't permit less than this many lines of a broken paragrah at the # bottom of a page: self.orphan_limit = self.get_numeric_pi('orphanlimit', default=2)
def write_heading(self, text, bullet='', autoAnchor=None, anchor=None, \ level=1): # Store the line number of this heading with its unique anchor, # to later create paging info begin = len(self.buf) self.heading_marks[begin] = autoAnchor RawTextRfcWriter.write_heading(self, text, bullet=bullet, \ autoAnchor=autoAnchor, anchor=anchor, \ level=level) # Reserve room for a blankline and some lines of section content # text, in order to prevent orphan headings # # We've now written a blank line before the heading, followed by # the heading. Next will be a blank line, followed by the section # content. We thus need (begin - end) + 1 + orphan_limit lines, but # if we ask for only that, we'll end up moving the text, to the next # page, without moving the section heading. So we ask for one more self.orphan_limit = self.get_numeric_pi('orphanlimit', default=self.orphan_limit) orphanlines = self.get_numeric_pi('sectionorphan', default=self.orphan_limit+2) end = len(self.buf) needed = end - begin + orphanlines self._set_break_hint(needed, 'raw', begin)
def post_process_lines(self, lines): return RawTextRfcWriter.post_process_lines(self, lines)