Skip to content

Fix: exporting Markdown with missing authors doesn't crash anymore #10278

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

Merged
merged 1 commit into from
Apr 28, 2023

Conversation

Mochitto
Copy link
Contributor

@Mochitto Mochitto commented Apr 1, 2023

Solves #10070 and maybe #10072

The previous version would crash due to author missing in the book's metadata.

-- line 38
local function prepareBookContent(book, formatting_options, highlight_formatting)
    [..........]
    content = content .. "##### " .. book.author:gsub("\n", ", ") .. "\n\n"
    [.........]

Added a conditional that sets the book author to a default (Author not found in book's metadata), so that the user can still have a feedback on missing metadata, while successfully exporting their notes.
The fix works both with export one file and export all files.

image


This change is Reviewable

@Mochitto
Copy link
Contributor Author

Mochitto commented Apr 1, 2023

I haven't looked into it, but it might be worth to attribute default values to all of the properties of the entry/book objects so that they still get put in the documents and the user can fill in missing metadata.

I noticed some values are supposed to be ok even if they are missing, but making sure that all values are at least an empty string could avoid crashes depending on types (nil).
Or, if there could be expressive defaults for some things (for example for books metadata, such as authors), the user can have feedback on what metadata is missing.

Would be ok on taking on to myself (Assignees) adding the defaults if you find it a good idea.

@NiLuJe
Copy link
Member

NiLuJe commented Apr 1, 2023

I tend to prefer explicit nil guards to empty string checks, but I can certainly see your point; RFC ;).

@Mochitto
Copy link
Contributor Author

Mochitto commented Apr 1, 2023

@NiLuJe What does RFC mean? :o I agree, explicit is better than implicit!

@NiLuJe
Copy link
Member

NiLuJe commented Apr 1, 2023

Request For Comments ;).

@poire-z
Copy link
Contributor

poire-z commented Apr 1, 2023

What does RFC mean?

just because it's today :) https://en.wikipedia.org/wiki/April_Fools%27_Day_Request_for_Comments

@pazos pazos merged commit 0db042f into koreader:master Apr 28, 2023
@pazos pazos linked an issue Apr 28, 2023 that may be closed by this pull request
@poire-z poire-z added this to the 2023.05 milestone Apr 29, 2023
@Frenzie Frenzie added the Plugin label Apr 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Koreader crashes when sharing highlights to markdown
5 participants