jgm / pandoc

Universal markup converter
https://pandoc.org
Other
34.02k stars 3.35k forks source link

Image wikilinks for export in Obsidian #8853

Closed anutator closed 1 year ago

anutator commented 1 year ago

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

jankap commented 1 year ago

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

jgm commented 1 year ago

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 commented 1 year ago

Good question, I don't know either. So maybe a filter to convert wikilinks to MD links would be recommended? Or using only MD links?

On Mon, Jul 3, 2023, 17:48 John MacFarlane @.***> wrote:

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

— Reply to this email directly, view it on GitHub https://github.com/jgm/pandoc/issues/8853#issuecomment-1618740988, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADCL5FG2GZPW6PQBTZYZHZTXOLSUPANCNFSM6AAAAAAYBZH5J4 . You are receiving this because you commented.Message ID: @.***>

jgm commented 1 year ago

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 commented 1 year ago

Wikilink images now supported.

FeralFlora commented 1 year ago

Wikilink images now supported.

Great news! Has this already been released?

jgm commented 1 year ago

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

FeralFlora commented 1 year ago

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 commented 12 months ago

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 commented 12 months ago

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

Demon-tk commented 12 months ago

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

FeralFlora commented 12 months ago

@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 commented 12 months ago

@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 commented 12 months ago

@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 commented 10 months ago

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 commented 10 months ago

This will currently work with markdown but not gfm.

jgm commented 10 months ago

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

AndreiPashkin commented 10 months ago

This will currently work with markdown but not gfm.

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

AndreiPashkin commented 10 months ago

@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 commented 10 months ago

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