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

Merged
merged 1 commit into from
Jul 27, 2024

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.

@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.

https://github.com/gsantner/markor/blob/856175fcb0390f3a618cf694e06d9f0b8abb8860/app/src/main/java/net/gsantner/markor/format/wikitext/WikitextLinkResolver.java#L94-L95

@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
The format {{}} is for images, other types should use [[]] instead.

References:
- https://github.com/zim-desktop-wiki/zim-desktop-wiki/blob/c88cf3cb53896bf272e87704826b77e82eddb3ef/data/manual/Help/Wiki_Syntax.txt

Zim: Fix link/attachment path of file selection

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: Fix attachment path of imported image

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: Fix attachment path of edit image

Zim local paths are relative to the current wiki file's attachment
directory.  Properly resolve an attachment path to edit the image.

Zim: Fix file link conversion to markdown

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.

Zim: Fallback to the current directory as root

Assume the current directory as top link if root cannot be determined.

Zim: Interpret image link attributes

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.

Zim: Enable audio recording/link button

Add logic to insert an audio recording/link.

Zim: Contribution for link/attachment fixes

Adding myself to CONTRIBUTORS.md
Copy link
Owner

@gsantner gsantner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks I rebased your changes on my own upon master...hope I did it all right and your intended changes still work.

I could at least press the >attach image< button, the text was inserted and a picture displayed in view mode. So should be OK I guess.

Thanks

@gsantner gsantner merged commit 3a506e2 into gsantner:master Jul 27, 2024
1 check passed
@mehw
Copy link
Contributor Author

mehw commented Aug 1, 2024

Thanks I rebased your changes on my own upon master...hope I did it all right and your intended changes still work.

I could at least press the >attach image< button, the text was inserted and a picture displayed in view mode. So should be OK I guess.

Thanks

Thank you very much for all your hard work.

Your consideration and merging my PR sure boost my mood ;)

Please, forgive my hiatus. The last time I posted, I thought that I was ready to resume programming at full power but I had to accept to go easy limiting to what requires less brain effort. I truly regret not being able to keep my promises.

On the bright side, I really enjoy programming and there are lots of things accumulated in my TODO list that keep me moving forward.

I treasure people, that is my strength, and my interest in debugging is an integral part of me.

I can't wait to be in tip-top shape for exploring the code.

@gsantner
Copy link
Owner

gsantner commented Aug 1, 2024

Thanks @mehw , feel welcome any time you want to join coding again.

Would you mind to install the latest v2.12.5 update and check if I did alright with the merge conflict? (So your initial change now works as you wanted it to)

@@ -72,6 +74,9 @@ private static String getLinkFormat(final int textFormatId) {
}

private static String getAudioFormat(final int textFormatId) {
if (textFormatId == FormatRegistry.FORMAT_WIKITEXT) {
return "[[LINK|TITLE]]";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for reference, this should have been [[%LINK%|%TITLE%]] :)

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.

3 participants