summaryrefslogtreecommitdiff
path: root/biblio/citation-style-language/citeproc-bib.lua
diff options
context:
space:
mode:
Diffstat (limited to 'biblio/citation-style-language/citeproc-bib.lua')
-rw-r--r--biblio/citation-style-language/citeproc-bib.lua27
1 files changed, 10 insertions, 17 deletions
diff --git a/biblio/citation-style-language/citeproc-bib.lua b/biblio/citation-style-language/citeproc-bib.lua
index b99ba955dd..7e24b1a6a5 100644
--- a/biblio/citation-style-language/citeproc-bib.lua
+++ b/biblio/citation-style-language/citeproc-bib.lua
@@ -16,24 +16,12 @@
local bib = {}
-require("lualibs")
local unicode = require("unicode")
+bib.bib_data = require("citeproc-bib-data")
local util = require("citeproc-util")
-local path = "citeproc-bib-data.json"
-if kpse then
- path = kpse.find_file(path)
-end
-if path then
- local contents = util.read_file(path)
- if not contents then
- error(string.format('Failed to find "%s"', path))
- end
- bib.bib_data = utilities.json.tolua(contents)
-end
-
function bib.parse(contents)
local items = {}
for item_contents in string.gmatch(contents, "(@%w+%b{})") do
@@ -80,9 +68,9 @@ end
function bib.parse_fields(contents)
local fields = {}
local field_patterns = {
- "^(%w+)%s*=%s*(%b{}),?%s*(.-)$",
- '^(%w+)%s*=%s*"([^"]*)",?%s*(.-)$',
- "^(%w+)%s*=%s*(%w+),?%s*(.-)$",
+ "^([^,}%s]+)%s*=%s*(%b{}),?%s*(.-)$",
+ '^([^,}%s]+)%s*=%s*"([^"]*)",?%s*(.-)$',
+ "^([^,}%s]+)%s*=%s*(%w+),?%s*(.-)$",
}
while #contents > 0 do
@@ -91,6 +79,7 @@ function bib.parse_fields(contents)
for pattern_index, pattern in ipairs(field_patterns) do
field, value, rest = string.match(contents, pattern)
if value then
+ field = string.lower(field)
if pattern_index == 1 then
-- Strip braces "{}"
value = string.sub(value, 2, -2)
@@ -106,10 +95,14 @@ function bib.parse_fields(contents)
end
end
fields[field] = value
- contents = rest
break
end
end
+ if value then
+ contents = rest
+ else
+ break
+ end
end
return fields
end