Skip to content

Commit

Permalink
Handle SpecRef aliases.
Browse files Browse the repository at this point in the history
  • Loading branch information
tabatkins committed Apr 24, 2015
1 parent 0731245 commit 9ef9fdb
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions bikeshed/biblio.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import division, unicode_literals
import re
import copy
from collections import defaultdict, deque
from .messages import *
from .htmlhelpers import *
Expand Down Expand Up @@ -206,10 +207,17 @@ def processSpecrefBiblioFile(text, storage, order):
# Required BiblioEntry fields
requiredFields = ["url", "title"]

aliases = {}
for biblioKey, data in datas.items():
if isinstance(data, basestring):
# Need to handle the preformatted string entries eventually
continue
if "aliasOf" in data:
if biblioKey.lower() != data["aliasOf"].lower():
# SpecRef uses aliases to handle capitalization differences,
# which I don't care about.
aliases[biblioKey] = data["aliasOf"]
continue
biblio = {"linkText": biblioKey, "order": order}
for jsonField, biblioField in fields.items():
if jsonField in data:
Expand All @@ -218,6 +226,13 @@ def processSpecrefBiblioFile(text, storage, order):
# Aliases should hit this case, I'll deal with them later
continue
storage[biblioKey.lower()].append(biblio)
for biblioKey, aliasOf in aliases.items():
aliasedBiblios = storage.get(aliasOf.lower(), [])
for aliasedBiblio in aliasedBiblios:
copiedBiblio = copy.copy(aliasedBiblio)
copiedBiblio['linkText'] = biblioKey
storage[biblioKey.lower()].append(copiedBiblio)

return storage


Expand Down

0 comments on commit 9ef9fdb

Please sign in to comment.