示例#1
0
      # This citation is outside of parentheses.
        # Change "&" to "and".
        cite = cite.replace('&', 'and')
        # Put the date in parentheses.
        cite = re.sub(r', ([^,]+)\Z', r' (\1)', cite)
    return '[[bib{}:{}][{}]]{}'.format(
        mo.group(1),
        mo.group(2).lower(),
          # The lower() is needed because quickbib coerces IDs to lowercase.
        cite,
        ' ' if mo.group(3) else '')
org = re.sub(r"\[\[bib(p?):([^\]]+)\]\]( |' |'s )?", f, org)

# Make the bibliography

ref_org = ("\n* References\n:PROPERTIES:\n:CUSTOM_ID: bibliography\n:END:\n" +
    '\n\n'.join(
        '<<{}>> {} @@html:{}@@'.format(
                encode_bibref(key), digest_citation(c), citematic_coins.coins(database[key]))
            for key, c in zip(ids, bibl)) +
    '\n\n')

# If there's a section for footnotes, put ref_org before that.
# Otherwise, put it at the end of the document.

chunks = re.split(r'^(\* .+)', org, flags = re.MULTILINE)
if len(chunks) >= 2 and chunks[-2] == '* Notes':
    print(''.join(chunks[:-2]) + ref_org + chunks[-2] + chunks[-1])
else:
    print(org + ref_org)
示例#2
0
#!/usr/bin/env python3

from sys import stderr
from os import environ
import yaml, cgi
from citematic_coins import coins

bib_path = environ['DAYLIGHT_BIB_PATH']

with open(bib_path) as o:
    database = yaml.load(o)

print('''<!DOCTYPE html>

<html lang="en-US">
<head>
   <meta charset="UTF-8">
   <title>Bibliography in COinS</title>   
</head>

<body>''')
for n, x in enumerate(database):
    print('{} of {} ({})…'.format(n + 1, len(database), x['KEY']), file = stderr)
    print('<p>{}: {}\n'.format(cgi.escape(x['KEY']), coins(x['csl'])))
print('</body></html>')