-
Notifications
You must be signed in to change notification settings - Fork 13
/
bibliorender.jl
43 lines (38 loc) · 1.2 KB
/
bibliorender.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import Bibliography
import BibInternal
function fmt(name::BibInternal.Name)
joined_name = replace(join([name.first, name.middle, name.last], " "), r"(\s+)" => s" ")
return joined_name
end
function fmt(authors::Vector{BibInternal.Name})
if length(authors) >= 3
return fmt(first(authors)) * " *et al.*"
else
return join(fmt.(authors), ", ", " & ")
end
end
function fmt(access::BibInternal.Access)
if ~isempty(access.doi)
return "[`$(access.doi)`](https://doi.org/$(access.doi))"
elseif ~isempty(access.url)
return "[URL]($(access.url))"
end
return ""
end
function fmt(pubedin::BibInternal.In)
if isempty(pubedin.journal)
return "*$(pubedin.publisher)*"
else
return "*$(pubedin.journal)* $(pubedin.volume)($(pubedin.number)) $(pubedin.pages)"
end
end
function fmt(entry::BibInternal.Entry)
auth = fmt(entry.authors)
title = "\"$(entry.title)\""
link = fmt(entry.access)
pubedin = fmt(entry.in)
bib_string = "$(auth) ($(entry.date.year)). $(title); $(pubedin)\n$(link)"
bib_string = replace(bib_string, "{\\c{c}}" => "ç")
bib_string = replace(bib_string, r"{(\w+)}" => s"\1")
return bib_string
end