Skip to content
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

Markdown formatting and line breaks not recognized when creating notes #168

Open
9j7axvsLuF opened this issue Oct 5, 2023 · 3 comments
Open
Assignees

Comments

@9j7axvsLuF
Copy link

9j7axvsLuF commented Oct 5, 2023

When creating notes using pyzotero, the markdown formatting isn't being recognized. I've followed the documentation closely, but the created notes show markdown characters (such as #) instead of rendering them as intended, and collapse line breaks (\n) into whitespaces.

Here's a simplified Python code snippet to demonstrate the issue:

from pyzotero import zotero

# Initialize Zotero API
library_id = "your_library_id"
api_key = "your_api_key"
zot = zotero.Zotero(library_id, "user", api_key)

# Retrieve a sample item
sample_item = zot.top()[0]

# Create a note with markdown formatting
note_template = zot.item_template('note')
note_template['note'] = "# Note Title\n\nThis is a note."
zot.create_items([note_template], sample_item['key'])

The created note should render the markdown formatting, displaying as follows in Zotero:

Note Title

This is a note.

Instead, this is what I see:

# Note Title This is a note.

When I export the resulting note in markdown, I get this with the hash symbol escaped:

\# Note Title This is a note.

At the very least I would like my created notes to respect line breaks in the content, otherwise the notes are unreadable in Zotero.

Additional Context:

  • Zotero version: 6.0.27
  • pyzotero version: 1.5.10
  • Python version: 3.11.4
  • OS: Windows 11
@9j7axvsLuF
Copy link
Author

I found a (perhaps hacky) solution: converting the content of the note from markdown to html using the markdown package before passing it to Zotero, like so:

note_content = markdown.markdown(note_content)

There might be a better way to do this though!

@urschrei
Copy link
Owner

urschrei commented Oct 5, 2023

It looks like the escaping is being inserted on the server side. Here's the JSON Pyzotero sends in its POST request:

{"itemType": "note", "note": "# Note Title\n\nThis is a note.", "tags": [], "collections": [], "relations": {}}

I'll see whether someone on the Zotero side knows what's going on.

@9j7axvsLuF
Copy link
Author

9j7axvsLuF commented Oct 5, 2023

Thanks for the quick response! In any case the html trick shared above works great. Perhaps there could be args in a future version of pyzotero to automatically handle the markdown-to-html conversion for markdown content, or at least something in the docs to explain how to preserve formatting (unless, of course, Zotero decides to change their API).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants