示例#1
0
文件: biblist.py 项目: jhill1/stk
  def to_xml(self, prefix='', indent=2):
    if not self.issorted:      self.sort()

    s=''
    for l in self.sortedList:
      if self.keepAbbrevs:
        bib=bibitem.BibItem(self.get_item(l)) # copy the item to resolve_abbrevs
        bib.resolve_abbrevs(self.abbrevDict)
        ss= bib.to_xml(p=prefix,indent=indent)
      else:
        ss= self.get_item(l).to_xml(p=prefix,indent=indent)
      
      s+= '%s' %(ss)
    return s
示例#2
0
文件: biblist.py 项目: jhill1/stk
  def to_latex(self,style={}):
    if not self.issorted:
      self.sort()

    s=''
    for l in self.sortedList:
      if self.keepAbbrevs:
        bib=bibitem.BibItem(self.get_item(l)) # copy the item to resolve_abbrevs
        bib.resolve_abbrevs(self.abbrevDict)
        ss= bib.to_latex(style)
      else:
        ss= self.get_item(l).to_latex(style)
      s+= '%s %s\n' %(r'\item',ss)
    return s
示例#3
0
文件: biblist.py 项目: jhill1/stk
  def to_html(self,style={}):
    if not self.issorted:
      self.sort()

    s=''
    for l in self.sortedList:
      tipo= self.get_item(l).get_field('_type','article')

      if self.keepAbbrevs:
        bib= bibitem.BibItem(self.get_item(l)) # copy the item to resolve_abbrevs
        bib.resolve_abbrevs(self.abbrevDict)
        ss= bib.to_html(style)
      else:
        ss= self.get_item(l).to_html(style)
      s+= '<li class="%s"> %s </li>\n' %(tipo, ss)
    return s
示例#4
0
文件: biblist.py 项目: jhill1/stk
  def add_item(self, bib, key=None):
    be= bibitem.BibItem(bib,key)
    key= be.get_key()
    if key == None:
      sys.stderr.write('%s\nENTRY FAILED TO IMPORT: %s\n%s%s\n'%(80*'*',bib.get_field('_code',''),bib,80*'*'))
      return False

    if key in self.ListItems:
      if key == self.get_item(key).get_field('_code'): 
        sys.stderr.write('W: ENTRY ALREADY PRESENT: %s (%s)\n'%(key,bib['_code']))
        return False
      else:
        key = be.get_field('_code')

    self.bib[key]= be
    self.ListItems.append(key)
    self.sortedList.append(key)
    self.issorted=False
    return True
示例#5
0
文件: biblist.py 项目: jhill1/stk
  def import_bibtex(self, fname=None, normalize=True, ReplaceAbbrevs=True):
    """
    Import a bibliography (set of items) from a file
    If normalize the code (citekey) is overwritten with a standard key following our criteria
    """
    ncount=0
    st,db= bibitem.bibparse.parsefile(fname)

    if st != []:
      for k,v in st.iteritems():
        self.insertAbbrev(k, v)

    self.keepAbbrevs = not ReplaceAbbrevs
    if db != None:
      for k,v in db.iteritems():
        b1= bibitem.BibItem(bibitem.bibparse.replace_abbrevs(self.abbrevDict,dict(v)), normalize = normalize)
        key= b1.get_key()               # The key is generated
        if self.keepAbbrevs:  status= self.add_item(v, key)
        else:                 status= self.add_item(b1,key)
        if status:
          ncount+= 1
          if normalize:   self.get_item(key).normalize() # _code is put equal to key
    self.sort()
    return ncount