Skip to main content

Converts Supernote exports to markdown

Project description

Supernote to Markdown converter (sn2md)

sn2md is a command-line tool to convert Supernote .note files into markdown. It leverages OpenAI GPT-4o to convert images and text from Supernote files into a structured markdown document.

Supernote to Markdown

Sample output: 20240712_151149.md

Features

  • Converts Supernote .note files to markdown.
  • Supports conversion of images to markdown using the Mermaid diagramming tool.
  • Automatically handles math equations using $ and $$ style math blocks.
  • Generates a markdown file and embedded images (custom output supported).

Installation

pip install sn2md

Setup your OPENAI_API_KEY environment variable.

Usage

To import a single Supernote .note file, use the file command:

# import one .note file:
sn2md file <path_to_note_file>

# import a directory of .note files:
sn2md directory <path_to_directory>

Notes:

  • A cache file is also generated, so repeated runs don't recreate the same data. You can force a refresh by running with the --force flag.

Configuration

A configuration file can be used to override the program defaults. The default location is platform specific (eg, ~/Library/Application Support/sn2md.toml on OSX, ~/.config/sn2md.toml on Linux, etc).

Values that you can override:

  • template: The output template to generate markdown.
  • prompt: The prompt sent to the OpenAI API. Requires a {context} placeholder to help the AI understand the context of the previous page.
  • title_prompt: The prompt sent to the OpenAI API to decode any titles (H1-H4 highlights).
  • model: The OpenAI model to use (default: gpt-4o-mini).
  • openai_api_key: Your OpenAI API key (defaults to your $OPENAI_API_KEY environmental variable setting).

Example instructing the AI to convert text to pirate speak:

prompt = """###
Context (what the last couple lines of the previous page were converted to markdown):
{context}
###
Convert the following image to markdown:
- Don't convert diagrams or images. Just output "<IMAGE>" on a newline.
"""

template = """
# Pirate Speak
{{markdown}}
"""

Prompt

The default prompt sent to the OpenAI API is:

###
Context (what the last couple lines of the previous page were converted to markdown):
{context}
###
Convert the following image to markdown:
- If a diagram or image appears on the page, and is a simple diagram that the mermaid diagramming tool can achieve, create a mermaid codeblock of it.
- When it is unclear what an image is, don't output anything for it.
- Assume text is not in a codeblock. Do not wrap any text in codeblocks.
- Use $$, $ style math blocks for math equations.

This can be overridden in the configuration file.

Output Template

You can provide your own jinja template, if you prefer to customize the markdown output. The default template is:

---
created: {{year_month_day}}
tags: supernote
---

{{markdown}}

# Images
{% for image in images %}
- ![{{ image.name }}]({{image.name}})
{%- endfor %}

# Keywords
{% for keyword in keywords %}
- Page {{ keyword.page_number }}: {{ keyword.content }}
{%- endfor %}

# Links
{% for link in links %}
- Page {{ link.page_number }}: {{ link.type }} {{ link.inout }} {{ link.name }}
{%- endfor %}

# Titles
{% for title in titles %}
- Page {{ title.page_number }}: Level {{ title.level }} "{{ title.content }}"
{%- endfor %}

Variables supplied to the template:

  • year_month_day: The date the note was created (eg, 2024-05-12).
  • markdown: The markdown content of the note.
  • images: an array of image objects with the following properties:
    • name: The name of the image file.
    • rel_path: The relative path to the image file to where the file was run from.
    • abs_path: The absolute path to the image file.
  • links: an array of links in or out of the note with the following properties:
    • page_number: The page number the link is on.
    • type: The link type (page, file, web)
    • name: The basename of the link (url, page, web)
    • device_path: The full path of the link
    • inout: The direction of the link (in, out)
  • keywords: an array of keywords with the following properties:
    • page_number: The page number the keyword is on.
    • content: The content of the keyword.
  • titles: an array of titles with the following properties:
    • page_number: The page number the title is on.
    • level: The level of the title (1-4).
    • content: The content of the title. If the area of the title appears to be text, the text, otherwise a description of it.

Contributing

Contributions are welcome. Please open an issue or submit a pull request.

Development

git clone https://github.com/yourusername/supernote-importer.git
cd supernote-importer
poetry install

License

This project is licensed under the AGPL License. See the LICENSE file for details.

Acknowledgements

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sn2md-1.1.0.tar.gz (20.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sn2md-1.1.0-py3-none-any.whl (20.9 kB view details)

Uploaded Python 3

File details

Details for the file sn2md-1.1.0.tar.gz.

File metadata

  • Download URL: sn2md-1.1.0.tar.gz
  • Upload date:
  • Size: 20.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.13.1 Darwin/23.4.0

File hashes

Hashes for sn2md-1.1.0.tar.gz
Algorithm Hash digest
SHA256 508469409f6d66b4886bdf908f6b6369a1e2f6ee0155b8b13d213e64ef0f0e2a
MD5 3f2a180898814ac8131dceb28fa0a18b
BLAKE2b-256 5f3ea4c38358d0534c67001ff46a4560512c144a6be83b3d8228912d877640f7

See more details on using hashes here.

File details

Details for the file sn2md-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: sn2md-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 20.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.13.1 Darwin/23.4.0

File hashes

Hashes for sn2md-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8195afee73079c4804f81484389bf43ebe1cae34c0f595b2396f21951242f429
MD5 91866014dfdb8b43a01591a0b4ca0395
BLAKE2b-256 3ae53c03683e9517f72628810b77e7b9bcd1300eacaf0c2993f28106260803f9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page