示例#1
0
def read_bibliography(span_iter):
    for is_break, p_spans in itertools.groupby(span_iter, lambda span: "break" in span.styles):
        if not is_break:
            p_spans = list(p_spans)
            p_text = "".join(span.text for span in p_spans)
            logger.debug("Parsing reference: %s", p_text)
            references = list(crossref_lookup(p_text))
            if len(references):
                # consider the paragraphs consumed
                for span in p_spans:
                    span.text = u""
                logger.debug("resolved bibliography_p: %s -> %s", p_text, references)
            else:
                logger.debug("could not parse reference string: %s", p_text)

            for reference in references:
                yield reference
示例#2
0
def parsebib(parser):
    opts = parser.parse_args()
    logger = logging.getLogger(__name__)

    from xdoc.bibliography import crossref_lookup
    from xdoc.formats.tex import serialize_reference

    input = sys.stdin if (opts.input == '-') else open(opts.input)
    output = sys.stdout if (opts.output == '-') else open(opts.output)

    for line in input:
        line = line.strip().decode('utf8')
        logger.info('Resolving "%s" via CrossRef API', line)

        for bibitem in crossref_lookup(line):
            print >> output, serialize_reference(bibitem)
            break
        else:
            logger.error('FIXME: could not parse bib item: %s', line)