Exemplo n.º 1
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
Exemplo n.º 2
0
 def make_footnote_ref(doc, label):
     # type: (nodes.Node, unicode) -> nodes.footnote_reference
     """Create a footnote_reference node with children"""
     footnote_ref = nodes.footnote_reference('[#]_')
     footnote_ref.append(nodes.Text(label))
     doc.note_autofootnote_ref(footnote_ref)
     return footnote_ref
Exemplo n.º 3
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
Exemplo n.º 4
0
 def make_footnote_ref(doc: nodes.document,
                       label: str) -> nodes.footnote_reference:
     """Create a footnote_reference node with children"""
     footnote_ref = nodes.footnote_reference('[#]_')
     footnote_ref.append(nodes.Text(label))
     doc.note_autofootnote_ref(footnote_ref)
     return footnote_ref
Exemplo n.º 5
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
Exemplo n.º 6
0
 def make_footnote_ref(doc, label):
     # type: (nodes.document, unicode) -> nodes.footnote_reference
     """Create a footnote_reference node with children"""
     footnote_ref = nodes.footnote_reference('[#]_')
     footnote_ref.append(nodes.Text(label))
     doc.note_autofootnote_ref(footnote_ref)
     return footnote_ref
 def footnote_reference(self, match: Match, lineno: int) -> DispatchResult:
     """Handles footnote/citation references, e.g. [1]_"""
     label = match.group("footnotelabel")
     refname = normalize_name(label)
     string = match.string
     before = string[: match.start("whole")]
     remaining = string[match.end("whole") :]
     if match.group("citationlabel"):
         refnode = nodes.citation_reference(f"[{label}]_", refname=refname)
         refnode += nodes.Text(label)
         self.document.note_citation_ref(refnode)
     else:
         refnode = nodes.footnote_reference(f"[{label}]_")
         if refname[0] == "#":
             refname = refname[1:]
             refnode["auto"] = 1
             self.document.note_autofootnote_ref(refnode)
         elif refname == "*":
             refname = ""
             refnode["auto"] = "*"
             self.document.note_symbol_footnote_ref(refnode)
         else:
             refnode += nodes.Text(label)
         if refname:
             refnode["refname"] = refname
             self.document.note_footnote_ref(refnode)
         if get_trim_footnote_ref_space(self.document.settings):
             before = before.rstrip()
     return (before, [refnode], remaining, [])
Exemplo n.º 8
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
Exemplo n.º 9
0
 def render_foot_reference(self, token):
     """Footnote references are added as auto-numbered,
     .i.e. `[^a]` is read as rST `[#a]_`
     """
     refnode = nodes.footnote_reference("[^{}]".format(token.target))
     self.add_line_and_source_path(refnode, token)
     refnode["auto"] = 1
     refnode["refname"] = token.target
     # refnode += nodes.Text(token.target)
     self.document.note_autofootnote_ref(refnode)
     self.document.note_footnote_ref(refnode)
     self.current_node.append(refnode)
Exemplo n.º 10
0
 def render_footnote_ref(self, token):
     """Footnote references are added as auto-numbered,
     .i.e. `[^a]` is read as rST `[#a]_`
     """
     # TODO we now also have ^[a] the inline version (currently disabled)
     # that would be rendered here
     target = token.meta["label"]
     refnode = nodes.footnote_reference("[^{}]".format(target))
     self.add_line_and_source_path(refnode, token)
     refnode["auto"] = 1
     refnode["refname"] = target
     # refnode += nodes.Text(token.target)
     self.document.note_autofootnote_ref(refnode)
     self.document.note_footnote_ref(refnode)
     self.current_node.append(refnode)
Exemplo n.º 11
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.º 12
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.º 13
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.º 14
0
    def render_footnote_ref(self, token: Token):
        """Footnote references are added as auto-numbered,
        .i.e. `[^a]` is read as rST `[#a]_`
        """
        target = token.meta["label"]

        refnode = nodes.footnote_reference("[^{}]".format(target))
        self.add_line_and_source_path(refnode, token)
        if not target.isdigit():
            refnode["auto"] = 1
            self.document.note_autofootnote_ref(refnode)
        else:
            refnode += nodes.Text(target)

        refnode["refname"] = target
        self.document.note_footnote_ref(refnode)

        self.current_node.append(refnode)
Exemplo n.º 15
0
def gcite_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
    """ weakcite role definition

        :param name: The role name used in the document.
        :param rawtext: The entire markup snippet, with role.
        :param text: The text marked with the role.
        :param lineno: The line number where rawtext appears in the input.
        :param inliner: The inliner instance that called us.
        :param options: Directive options for customization.
        :param content: The directive content for customization.
    """
    global ftnote_lst
    #<footnote_reference auto="1" ids="id1" refid="proj2">1</footnote_reference>

    ftnote_lst.append(text)
    ftnote_idx = len(ftnote_lst)
    ftnote_ref = nodes.footnote_reference( \
        text=str(ftnote_idx),
        auto="1",
        ids="id%d" % ftnote_idx,
        refid=text)

    return [ftnote_pxref(inliner.document, text), ftnote_ref], []
Exemplo n.º 16
0
 def make_footnote_ref(doc, label):
     """Create a footnote_reference node with children"""
     footnote_ref = nodes.footnote_reference("[#]_")
     footnote_ref.append(nodes.Text(label))
     doc.note_autofootnote_ref(footnote_ref)
     return footnote_ref