Exemplo n.º 1
0
 def symbolize_footnotes(self):
     """Add symbols indexes to "[*]"-style footnotes and references."""
     labels = []
     for footnote in self.document.symbol_footnotes:
         reps, index = divmod(self.document.symbol_footnote_start, len(self.symbols))
         labeltext = self.symbols[index] * (reps + 1)
         labels.append(labeltext)
         footnote.insert(0, nodes.label("", labeltext))
         self.document.symbol_footnote_start += 1
         self.document.set_id(footnote)
     i = 0
     for ref in self.document.symbol_footnote_refs:
         try:
             ref += nodes.Text(labels[i])
         except IndexError:
             msg = self.document.reporter.error(
                 "Too many symbol footnote references: only %s "
                 "corresponding footnotes available." % len(labels),
                 base_node=ref,
             )
             msgid = self.document.set_id(msg)
             for ref in self.document.symbol_footnote_refs[i:]:
                 if ref.resolved or ref.hasattr("refid"):
                     continue
                 prb = nodes.problematic(ref.rawsource, ref.rawsource, refid=msgid)
                 prbid = self.document.set_id(prb)
                 msg.add_backref(prbid)
                 ref.replace_self(prb)
             break
         footnote = self.document.symbol_footnotes[i]
         assert len(footnote["ids"]) == 1
         ref["refid"] = footnote["ids"][0]
         self.document.note_refid(ref)
         footnote.add_backref(ref["ids"][0])
         i += 1
Exemplo n.º 2
0
    def run(self):
        global ftnote_lst

        #<footnote auto="1" backrefs="id1" ids="proj2" names="proj2">
        #   <label>1</label>
        #   <paragraph>Project 2 Documentation, v3 2018</paragraph>
        #</footnote>

        ftnotes = []
        ftnote_idx = 0
        for ref in ftnote_lst:
            entry = self.state.document.settings.env.app.config.global_citations[
                ref]
            ftnote_idx += 1
            ftnote = nodes.footnote(auto="1",
                                    backrefs="id%d" % ftnote_idx,
                                    ids=ref,
                                    names=ref)
            ftnote += nodes.label(text="%d" % ftnote_idx)
            ftnote_para = nodes.paragraph()
            ftnote_para += nodes.Text(" %s. " % entry['author'])
            ftnote_para += ftnote_pxref(self.state.document, ref)
            ftnote_para += nodes.Text(".")
            ftnote_para += nodes.Text(" %s. " % entry['date'])
            ftnote += ftnote_para
            ftnotes.append(ftnote)

        # Wipe this list. (This makes this directive non-reentrant.)
        # TODO: Find a way to execute this on "exit <document>" event.
        while (len(ftnote_lst) > 0):
            ftnote_lst.pop()

        return ftnotes
Exemplo n.º 3
0
    def renumber_footnotes(self):
        # type: () -> None
        collector = FootnoteCollector(self.document)
        self.document.walkabout(collector)

        num = 0
        for footnote in collector.auto_footnotes:
            # search unused footnote number
            while True:
                num += 1
                if str(num) not in collector.used_footnote_numbers:
                    break

            # assign new footnote number
            old_label = cast(nodes.label, footnote[0])
            old_label.replace_self(nodes.label('', str(num)))
            if old_label in footnote['names']:
                footnote['names'].remove(old_label.astext())
            footnote['names'].append(str(num))

            # update footnote_references by new footnote number
            docname = footnote['docname']
            for ref in collector.footnote_refs:
                if docname == ref['docname'] and footnote['ids'][0] == ref['refid']:
                    ref.remove(ref[0])
                    ref += nodes.Text(str(num))
Exemplo n.º 4
0
    def number_footnotes(self, startnum):
        """
        Assign numbers to autonumbered footnotes.

        For labeled autonumbered footnotes, copy the number over to
        corresponding footnote references.
        """
        for footnote in self.document.autofootnotes:
            while 1:
                label = str(startnum)
                startnum += 1
                if not self.document.nameids.has_key(label):
                    break
            footnote.insert(0, nodes.label('', label))
            if footnote.hasattr('dupname'):
                continue
            if footnote.hasattr('name'):
                name = footnote['name']
                for ref in self.document.footnote_refs.get(name, []):
                    ref += nodes.Text(label)
                    ref.delattr('refname')
                    ref['refid'] = footnote['id']
                    footnote.add_backref(ref['id'])
                    self.document.note_refid(ref)
                    ref.resolved = 1
            else:
                footnote['name'] = label
                self.document.note_explicit_target(footnote, footnote)
                self.autofootnote_labels.append(label)
        return startnum
Exemplo n.º 5
0
    def number_footnotes(self, startnum):
        """
        Assign numbers to autonumbered footnotes.

        For labeled autonumbered footnotes, copy the number over to
        corresponding footnote references.
        """
        for footnote in self.document.autofootnotes:
            while True:
                label = str(startnum)
                startnum += 1
                if label not in self.document.nameids:
                    break
            footnote.insert(0, nodes.label('', label))
            for name in footnote['names']:
                for ref in self.document.footnote_refs.get(name, []):
                    ref += nodes.Text(label)
                    ref.delattr('refname')
                    assert len(footnote['ids']) == len(ref['ids']) == 1
                    ref['refid'] = footnote['ids'][0]
                    footnote.add_backref(ref['ids'][0])
                    self.document.note_refid(ref)
                    ref.resolved = 1
            if not footnote['names'] and not footnote['dupnames']:
                footnote['names'].append(label)
                self.document.note_explicit_target(footnote, footnote)
                self.autofootnote_labels.append(label)
        return startnum
Exemplo n.º 6
0
    def number_footnotes(self, startnum):
        """
        Assign numbers to autonumbered footnotes.

        For labeled autonumbered footnotes, copy the number over to
        corresponding footnote references.
        """
        for footnote in self.document.autofootnotes:
            while 1:
                label = str(startnum)
                startnum += 1
                if label not in self.document.nameids:
                    break
            footnote.insert(0, nodes.label('', label))
            for name in footnote['names']:
                for ref in self.document.footnote_refs.get(name, []):
                    ref += nodes.Text(label)
                    ref.delattr('refname')
                    assert len(footnote['ids']) == len(ref['ids']) == 1
                    ref['refid'] = footnote['ids'][0]
                    footnote.add_backref(ref['ids'][0])
                    self.document.note_refid(ref)
                    ref.resolved = 1
            if not footnote['names'] and not footnote['dupnames']:
                footnote['names'].append(label)
                self.document.note_explicit_target(footnote, footnote)
                self.autofootnote_labels.append(label)
        return startnum
Exemplo n.º 7
0
    def renumber_footnotes(self):
        # type: () -> None
        collector = FootnoteCollector(self.document)
        self.document.walkabout(collector)

        num = 0
        for footnote in collector.auto_footnotes:
            # search unused footnote number
            while True:
                num += 1
                if str(num) not in collector.used_footnote_numbers:
                    break

            # assign new footnote number
            old_label = footnote[0].astext()
            footnote[0].replace_self(nodes.label('', str(num)))
            if old_label in footnote['names']:
                footnote['names'].remove(old_label)
            footnote['names'].append(str(num))

            # update footnote_references by new footnote number
            docname = footnote['docname']
            for ref in collector.footnote_refs:
                if docname == ref['docname'] and footnote['ids'][0] == ref['refid']:
                    ref.remove(ref[0])
                    ref += nodes.Text(str(num))
Exemplo n.º 8
0
 def symbolize_footnotes(self):
     """Add symbols indexes to "[*]"-style footnotes and references."""
     labels = []
     for footnote in self.document.symbol_footnotes:
         reps, index = divmod(self.document.symbol_footnote_start,
                              len(self.symbols))
         labeltext = self.symbols[index] * (reps + 1)
         labels.append(labeltext)
         footnote.insert(0, nodes.label('', labeltext))
         self.document.symbol_footnote_start += 1
         self.document.set_id(footnote)
     i = 0
     for ref in self.document.symbol_footnote_refs:
         try:
             ref += nodes.Text(labels[i])
         except IndexError:
             msg = self.document.reporter.error(
                   'Too many symbol footnote references: only %s '
                   'corresponding footnotes available.' % len(labels),
                   base_node=ref)
             msgid = self.document.set_id(msg)
             for ref in self.document.symbol_footnote_refs[i:]:
                 if ref.resolved or ref.hasattr('refid'):
                     continue
                 prb = nodes.problematic(
                       ref.rawsource, ref.rawsource, refid=msgid)
                 prbid = self.document.set_id(prb)
                 msg.add_backref(prbid)
                 ref.parent.replace(ref, prb)
             break
         footnote = self.document.symbol_footnotes[i]
         ref['refid'] = footnote['id']
         self.document.note_refid(ref)
         footnote.add_backref(ref['id'])
         i += 1
Exemplo n.º 9
0
    def number_footnotes(self, startnum):
        """
        Assign numbers to autonumbered footnotes.

        For labeled autonumbered footnotes, copy the number over to
        corresponding footnote references.
        """
        for footnote in self.document.autofootnotes:
            while 1:
                label = str(startnum)
                startnum += 1
                if not self.document.nameids.has_key(label):
                    break
            footnote.insert(0, nodes.label('', label))
            if footnote.hasattr('dupname'):
                continue
            if footnote.hasattr('name'):
                name = footnote['name']
                for ref in self.document.footnote_refs.get(name, []):
                    ref += nodes.Text(label)
                    ref.delattr('refname')
                    ref['refid'] = footnote['id']
                    footnote.add_backref(ref['id'])
                    self.document.note_refid(ref)
                    ref.resolved = 1
            else:
                footnote['name'] = label
                self.document.note_explicit_target(footnote, footnote)
                self.autofootnote_labels.append(label)
        return startnum
Exemplo n.º 10
0
 def make_footnote(doc, label, uri):
     """Create a footnote node with children"""
     footnote = nodes.footnote(uri)
     para = nodes.paragraph()
     para.append(nodes.Text(uri))
     footnote.append(para)
     footnote.insert(0, nodes.label('', label))
     doc.note_autofootnote(footnote)
     return footnote
Exemplo n.º 11
0
 def make_footnote(doc, label, uri):
     """Create a footnote node with children"""
     footnote = nodes.footnote(uri)
     para = nodes.paragraph()
     para.append(nodes.Text(uri))
     footnote.append(para)
     footnote.insert(0, nodes.label('', label))
     doc.note_autofootnote(footnote)
     return footnote
Exemplo n.º 12
0
    def visit_footnote(self, node):
        # Handle case where footnote consists only of math
        if len(node.astext().split()) < 2:
            node.append(nodes.label(text='_abcdefghijklmno_'))

        # Work-around for a bug in docutils where
        # "%" is prepended to footnote text
        LaTeXTranslator.visit_footnote(self, node)
        self.out[-1] = self.out[1].strip('%')

        self.non_breaking_paragraph = True
Exemplo n.º 13
0
    def visit_footnote(self, node):
        # Handle case where footnote consists only of math
        if len(node.astext().split()) < 2:
            node.append(nodes.label(text='_abcdefghijklmno_'))

        # Work-around for a bug in docutils where
        # "%" is prepended to footnote text
        LaTeXTranslator.visit_footnote(self, node)
        self.out[-1] = self.out[1].strip('%')

        self.non_breaking_paragraph = True
Exemplo n.º 14
0
    def create_footnote(self, uri: str, docname: str) -> Tuple[nodes.footnote, nodes.footnote_reference]:  # NOQA
        reference = nodes.reference('', nodes.Text(uri), refuri=uri, nolinkurl=True)
        footnote = nodes.footnote(uri, auto=1, docname=docname)
        footnote['names'].append('#')
        footnote += nodes.label('', '#')
        footnote += nodes.paragraph('', '', reference)
        self.document.note_autofootnote(footnote)

        footnote_ref = nodes.footnote_reference('[#]_', auto=1,
                                                refid=footnote['ids'][0], docname=docname)
        footnote_ref += nodes.Text('#')
        self.document.note_autofootnote_ref(footnote_ref)
        footnote.add_backref(footnote_ref['ids'][0])

        return footnote, footnote_ref
Exemplo n.º 15
0
    def render_footnote_reference_open(self, token: NestedTokens):
        target = token.meta["label"]

        footnote = nodes.footnote()
        self.add_line_and_source_path(footnote, token)
        footnote["names"].append(target)
        if not target.isdigit():
            footnote["auto"] = 1
            self.document.note_autofootnote(footnote)
        else:
            footnote += nodes.label("", target)
            self.document.note_footnote(footnote)
        self.document.note_explicit_target(footnote, footnote)
        with self.current_node_context(footnote, append=True):
            self.render_children(token)
Exemplo n.º 16
0
    def create_footnote(self, uri, docname):
        # type: (str, str) -> Tuple[nodes.footnote, nodes.footnote_reference]
        reference = nodes.reference('', nodes.Text(uri), refuri=uri, nolinkurl=True)
        footnote = nodes.footnote(uri, auto=1, docname=docname)
        footnote['names'].append('#')
        footnote += nodes.label('', '#')
        footnote += nodes.paragraph('', '', reference)
        self.document.note_autofootnote(footnote)

        footnote_ref = nodes.footnote_reference('[#]_', auto=1,
                                                refid=footnote['ids'][0], docname=docname)
        footnote_ref += nodes.Text('#')
        self.document.note_autofootnote_ref(footnote_ref)
        footnote.add_backref(footnote_ref['ids'][0])

        return footnote, footnote_ref
Exemplo n.º 17
0
    def create_footnote(self, uri, docname):
        # type: (unicode, unicode) -> Tuple[nodes.footnote, nodes.footnote_ref]
        label = nodes.label('', '#')
        para = nodes.paragraph()
        para.append(nodes.reference('', nodes.Text(uri), refuri=uri, nolinkurl=True))
        footnote = nodes.footnote(uri, label, para, auto=1, docname=docname)
        footnote['names'].append('#')
        self.document.note_autofootnote(footnote)

        label = nodes.Text('#')
        footnote_ref = nodes.footnote_reference('[#]_', label, auto=1,
                                                refid=footnote['ids'][0], docname=docname)
        self.document.note_autofootnote_ref(footnote_ref)
        footnote.add_backref(footnote_ref['ids'][0])

        return footnote, footnote_ref
Exemplo n.º 18
0
def issue_role(name, rawtext, text, line, inliner, options={}, content=[]):
    "generate link to an issue"
    #NOTE:
    #   name - role name in doc, should be 'issue'
    #   rawtext - text of entire node
    #   text - contents of role
    #   lineno
    #   inliner - ???
    #   options - ???
    #   content - ???
    # returns (nodes, messages)

    # extract title & issue number from text
    m = issue_re.match(text)
    if m:
        issue = int(m.group("issue1") or m.group("issue2"))
        title = m.group("title")
    else:
        return make_error(inliner, rawtext, line,
                          "Invalid issue identifier: %r" % (text,))

    # get url template from config, resolve aliases
    config = inliner.document.settings.env.app.config
    url_template = get_issue_tracker_url(config)
    title_template = get_issue_tracker_title(config)

    # generate replacement node
    if not title:
        title = title_template.format(issue=issue)
    set_classes(options)
    clist = options.setdefault('classes',[])
    clist.append("issue")
    if url_template:
        url = url_template.format(issue=issue, title=title)
        node = nodes.reference(rawtext, title, refuri=url, **options)
    else:
        node = nodes.label(rawtext, title, **options)
    return [node], []
Exemplo n.º 19
0
 def get_name(self, name):
     name = ":ref:`%s`" % name
     cnode = nodes.Element()  # anonymous container for parsing
     sl = statemachine.StringList([name], source='')
     self.state.nested_parse(sl, self.content_offset, cnode)
     return nodes.label(name, '', *cnode)