Skip to content

Commit

Permalink
fix: Check first line for bib entry too
Browse files Browse the repository at this point in the history
This commit fixes a previously-unnoticed issue in which a citation key
occurring on the first line of a bib file could not be identified.
  • Loading branch information
jakewvincent committed Aug 25, 2024
1 parent 683c358 commit 4638b05
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lua/mkdnflow/bib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,13 @@ local search_bib_file = function(path, citekey)
if bib_file then
local text = bib_file:read('*a')
if text then
local start, _ = string.find(text, '\n%s?@[%a]-{%s?' .. utils.luaEscape(citekey))
-- Check first at the beginning of the file text; then at the beginning of each line
local start, _ = string.find(text, "^%s?@[%a]-{%s?" .. utils.luaEscape(citekey))
if not start then
start, _ = string.find(text, '\n%s?@[%a]-{%s?' .. utils.luaEscape(citekey))
end

-- If we have a match, get the entry based on bracket matching
if start then
local match = text:match('%b{}', start)
return match
Expand Down

0 comments on commit 4638b05

Please sign in to comment.