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

Fix conformance to Zim (and enable Insert Audio button): wrong attachment directories, linked file not found, missing image link's tags, minsdk 16-18 #2147

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

mehw
Copy link
Contributor

@mehw mehw commented Nov 11, 2023

Hello,

This series of patches is to conform the wikitext format to Zim:

  1. The expression {{}} is for images, other types should use [[]].
  2. Notebook's links should be relative to a wiki page's attachment directory.
  3. Files pulled into a Notebook should be placed in a proper attachment directory.
  4. Interpret image link's tags: id, width, height, href; images can link other files.

As an extra, the Insert Audio button is enabled.

More descriptions about Zim conformance are in the commits and in the code as comments.

Zim attachment directories

In wiki-example.txt, [[./video.mkv]] would be a link to a file residing in the wiki-example directory (relative path). Linking notebook.zim would add [[../notebook.zim]], and [[/home/user/README]] would be a link to a file outside the Notebook's root (absolute path).

/home/user/Notebook            # Notebook directory
      |    |
      |    `- notebook.zim     # marks the root of the Notebook
      |    |
      |    `- wiki-example     # wiki page's attachment directory
      |    |  |
      |    |  `- video.mkv     # wiki-example.txt file attachment
      |    |
      |    `- wiki-example.txt # wiki file written in wiki markup
      |
      `- README                # file outside the Notebook's root

Zim image link's tags

If {{./image.png?href=.%2Fvideo.mkv&id=anchor-name&width=50}} is in wiki-example.txt, ./ is resolved to the wiki page's attachment directory wiki-example, and in Markor you would have something like:

<a href="/home/user/Notebook/wiki-example/video.mkv"><img src="wiki-example/image.png" alt="wiki-example.txt" id="anchor-name" width="50" /></a>

@gsantner
Copy link
Owner

Hello @mehw the CI shows some build errors with these PR changes. Can you please check/fix that?

@mehw
Copy link
Contributor Author

mehw commented Nov 19, 2023

@gsantner I'm on it.

While editing a wiki file, Zim adds links to a target residing inside
the Notebook (where notebook.zim file is found) resolving the path as
relative to the wiki file's attachment directory (same parent/name of
the wiki file, but without the extension).  If a link's target is not
a child of the Notebook, Zim adds the link as an absolute path.

Zim always prefixes relative paths, adding './' if a link's target is
a child of a wiki file's attachment directory.

/home/user/Notebook            # Notebook directory
      |    |
      |    `- notebook.zim     # marks the root of the Notebook
      |    |
      |    `- wiki-example     # wiki file's attachment directory
      |    |  |
      |    |  `- video.mkv     # wiki-example.txt file attachment
      |    |
      |    `- wiki-example.txt # wiki file written in wiki markup
      |
      `- README                # file outside the Notebook's root

In wiki-example.txt, [[./video.mkv]] would be a link to an attachment
residing in the 'wiki-example' directory.  Linking notebook.zim would
add [[../notebook.zim]], and [[/home/user/README]] would be a link to
a file outside the Notebook.
Zim uses the path of the .txt wiki file for attachments, but without
the extension, i.e. wiki-text.txt would be connected to wiki-text as
attachment directory.
Zim local paths are relative to the current wiki file's attachment
directory.  Properly resolve an attachment path to edit the image.
Zim inserts file links relative to a wiki page's attachment directory,
if the target is a child of the Notebook.  Adapt the conversion of Zim
wiki pages to markdown, translating Zim file links accordingly.
Assume the current directory as top link if root cannot be determined.
Zim may insert attributes, as html tags, in an image link: id, width,
height, type, href.

{{./image.png?href=.%2Fvideo.mkv&id=anchor-name&width=50}}

In markdown [![name](image)](link) is close to the above, but without
the possibility to insert extra tags.
Add logic to insert an audio recording/link.
Adding myself to CONTRIBUTORS.md
@mehw
Copy link
Contributor Author

mehw commented Nov 20, 2023

Hello @mehw the CI shows some build errors with these PR changes. Can you please check/fix that?

@gsantner I changed a test to reflect a new behavior, this fixes the CI: assume the current directory as top link if root cannot be determined.

I thought this as a fallback, but also if the user wants to organize a notebook as a relative structure, without a specific root directory.

When notebook.zim is required to be found (aka isWikitextDynamicNotebookRootEnabled) but it doesn't exist, the current page's parent directory (aka current directory) is assumed to be the notebook's root from where to resolve the page's links.

// try the current directory as a possible notebook root dir
_notebookRootDir = _currentPage.getParentFile();

@gsantner
Copy link
Owner

gsantner commented Dec 3, 2023

Due other PR's edited the same files/things, there are merge conflicts now.

Can you please fix it?

@mehw
Copy link
Contributor Author

mehw commented Jan 7, 2024

Due other PR's edited the same files/things, there are merge conflicts now.

Can you please fix it?

@gsantner I will look into it in these days. Forgive me for leaving you hanging.

@gsantner
Copy link
Owner

no problem

@gsantner gsantner marked this pull request as draft March 27, 2024 03:03
@gsantner gsantner added this to the Markor v2.13 milestone Mar 27, 2024
@gsantner gsantner changed the title Fix conformance to Zim (and enable Insert Audio button): wrong attachment directories, linked file not found, missing image link's tags Fix conformance to Zim (and enable Insert Audio button): wrong attachment directories, linked file not found, missing image link's tags, minsdk 16-18 Mar 27, 2024
@gsantner gsantner marked this pull request as ready for review May 25, 2024 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants