Пример #1
0
 def make_target_footnote(self, target, refs, notes):
     refuri = target['refuri']
     if notes.has_key(refuri):  # duplicate?
         footnote = notes[refuri]
         footnote_name = footnote['name']
     else:                           # original
         footnote = nodes.footnote()
         footnote_id = self.document.set_id(footnote)
         # Use a colon; they can't be produced inside names by the parser:
         footnote_name = 'target_note: ' + footnote_id
         footnote['auto'] = 1
         footnote['name'] = footnote_name
         footnote_paragraph = nodes.paragraph()
         footnote_paragraph += nodes.reference('', refuri, refuri=refuri)
         footnote += footnote_paragraph
         self.document.note_autofootnote(footnote)
         self.document.note_explicit_target(footnote, footnote)
     for ref in refs:
         if isinstance(ref, nodes.target):
             continue
         refnode = nodes.footnote_reference(
             refname=footnote_name, auto=1)
         self.document.note_autofootnote_ref(refnode)
         self.document.note_footnote_ref(refnode)
         index = ref.parent.index(ref) + 1
         reflist = [refnode]
         if not self.document.settings.trim_footnote_reference_space:
             reflist.insert(0, nodes.Text(' '))
         ref.parent.insert(index, reflist)
     return footnote
Пример #2
0
 def make_target_footnote(self, refuri, refs, notes):
     if refuri in notes:  # duplicate?
         footnote = notes[refuri]
         assert len(footnote['names']) == 1
         footnote_name = footnote['names'][0]
     else:                           # original
         footnote = nodes.footnote()
         footnote_id = self.document.set_id(footnote)
         # Use uppercase letters and a colon; they can't be
         # produced inside names by the parser.
         footnote_name = 'TARGET_NOTE: ' + footnote_id
         footnote['auto'] = 1
         footnote['names'] = [footnote_name]
         footnote_paragraph = nodes.paragraph()
         footnote_paragraph += nodes.reference('', refuri, refuri=refuri)
         footnote += footnote_paragraph
         self.document.note_autofootnote(footnote)
         self.document.note_explicit_target(footnote, footnote)
     for ref in refs:
         if isinstance(ref, nodes.target):
             continue
         refnode = nodes.footnote_reference(refname=footnote_name, auto=1)
         refnode['classes'] += self.classes
         self.document.note_autofootnote_ref(refnode)
         self.document.note_footnote_ref(refnode)
         index = ref.parent.index(ref) + 1
         reflist = [refnode]
         if not utils.get_trim_footnote_ref_space(self.document.settings):
             if self.classes:
                 reflist.insert(0, nodes.inline(text=' ', Classes=self.classes))
             else:
                 reflist.insert(0, nodes.Text(' '))
         ref.parent.insert(index, reflist)
     return footnote
Пример #3
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
Пример #4
0
 def make_footnote(doc: nodes.document, label: str, uri: str) -> nodes.footnote:
     """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
Пример #5
0
 def render_footnote_reference_open(self, token):
     target = token.meta["label"]
     footnote = nodes.footnote()
     self.add_line_and_source_path(footnote, token)
     footnote["names"].append(target)
     footnote["auto"] = 1
     self.document.note_autofootnote(footnote)
     self.document.note_explicit_target(footnote, footnote)
     with self.current_node_context(footnote, append=True):
         self.render_children(token)
Пример #6
0
 def make_footnote(doc, label, uri):
     # type: (nodes.document, unicode, unicode) -> nodes.footnote
     """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
Пример #7
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
Пример #8
0
    def render_footnote_reference(self, token: SyntaxTreeNode) -> None:
        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)
Пример #9
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
Пример #10
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
Пример #11
0
 def render_footnote(self, token: block_tokens_ext.Footnote):
     footnote = nodes.footnote()
     self.add_line_and_source_path(footnote, token)
     # footnote += nodes.label('', token.target)
     footnote["names"].append(token.target)
     footnote["auto"] = 1
     self.document.note_autofootnote(footnote)
     self.document.note_explicit_target(footnote, footnote)
     # TODO for now we wrap the content (which are list of spans tokens)
     # in a paragraph, but eventually upstream in mistletoe this will already be
     # block level tokens
     self.current_node.append(footnote)
     paragraph = nodes.paragraph("")
     self.add_line_and_source_path(paragraph, token)
     footnote.append(paragraph)
     with self.current_node_context(paragraph, append=False):
         self.render_children(token)