Python docutils.languages.append() Examples

The following are 30 code examples of docutils.languages.append(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module docutils.languages , or try the search function .
Example #1
Source File: _html_base.py    From faces with GNU General Public License v2.0 6 votes vote down vote up
def visit_entry(self, node):
        atts = {'class': []}
        if isinstance(node.parent.parent, nodes.thead):
            atts['class'].append('head')
        if node.parent.parent.parent.stubs[node.parent.column]:
            # "stubs" list is an attribute of the tgroup element
            atts['class'].append('stub')
        if atts['class']:
            tagname = 'th'
            atts['class'] = ' '.join(atts['class'])
        else:
            tagname = 'td'
            del atts['class']
        node.parent.column += 1
        if 'morerows' in node:
            atts['rowspan'] = node['morerows'] + 1
        if 'morecols' in node:
            atts['colspan'] = node['morecols'] + 1
            node.parent.column += node['morecols']
        self.body.append(self.starttag(node, tagname, '', **atts))
        self.context.append('</%s>\n' % tagname.lower())
        # TODO: why does the html4css1 writer insert an NBSP into empty cells?
        # if len(node) == 0:              # empty cell
        #     self.body.append('&#0160;') # no-break space 
Example #2
Source File: _html_base.py    From faces with GNU General Public License v2.0 6 votes vote down vote up
def visit_literal(self, node):
        # special case: "code" role
        classes = node.get('classes', [])
        if 'code' in classes:
            # filter 'code' from class arguments
            node['classes'] = [cls for cls in classes if cls != 'code']
            self.body.append(self.starttag(node, 'code', ''))
            return
        self.body.append(
            self.starttag(node, 'span', '', CLASS='docutils literal'))
        text = node.astext()
        # remove hard line breaks (except if in a parsed-literal block)
        if not isinstance(node.parent, nodes.literal_block):
            text = text.replace('\n', ' ')
        # Protect text like ``--an-option`` and the regular expression
        # ``[+]?(\d+(\.\d*)?|\.\d+)`` from bad line wrapping
        for token in self.words_and_spaces.findall(text):
            if token.strip() and self.sollbruchstelle.search(token):
                self.body.append('<span class="pre">%s</span>'
                                    % self.encode(token))
            else:
                self.body.append(self.encode(token))
        self.body.append('</span>')
        # Content already processed:
        raise nodes.SkipNode 
Example #3
Source File: _html_base.py    From faces with GNU General Public License v2.0 6 votes vote down vote up
def depart_colspec(self, node):
        # write out <colgroup> when all colspecs are processed
        if isinstance(node.next_node(descend=False, siblings=True),
                      nodes.colspec):
            return
        if 'colwidths-auto' in node.parent.parent['classes'] or (
            'colwidths-auto' in self.settings.table_style and
            ('colwidths-given' not in node.parent.parent['classes'])):
            return
        total_width = sum(node['colwidth'] for node in self.colspecs)
        self.body.append(self.starttag(node, 'colgroup'))
        for node in self.colspecs:
            colwidth = int(node['colwidth'] * 100.0 / total_width + 0.5)
            self.body.append(self.emptytag(node, 'col',
                                           style='width: %i%%' % colwidth))
        self.body.append('</colgroup>\n') 
Example #4
Source File: _html_base.py    From faces with GNU General Public License v2.0 5 votes vote down vote up
def visit_footnote(self, node):
        if not self.in_footnote_list:
            classes = 'footnote ' + self.settings.footnote_references
            self.body.append('<dl class="%s">\n'%classes)
            self.in_footnote_list = True 
Example #5
Source File: _html_base.py    From faces with GNU General Public License v2.0 5 votes vote down vote up
def visit_list_item(self, node):
        self.body.append(self.starttag(node, 'li', '')) 
Example #6
Source File: _html_base.py    From faces with GNU General Public License v2.0 5 votes vote down vote up
def visit_option_group(self, node):
        self.body.append(self.starttag(node, 'dt', ''))
        self.body.append('<kbd>') 
Example #7
Source File: _html_base.py    From faces with GNU General Public License v2.0 5 votes vote down vote up
def depart_option_group(self, node):
        self.body.append('</kbd></dt>\n') 
Example #8
Source File: _html_base.py    From faces with GNU General Public License v2.0 5 votes vote down vote up
def depart_option_argument(self, node):
        self.body.append('</var>') 
Example #9
Source File: _html_base.py    From faces with GNU General Public License v2.0 5 votes vote down vote up
def add_meta(self, tag):
        self.meta.append(tag)
        self.head.append(tag) 
Example #10
Source File: _html_base.py    From faces with GNU General Public License v2.0 5 votes vote down vote up
def depart_literal_block(self, node):
        if 'code' in node.get('classes', []):
            self.body.append('</code>')
        self.body.append('</pre>\n')

    # Mathematics:
    # As there is no native HTML math support, we provide alternatives
    # for the math-output: LaTeX and MathJax simply wrap the content,
    # HTML and MathML also convert the math_code.
    # HTML container 
Example #11
Source File: _html_base.py    From faces with GNU General Public License v2.0 5 votes vote down vote up
def visit_literal_block(self, node):
        self.body.append(self.starttag(node, 'pre', '', CLASS='literal-block'))
        if 'code' in node.get('classes', []):
            self.body.append('<code>') 
Example #12
Source File: _html_base.py    From faces with GNU General Public License v2.0 5 votes vote down vote up
def depart_literal(self, node):
        # skipped unless literal element is from "code" role:
        self.body.append('</code>') 
Example #13
Source File: _html_base.py    From faces with GNU General Public License v2.0 5 votes vote down vote up
def depart_option(self, node):
        self.body.append('</span>')
        if isinstance(node.next_node(descend=False, siblings=True),
                      nodes.option):
            self.body.append(', ') 
Example #14
Source File: _html_base.py    From faces with GNU General Public License v2.0 5 votes vote down vote up
def visit_header(self, node):
        self.context.append(len(self.body)) 
Example #15
Source File: _html_base.py    From faces with GNU General Public License v2.0 5 votes vote down vote up
def visit_generated(self, node):
        if 'sectnum' in node['classes']:
            # get section number (strip trailing no-break-spaces)
            sectnum = node.astext().rstrip(' ')
            # print sectnum.encode('utf-8')
            self.body.append('<span class="sectnum">%s</span> '
                                    % self.encode(sectnum))
            # Content already processed:
            raise nodes.SkipNode 
Example #16
Source File: _html_base.py    From faces with GNU General Public License v2.0 5 votes vote down vote up
def depart_footnote_reference(self, node):
        self.body.append('</a>')

    # Docutils-generated text: put section numbers in a span for CSS styling: 
Example #17
Source File: _html_base.py    From faces with GNU General Public License v2.0 5 votes vote down vote up
def visit_footnote_reference(self, node):
        href = '#' + node['refid']
        classes = 'footnote-reference ' + self.settings.footnote_references
        self.body.append(self.starttag(node, 'a', '', #suffix,
                                       CLASS=classes, href=href)) 
Example #18
Source File: _html_base.py    From faces with GNU General Public License v2.0 5 votes vote down vote up
def visit_inline(self, node):
        self.body.append(self.starttag(node, 'span', '')) 
Example #19
Source File: _html_base.py    From faces with GNU General Public License v2.0 5 votes vote down vote up
def depart_footer(self, node):
        start = self.context.pop()
        footer = [self.starttag(node, 'div', CLASS='footer'),
                  '<hr class="footer" />\n']
        footer.extend(self.body[start:])
        footer.append('\n</div>\n')
        self.footer.extend(footer)
        self.body_suffix[:0] = footer
        del self.body[start:]

    # footnotes
    # ---------
    # use definition list instead of table for footnote text

    # TODO: use the new HTML5 element <aside>? (Also for footnote text) 
Example #20
Source File: _html_base.py    From faces with GNU General Public License v2.0 5 votes vote down vote up
def visit_footer(self, node):
        self.context.append(len(self.body)) 
Example #21
Source File: _html_base.py    From faces with GNU General Public License v2.0 5 votes vote down vote up
def depart_figure(self, node):
        self.body.append('</div>\n')

    # use HTML 5 <footer> element? 
Example #22
Source File: _html_base.py    From faces with GNU General Public License v2.0 5 votes vote down vote up
def visit_figure(self, node):
        atts = {'class': 'figure'}
        if node.get('width'):
            atts['style'] = 'width: %s' % node['width']
        if node.get('align'):
            atts['class'] += " align-" + node['align']
        self.body.append(self.starttag(node, 'div', **atts)) 
Example #23
Source File: _html_base.py    From faces with GNU General Public License v2.0 5 votes vote down vote up
def visit_field_body(self, node):
        self.body.append(self.starttag(node, 'dd', '',
                                       CLASS=''.join(node.parent['classes'])))
        # prevent misalignment of following content if the field is empty:
        if not node.children:
            self.body.append('<p></p>') 
Example #24
Source File: _html_base.py    From faces with GNU General Public License v2.0 5 votes vote down vote up
def depart_field_name(self, node):
        self.body.append('</dt>\n') 
Example #25
Source File: _html_base.py    From faces with GNU General Public License v2.0 5 votes vote down vote up
def visit_field_name(self, node):
        self.body.append(self.starttag(node, 'dt', '',
                                       CLASS=''.join(node.parent['classes']))) 
Example #26
Source File: _html_base.py    From faces with GNU General Public License v2.0 5 votes vote down vote up
def depart_field_list(self, node):
        self.body.append('</dl>\n') 
Example #27
Source File: _html_base.py    From faces with GNU General Public License v2.0 5 votes vote down vote up
def visit_field_list(self, node):
        # Keep simple paragraphs in the field_body to enable CSS
        # rule to start body on new line if the label is too long
        classes = 'field-list'
        if (self.is_compactable(node)):
            classes += ' simple'
        self.body.append(self.starttag(node, 'dl', CLASS=classes)) 
Example #28
Source File: _html_base.py    From faces with GNU General Public License v2.0 5 votes vote down vote up
def visit_enumerated_list(self, node):
        atts = {}
        if 'start' in node:
            atts['start'] = node['start']
        if 'enumtype' in node:
            atts['class'] = node['enumtype']
        if self.is_compactable(node):
            atts['class'] = (atts.get('class', '') + ' simple').strip()
        self.body.append(self.starttag(node, 'ol', **atts)) 
Example #29
Source File: _html_base.py    From faces with GNU General Public License v2.0 5 votes vote down vote up
def depart_entry(self, node):
        self.body.append(self.context.pop()) 
Example #30
Source File: _html_base.py    From faces with GNU General Public License v2.0 5 votes vote down vote up
def depart_emphasis(self, node):
        self.body.append('</em>')