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

Image wikilinks for export in Obsidian #8853

Closed
anutator opened this issue May 15, 2023 · 20 comments
Closed

Image wikilinks for export in Obsidian #8853

anutator opened this issue May 15, 2023 · 20 comments

Comments

@anutator
Copy link

anutator commented May 15, 2023

I use Obsidian and Pandoc Plugin to export to epub, html, docx.

There are new extensions in Pandoc 3.0 for wikilinks:
"Add new extensions wikilinks_title_after_pipe and wikilinks_title_before_pipe for commonmark and markdown".

They can't export Obdisian images with ! to markdown image links:
![[image1.png]] — image wikilink in Obsidian.

I get ! and an image URL, so images are not inserted.
Besides I have two problems:

  • I keep images in "assets" subfolder. I can't use option --resource-path=assets.
  • With --from=gfm+wikilinks_title_after_pipe text is exported from Obsidian without colors from Obsidian theme.

I'd like to automatically export wikilinks to markdown links not only for URLs but also for images, with title from image file name if it is not specified. Please add features to your extensions and give examples.

Current alternative:
At first I convert wikilinks to markdown links from every article I want to export with another plugin obsidian-link-converter . Or I can convert all wikilinks from my vault.

@anutator anutator changed the title Wikilinks for images for export in Obsidian Image wikilinks for export in Obsidian May 15, 2023
@jankap
Copy link

jankap commented Jul 3, 2023

You can find some LUA filters here, but basically I'm facing the same problem.

@jgm
Copy link
Owner

jgm commented Jul 3, 2023

This extension is supposed to be a general extension, not Obsidian specific.
So, I'm wondering whether ! + wikilink = image in other markdown applications that support wikilinks (e.g. GitHub wiki).

@jankap
Copy link

jankap commented Jul 3, 2023 via email

@jgm
Copy link
Owner

jgm commented Jul 4, 2023

For an obsidian-specific solution, you just need a filter that finds the sequence

Str "!", Link {}

and converts this to an Image. That's not the easiest kind of filter to write but it's possible.

@jgm jgm closed this as completed Jul 4, 2023
@jgm jgm reopened this Jul 4, 2023
@jgm jgm closed this as completed in 09de84f Aug 30, 2023
@jgm
Copy link
Owner

jgm commented Aug 30, 2023

Wikilink images now supported.

@FeralFlora
Copy link

Wikilink images now supported.

Great news! Has this already been released?

@jgm
Copy link
Owner

jgm commented Aug 30, 2023

No, it will be in the next release. Probably within the next couple of weeks?

@FeralFlora
Copy link

No, it will be in the next release. Probably within the next couple of weeks?

Okay, thanks for the answer. Looking forward to it!

@Demon-tk
Copy link

I am running Pandoc 3.1.8, with Obsidian.md and Pandoc plugin 0.4.1

Simply running the pandoc MD to DOCX results in an error. The path of the image files are incorrect, regardless of --resource-path=files; it is ignored.

What settings need to be configured to properly export to a Docx?

@FeralFlora
Copy link

@Demon-tk Are you using the wikilinks_title_after_pipe extension? Also, Do you have a proper path in your --resource-path?

@Demon-tk
Copy link

Demon-tk commented Sep 25, 2023

@FeralFlora Thanks for the response, where do I enable extensions?
P.S. The path appears correct.

@FeralFlora
Copy link

@FeralFlora Thanks for the response, where do I enable extensions? P.S. The path appears correct.

You add it to the input format (from) like so -f markdown+wikilinks_title_after_pipe.

@Demon-tk
Copy link

Demon-tk commented Sep 25, 2023

@FeralFlora Thanks for the response, where do I enable extensions? P.S. The path appears correct.

You add it to the input format (from) like so -f markdown+wikilinks_title_after_pipe.

Untitled

Above I have put my Obsidian Pandoc settings. Additionally my extra arguments are:

--resource-path=files
--from=gfm+wikilinks_title_after_pipe

EDIT:

After checking the docx file it appears that the images are turned into words rather than the actual image. Any idea what I'm doing wrong?

@FeralFlora
Copy link

@Demon-tk Since you edited you comment, I have to ask if you are still having errors or not, as you mentioned earlier?

I think you should consider switching to the Enhancing export plugin, since it is still maintained, and allows you to customize your whole command, not just add extra arguments. But regardless, I think image wikilink exports should work through the Pandoc plugin using extra arguments—it works for me.

@AndreiPashkin
Copy link

I have a source file

# Test

![[Attachments/test.png]]

And Pandoc command like this: pandoc -f gfm+wikilinks_title_after_pipe -t gfm --resource-path='<my-attachments-path' --columns=120 -o out.md in.md

And the result is:

# Test

\![Attachments/test.png](Attachments/test.png "wikilink")

For some reason Pandoc comments out the image.

@jgm
Copy link
Owner

jgm commented Nov 1, 2023

This will currently work with markdown but not gfm.

@jgm
Copy link
Owner

jgm commented Nov 1, 2023

You can add a new issue requesting support for gfm and commonmark.
This shouldn't be too hard to add.

@AndreiPashkin
Copy link

This will currently work with markdown but not gfm.

Indeed! Thank you for a prompt response. I'll add an issue.

@AndreiPashkin
Copy link

@jgm, I wonder if it's also possible to transform paths of wikilinks somehow? For example - if I have wikilinks pointing to a subfolder - can Pandoc rewrite them to point to the top-level folder?

@jgm
Copy link
Owner

jgm commented Nov 2, 2023

You can use a filter to rewrite wikilink URLs.
See the docs on pandoc.org for Lua filters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants