JulioLoayzaM / bsimport

A Python tool for importing Markdown files to a Bookstack instance.
https://pypi.org/project/bsimport/
MIT License
4 stars 3 forks source link

Import fails if page is empty #2

Open WillNilges opened 11 months ago

WillNilges commented 11 months ago

(I know this project is unmaintained, I'm just putting this here for others)

Importing will fail with the following message if you try to import an empty file:

Import page failed with: API request error
Debug: {'message': 'The given data was invalid.', 'validation': {'html': ['The html field is required when markdown is not present.'], 'markdown': ['The markdown field is required when html is not present.']}, 'code': 422}
Skipping page '<page>.md'

Perhaps this should include a warning that the page is empty?

JulioLoayzaM commented 10 months ago

Hi @WillNilges,

First of all, thanks for sharing :) it is unmaintained but issues like this are welcome.

I tried importing an empty file created with touch empty.md but couldn't reproduce the issue. Indeed, there's already a check for empty files when trying to import a page.

I did manage to reproduce the issue with an almost empty file created with echo "" > empty.md. In this case, the file actually contains a single linefeed, you can check this with ls -l. This means that file passes the check and is uploaded to Bookstack, which doesn't seem to like a page with just a linefeed.

So I'm not sure if this requires any action. One option could be to strip white space at the end of each line during parsing, and checking if the concatenated text is not empty before calling the API. I'll think about it before closing the issue, I'm open to suggestions. :)