-
Notifications
You must be signed in to change notification settings - Fork 249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed small bug in note.from_lines #67
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @s-cassidy! Just one minor suggestion
lua/obsidian/note.lua
Outdated
@@ -209,6 +209,9 @@ note.from_lines = function(lines, path, root) | |||
if #frontmatter_lines > 0 then | |||
local frontmatter = table.concat(frontmatter_lines, "\n") | |||
local ok, data = pcall(yaml.loads, frontmatter) | |||
if type(data) == 'string' then | |||
data = {data = nil} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about just this:
data = {data = nil} | |
data = {} |
That's my poor Lua knowledge showing me up as I didn't realize nil table entries effectively don't exist. I've made the change if you want to just go with it. However, this is closer to what I was thinking
This way the following code still gets the name of the empty field (with trailing whitespace and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, LGTM
If a note had frontmatter consisting of exactly one empty field,
yaml.loads
would return that field as a string rather than a table, causing an exception innote.from_lines
.