Cobertos / md2notion

A better Notion.so Markdown importer
MIT License
657 stars 66 forks source link

Pass CodeBlock as raw Markdown #4

Closed prurph closed 4 years ago

prurph commented 4 years ago

Awesome library! I seem to be having a small issue with code blocks and indentation:

code = """\
```python
def hello():
    print("World!")
```"""
uploadBlock(convert(code)[0], page, "")

Expected: code block is created on page with print("World!") indented. Actual: code block is created on page with print("World!") (no ident) instead.

image

I did some very brief poking at notion-py and it seems to be that we're passing this as a CodeBlock which is translated (inherits from BasicBlock) as markdown by default, but since we've already stripped out the markdown portion, it looks like the parsing strips out the leading whitespace.

I'm not sure if perhaps this is an issue for notion-py, but here's a quick stab at a fix in this library.

Cobertos commented 4 years ago

Wow this is great! I sincerely appreciate the work, and I do agree that having it be able to parse code fences with no explicit language is beneficial. Thanks for adding that feature and test.

The only thing I would change is that there's a recently added, currently undocumented feature in notion-py that would be a better handle for this, title_plaintext.

If you change title in the dict to title_plaintext, it should allow us to pass in the code text and language without having to make it a codefence + language and get reparsed + run into another sort of fuck up in the process.

Cobertos commented 4 years ago

Looks good, thanks!