コード例 #1
0
ファイル: publish_text.py プロジェクト: wijjo/cmdo
    def flushPending(self, context):

        # Make sure a non-plaintext document starts with at least one blank line
        depth = context.getDepth()
        if self.nFlushes == 0 and not self.plaintextDoc:
            gap = 1
        else:
            gap = 0
        self.nFlushes += 1

        # Start from the topmost node with text and work down.  There should be
        # no remaining cached text, gaps, headings or borders when done.
        for level in range(depth-1, -1, -1):

            gapCur = context.takeCache('gapBefore', default = 0, level = level)
            if gapCur > gap:
                gap = gapCur

            indent = context.getCache('indent', '', level = level, inherit = True)
            indentInside = context.getCache('indentInside', '', level = level, inherit = True)

            # Heading?
            heading = context.takeCache('heading', level = level)
            if heading:
                hdLevel = len(context.getPropsStack('heading', level = level + 1))
                frame = framesHeading[min(hdLevel, len(framesHeading) - 1)]
                if frame.t and gap < 2:
                    gap = 2
                elif gap < 1:
                    gap = 1
                self._writeln(context, gap, indent, frame.build(heading))
                gap = 1

            # Top border?
            borderTop = context.takeCache('borderTop', level = level)
            if borderTop:
                self._writeln(context, gap, indent, borderTop)
                gap = 0

            # Text?
            indent += indentInside
            text = context.takeCache('text', default = '', level = level)
            if text:
                if (context.getProp('form', level = level, inherit = True) == 'plaintext' or
                    context.getCache('plaintext')):
                    for line in text_utility.textFormatPlain(text, indent):
                        self._writeln(context, gap, '', line)
                        gap = 0
                    self.setGapBefore(context, 1, level = level, inherit = True)
                else:
                    prefix = context.getCache('prefix', default = '', level = level, inherit = True)
                    for line in text_utility.textFormatWrapped(text, indent, prefix, maxWidth):
                        self._writeln(context, gap, '', line)
                        gap = 0
コード例 #2
0
ファイル: publish_html.py プロジェクト: wijjo/cmdo
 def nodeBegin(self, context):
     form    = context.getProp('form', default = '')
     heading = context.getProp('heading')
     tocid   = context.getProp('tocid')
     if tocid:
         self.write(context, '<span id="%s">\n' % tocid)
     if heading:
         heading = cgi.escape(heading)
         self.hdLevel += 1
         if tocid and self.hdLevel <= 2:
             self.write(context, '<table class="h%dbar"><tr>' % self.hdLevel)
             self.write(context, '<td><h%d class="h%dbarheading">%s</h%d></td>'
                             % (self.hdLevel, self.hdLevel, heading, self.hdLevel))
             self.write(context, '<td class="h%dbartopcell">' % self.hdLevel)
             self.write(context, '<a href="#toc" class="h%dbartoplink">Top</a>' % self.hdLevel)
             self.write(context, '</td>')
             self.write(context, '</tr></table>\n')
         else:
             self.write(context, '<h%d class="heading%d">%s</h%d>\n'
                                     % (self.hdLevel, self.hdLevel, heading, self.hdLevel))
     context.cacheProp('text')
     context.setCache('newLine', True)
     if form == 'table':
         self.tableBegin(context)
     elif form == 'list':
         self.listBegin(context)
     elif form == 'item':
         self.itemBegin(context)
     elif form == 'row':
         self.rowBegin(context)
     elif form == 'cell':
         self.cellBegin(context)
     elif form == 'plaintext':
         self.plaintextBegin(context)
     elif form == 'link':
         self.linkBegin(context)
     elif form == 'block':
         self.blockBegin(context)
     elif form[:3] == 'toc':
         assert len(form) > 3
         self.tocBegin(context, int(form[3:]))
     if context.hasCache('text'):
         text = cgi.escape(context.getCache('text'))
         if self.plaintext > 0:
             context.write('\n<pre>')
             #indent = '  ' * self.depth
             indent = ''
             for line in text_utility.textFormatPlain(text, indent, 80):
                 context.write('\n')
                 context.write(line)
             context.write('</pre>\n')
         else:
             if context.getCache('newLine', default = True):
                 indent = '  ' * self.depth
                 for line in text_utility.textFormatWrapped(text, indent, '', 80):
                     context.write('\n')
                     context.write(line)
             else:
                 context.write(text)
         context.flush()
     self.depth += 1
     if heading and self.pendingTOC:
         self.pendingTOC = False
         context.feedTOC(self)