peter88213 / zim2obsidian

Post-process Zim Markdown export for use with Obsidian.
MIT License
9 stars 1 forks source link

Exclude code blocks from zim2obsidian formatting #21

Closed laszabine closed 8 months ago

laszabine commented 8 months ago

Application/script

Describe the bug The formatting in zim2obsidian.py should exclude any string that is in a code environment (surrounded by 3 backticks each, perhaps also in-line code environments?). In my case, I have code environments containing bibtex code which includes the character @ and it got changed to # like a tag.

To Reproduce

  1. Copy my zim repository containing pages with code blocks with bibtex code
  2. Open zim (0.75.2), export to "Markdown (pandoc)", close zim
  3. Create python 3.12.2 venv, launch
  4. Copy zim2obsidian.py to the root location of the copied zim repository
  5. Run python zim2obsidian.py

Expected behavior Code environments should be excluded from the formatting.

Execution environment:

laszabine commented 8 months ago

Thank you for clarifying (and for your work on this!) Do you accept pull requests?

peter88213 commented 8 months ago

Sorry, I deleted my original comment before I saw your reply. I've just looked at it again and I think it can be considered a bug anyway. I have no experience with pull requests, but you can give it a try.

peter88213 commented 8 months ago

I just committed v0.11.3 that should exclude code blocks. You find it in this branch. The changes in the code are not yet tested. You may wish to update the test files and run test_zim2obsidian.py. Then you can contribute the test data and further code changes, if needed. As soon this is validated, I will publish the release.

Update: I just did it myself, merged the branch, and closed the issue. Good luck. If problems occur with your pages and code blocks, just re-open this issue.

sojusnik commented 8 months ago

@laszabine

Did you find a solution for the problem where text indentations aren't converted properly, as described here and here?

peter88213 commented 8 months ago

Please do not use the issue tracker for off-topic conversations, also not in closed issues. Remember that this will send email notifications that are distracting.

Your concern is already clearly visible in the other issues and in the discussions, and I'm sure that anyone who wants to contribute will address it there.

peter88213 commented 7 months ago

As of version 0.11.6, the zim2obsidian.py script excludes paragraphs that are enclosed with three backticks from conversion, as well as inline text enclosed with a single backtick (see #22).

Actually, enclosing text with backticks is not the way to mark "verbatim" text as specified with Zim:

To render a whole block verbatim, the first and last line of the block should contain 3 quotes and no other characters.

For "Inline code", there is no specification. However, if you mark verbatim blocks as specified, the Markdown result as exported by Zim is just indented, which is currently not supported by zim2obsidian.py (see #20 ).

For the record: The changes made with version 0.11.6 are actually working, but they are not bug fixes in the true meaning of the word. You can use them, but you should be aware that by using backticks you are deviating from the Zim specification.

peter88213 commented 7 months ago

With version 0.13.0 the behavior as requested here is implemented, yet optional. It can be selected with the --backticks parameter. See also: https://github.com/peter88213/zim2obsidian/discussions/15#discussioncomment-8918078