Skip to content

Commit

Permalink
add import from logseq
Browse files Browse the repository at this point in the history
  • Loading branch information
Nriver committed Jan 6, 2023
1 parent ab1cd95 commit 1e0bdba
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

Python client for ETAPI of Trilium Note.

# Toc
# Table of Contents

<!--ts-->

=================

* [trilium-py](#trilium-py)
* [Toc](#toc)
* [Installation](#installation)
Expand All @@ -28,6 +30,9 @@ Python client for ETAPI of Trilium Note.
* [(Advanced Usage) Upload Markdown files](#advanced-usage-upload-markdown-files)
* [Upload single Markdown file with images](#upload-single-markdown-file-with-images)
* [Bulk upload Markdown files in a folder!](#bulk-upload-markdown-files-in-a-folder)
* [Import from VNote](#import-from-vnote)
* [Import from Logseq](#import-from-logseq)
* [Import from other markdown software](#import-from-other-markdown-software)
* [Develop](#develop)
* [Original OpenAPI Documentation](#original-openapi-documentation)

Expand Down Expand Up @@ -244,6 +249,8 @@ res = ea.upload_md_file(

You can upload a folder with lots of Markdown files to Trilium and preserve the folder structure!

### Import from VNote

Say, upload all the notes from [VNote](https://github.com/vnotex/vnote), simply do this:

```
Expand All @@ -254,6 +261,29 @@ res = ea.upload_md_folder(
)
```

### Import from Logseq

```
res = ea.upload_md_folder(
parentNoteId="root",
mdFolder="/home/nate/data/logseq_data/",
ignoreFolder=['assets', 'logseq'],
)
```

### Import from other markdown software

In general, markdown files have variety of standards. You can always try import them with

```
res = ea.upload_md_folder(
parentNoteId="root",
mdFolder="/home/nate/data/your_markdown_files/",
)
```

If there is any problem, please feel free to create an [issue](https://github.com/Nriver/trilium-py/issues/new).

# Develop

Install with pip egg link to make package change without reinstall.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
# For a discussion on single-sourcing the version across setup.py and the
# project code, see
# https://packaging.python.org/guides/single-sourcing-package-version/
version='0.6.6', # Required
version='0.6.7', # Required

# This is a one-line description or tagline of what your project does. This
# corresponds to the "Summary" metadata field:
Expand Down
7 changes: 6 additions & 1 deletion src/trilium_py/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,11 @@ def upload_md_file(self, file: str, parentNoteId: str):
# convert md to html
with open(md_file, 'r', encoding='utf-8') as f:
content = f.read()

# fix logseq image size format
logseq_image_pat = r'(\!\[.*\]\(.*\))\{.*?:height.*width.*}'
content = re.sub(logseq_image_pat, r'\1', content)

# extra format support
# https://github.com/trentm/python-markdown2/wiki/Extras
html = markdown2.markdown(content, extras=['fenced-code-blocks', 'strike', 'tables', 'task_list'])
Expand Down Expand Up @@ -661,7 +666,7 @@ def upload_md_file(self, file: str, parentNoteId: str):
def upload_md_folder(self, parentNoteId: str, mdFolder: str, includePattern=[],
ignoreFolder=[], ignoreFile=[]):
if not includePattern:
includePattern = ['*md', ]
includePattern = ['.md', ]

# note tree
# record for noteId
Expand Down

0 comments on commit 1e0bdba

Please sign in to comment.