예제 #1
0
def latex_to_nodes(text):
  """
  Convert '_{}' and '^{}' text to node representation.
  TODO: This doesn't work yet
  """
  return nodes.inline(text, text)
  m = SUBSUP_RE.findall(text)
  if m:
    n += latex_to_nodes(m[0][0])
    if m[0][1] == '^':
      n += nodes.superscript(latex_to_nodes(m[0][2]))
    elif m[0][1] == '_':
      n += nodes.subscript(latex_to_nodes(m[0][2]))
  else:
    n = nodes.inline(text, text)
  return n
예제 #2
0
 def superscript_children(self, target):
     """
     Yield the children of `target` in order, removing
     parenthesized sense numbers like "(1)" and "(2)" from text
     nodes, and adding new superscript nodes as necessary.
     """
     for e in target:
         if not isinstance(e, nodes.Text):
             yield e
             continue
         m = self.sense_re.match(e)
         if not m:
             yield e
             continue
         yield nodes.Text(m.group(1))
         yield nodes.superscript(text=m.group(2))
예제 #3
0
    def run(self):
        """
    Generate the definition list that displays the actual references.
    """
        env = self.state.document.settings.env
        keys = env.domaindata["cite"]["keys"]
        env.domaindata["cite"]["refdoc"] = env.docname

        citations = env.domains["cite"].citations

        # TODO: implement
        # env.domaindata['cite']['refdocs'][env.docname] = Citations(env, path)

        # Build the references list
        # TODO: Make this an enumerated_list or field_list maybe?
        node = nodes.definition_list()
        node.document = self.state.document
        node["classes"].append("references")

        items = []
        for i, key in enumerate(keys):
            term = nodes.term("", "")

            # TODO: Allow the format of the reference list be configurable
            if env.domaindata["cite"]["conf"]["style"] == "super":
                term.children = [nodes.superscript("", i + 1)]
            else:
                term.children = [nodes.inline("", "%s) " % (i + 1))]

            nid = "citation-%s" % nodes.make_id(key)
            definition = self.get_reference_node(citations.get(key))

            li = nodes.definition_list_item("", term, definition)
            li[0]["ids"].append(nid)
            li[0]["names"].append(nid)
            items.append(li)
        node.extend(item for item in items)

        return [node]
예제 #4
0
 def cite(self, cmd, refuri, global_keys=None):
   """
   Return a docutils Node consisting of properly formatted citations children
   nodes.
   """
   if global_keys is not None:
       self.global_keys = global_keys
   bo, bc = self.config['brackets']
   sep = u'%s ' % self.config['separator']
   style = self.config['style']
   all_auths = (cmd.endswith('s'))
   alt = (cmd.startswith('alt') or \
               (cmd.startswith('alp')) or \
               (style == 'citeyear'))
   
   if (cmd.startswith('p') or cmd == 'yearpar') and style != 'super':
     node = nodes.inline(bo, bo, classes=['citation'])
   else:
     node = nodes.inline('', '', classes=['citation'])
   
   if self.pre:
     pre = u"%s " % self.pre.decode('latex')
     node += nodes.inline(pre, pre, classes=['pre'])
   
   for i, ref in enumerate(self.refs):
     authors = ref.persons.get('author', [])
     author_text = self.get_author(authors, all_auths).decode('latex')
     lrefuri = refuri + '#citation-' + nodes.make_id(ref.key)
     
     if i > 0 and i < len(self.refs):
       if style == "authoryear":
         node += nodes.inline(sep, sep)
       else:
         if style == "super":
           node += nodes.superscript(', ', ', ')
         else:
           node += nodes.inline(', ', ', ')
     
     if cmd == 'title':
         title = ref.fields.get('title')
         if title is None:
             title = ref.fields.get('key', '')
         author_text = title
     
     if (style == "authoryear" and (cmd.startswith('p') or cmd.startswith('alp'))) or \
        (cmd.startswith('t') or cmd.startswith('alt') or cmd.startswith('author')):
       node += nodes.reference(author_text, author_text, internal=True, refuri=lrefuri)
       
       if cmd.startswith('p') or cmd.startswith('alp'):
         node += nodes.inline(', ', ', ')
       else:
         node += nodes.inline(' ', ' ')
     
     # Add in either the year or the citation number
     if cmd == 'title':
         pass
     elif cmd.startswith('author'):
         pass
     else:
       if style != 'authoryear':
         num = self.get_ref_num(ref.key)
       else:
         num = ref.fields.get('year')
     
       refnode = nodes.reference(str(num), str(num), internal=True, refuri=lrefuri)
     
       if cmd.startswith('t') and style != 'super':
         node += nodes.inline(bo, bo)
       
       if style == 'super':
         node += nodes.superscript('', '', refnode)
       else:
         node += refnode
     
       if cmd.startswith('t') and style != 'super':
         node += nodes.inline(bc, bc)
   
   if self.post:
     post = u", %s" % self.post.decode('latex')
     node += nodes.inline(post, post, classes=['post'])  
   
   if (cmd.startswith('p') or cmd == 'yearpar') and style != 'super':
     node += nodes.inline(bc, bc, classes=['citation'])
   
   return node
예제 #5
0
    def cite(self, cmd, refuri):
        """
    Return a docutils Node consisting of properly formatted citations children
    nodes.
    """
        bo, bc = self.config["brackets"]
        sep = u"%s " % self.config["separator"]
        style = self.config["style"]
        all_auths = cmd.endswith("s")
        alt = cmd.startswith("alt") or (cmd.startswith("alp")) or (style == "citeyear")

        if (cmd.startswith("p") or cmd == "yearpar") and style != "super":
            node = nodes.inline(bo, bo, classes=["citation"])
        else:
            node = nodes.inline("", "", classes=["citation"])

        if self.pre:
            pre = u"%s " % self.pre.decode("latex")
            node += nodes.inline(pre, pre, classes=["pre"])

        for i, ref in enumerate(self.refs):
            authors = ref.persons.get("author", [])
            author_text = self.get_author(authors, all_auths).decode("latex")
            lrefuri = refuri + "#citation-" + nodes.make_id(ref.key)

            if i > 0 and i < len(self.refs):
                if style == "authoryear":
                    node += nodes.inline(sep, sep)
                else:
                    if style == "super":
                        node += nodes.superscript(", ", ", ")
                    else:
                        node += nodes.inline(", ", ", ")

            if (style == "authoryear" and (cmd.startswith("p") or cmd.startswith("alp"))) or (
                cmd.startswith("t") or cmd.startswith("alt") or cmd.startswith("author")
            ):
                node += nodes.reference(author_text, author_text, internal=True, refuri=lrefuri)

                if cmd.startswith("p") or cmd.startswith("alp"):
                    node += nodes.inline(", ", ", ")
                else:
                    node += nodes.inline(" ", " ")

            # Add in either the year or the citation number
            if not cmd.startswith("author"):
                if style != "authoryear":
                    num = self.get_ref_num(ref.key)
                else:
                    num = ref.fields.get("year")

                refnode = nodes.reference(str(num), str(num), internal=True, refuri=lrefuri)

                if cmd.startswith("t") and style != "super":
                    node += nodes.inline(bo, bo)

                if style == "super":
                    node += nodes.superscript("", "", refnode)
                else:
                    node += refnode

                if cmd.startswith("t") and style != "super":
                    node += nodes.inline(bc, bc)

        if self.post:
            post = u", %s" % self.post.decode("latex")
            node += nodes.inline(post, post, classes=["post"])

        if (cmd.startswith("p") or cmd == "yearpar") and style != "super":
            node += nodes.inline(bc, bc, classes=["citation"])

        return node
예제 #6
0
  def cite(self, cmd, refuri):
    """ Return a docutils Node consisting of properly formatted citations children
    nodes.                Brent edit: replaced 'inline' with 'generated' """
    bo, bc    = self.config['brackets']
    sep       = '%s ' % self.config['separator']
    style     = self.config['style']
    all_auths = (cmd.endswith('s'))
    alt       = (cmd.startswith('alt') or \
                (cmd.startswith('alp')) or \
                (style == 'citeyear'))

    if (cmd.startswith('p') or cmd == 'yearpar') and style != 'super':
      #node = nodes.inline(bo, bo, classes=['citation'])
      node = nodes.generated(bo, bo, classes=['citation'])
    else:
      #node = nodes.inline('', '', classes=['citation'])
      node = nodes.generated('', '', classes=['citation'])

    if self.pre:
      pre="%s ".format(decod(self.pre))
      #node += nodes.inline(pre, pre, classes=['pre'])
      node += nodes.generated(pre, pre, classes=['pre'])

    for i, ref in enumerate(self.refs):
      authors = ref.persons.get('author', [])
      author_text = decod(self.get_author(authors, all_auths))
      lrefuri = refuri + '#citation-' + nodes.make_id(ref.key)

      if i > 0 and i < len(self.refs):
        if style == "authoryear":
          #node += nodes.inline(sep, sep)
          node += nodes.generated(sep, sep)
        else:
          if style == "super": node+=nodes.superscript(', ',', ')
          else:
            #node += nodes.inline(', ', ', ')
            node += nodes.generated(', ', ', ')

      if (style == "authoryear" and (cmd.startswith('p') or cmd.startswith('alp'))) or \
         (cmd.startswith('t') or cmd.startswith('alt') or cmd.startswith('author')):
        node+=nodes.reference(author_text,author_text,internal=True,refuri=lrefuri)

        if cmd.startswith('p') or cmd.startswith('alp'):
          #node+=nodes.inline(', ',', ')
          node+=nodes.generated(', ',', ')
        else:
          #node+=nodes.inline(' ',' ')
          node+=nodes.generated(' ',' ')

      # Add in either the year or the citation number
      if not cmd.startswith('author'):
        if style != 'authoryear':
          num = self.get_ref_num(ref.key)
        else:
          num = ref.fields.get('year')
      
        refnode = nodes.reference(str(num), str(num), internal=True, refuri=lrefuri)
      
        if cmd.startswith('t') and style != 'super':
          #node += nodes.inline(bo, bo)
          node += nodes.generated(bo, bo)
        
        if style == 'super':
          node += nodes.superscript('', '', refnode)
        else:
          node += refnode
      
        if cmd.startswith('t') and style != 'super':
          #node += nodes.inline(bc, bc)
          node += nodes.generated(bc, bc)
    
    if self.post:
      post=", %s".format(decod(self.post))
      #node += nodes.inline(post, post, classes=['post'])  
      node += nodes.generated(post, post, classes=['post'])  
    
    if (cmd.startswith('p') or cmd == 'yearpar') and style != 'super':
      #node += nodes.inline(bc, bc, classes=['citation'])
      node += nodes.generated(bc, bc, classes=['citation'])

    return node
예제 #7
0
    def cite(self, cmd, refuri, global_keys=None):
        """
    Return a docutils Node consisting of properly formatted citations children
    nodes.
    """
        if global_keys is not None:
            self.global_keys = global_keys
        bo, bc = self.config['brackets']
        sep = u'%s ' % self.config['separator']
        style = self.config['style']
        all_auths = (cmd.endswith('s'))
        alt = (cmd.startswith('alt') or \
                    (cmd.startswith('alp')) or \
                    (style == 'citeyear'))

        if (cmd.startswith('p') or cmd == 'yearpar') and style != 'super':
            node = nodes.inline(bo, bo, classes=['citation'])
        else:
            node = nodes.inline('', '', classes=['citation'])

        if self.pre:
            pre = u"%s " % self.pre.decode('latex')
            node += nodes.inline(pre, pre, classes=['pre'])

        for i, ref in enumerate(self.refs):
            authors = ref.persons.get('author', [])
            author_text = self.get_author(authors, all_auths).decode('latex')
            lrefuri = refuri + '#citation-' + nodes.make_id(ref.key)

            if i > 0 and i < len(self.refs):
                if style == "authoryear":
                    node += nodes.inline(sep, sep)
                else:
                    if style == "super":
                        node += nodes.superscript(', ', ', ')
                    else:
                        node += nodes.inline(', ', ', ')

            if cmd == 'title':
                title = ref.fields.get('title')
                if title is None:
                    title = ref.fields.get('key', '')
                author_text = title

            if (style == "authoryear" and (cmd.startswith('p') or cmd.startswith('alp'))) or \
               (cmd.startswith('t') or cmd.startswith('alt') or cmd.startswith('author')):
                node += nodes.reference(author_text,
                                        author_text,
                                        internal=True,
                                        refuri=lrefuri)

                if cmd.startswith('p') or cmd.startswith('alp'):
                    node += nodes.inline(', ', ', ')
                else:
                    node += nodes.inline(' ', ' ')

            # Add in either the year or the citation number
            if cmd == 'title':
                pass
            elif cmd.startswith('author'):
                pass
            else:
                if style != 'authoryear':
                    num = self.get_ref_num(ref.key)
                else:
                    num = ref.fields.get('year')

                refnode = nodes.reference(str(num),
                                          str(num),
                                          internal=True,
                                          refuri=lrefuri)

                if cmd.startswith('t') and style != 'super':
                    node += nodes.inline(bo, bo)

                if style == 'super':
                    node += nodes.superscript('', '', refnode)
                else:
                    node += refnode

                if cmd.startswith('t') and style != 'super':
                    node += nodes.inline(bc, bc)

        if self.post:
            post = u", %s" % self.post.decode('latex')
            node += nodes.inline(post, post, classes=['post'])

        if (cmd.startswith('p') or cmd == 'yearpar') and style != 'super':
            node += nodes.inline(bc, bc, classes=['citation'])

        return node
예제 #8
0
파일: xroles.py 프로젝트: xcore/xdoc
def superscript(role, rawtext, text, lineno, inliner, options={}, content={}):
    sup = nodes.superscript()
    sup += miniparse(text)
    return [sup],[]
 def visit_sup(self, node):
     sup = nodes.superscript()
     ids = node.attrib.get("id", "")
     if ids:
         sup['ids'] = [node.attrib.pop("id")]
     return sup