zhaoterryy / mkdocs-pdf-export-plugin

An MkDocs plugin to export content pages as PDF files
MIT License
313 stars 44 forks source link

Links in combined PDFs are still broken #43

Open erilot opened 5 years ago

erilot commented 5 years ago

Running mkdocs-pdf-export-plugin 0.5.3, relative links between pages are still pointing to local file locations:

image

It looks like this was fixed in #28 but may have regressed since then. I've tested this in my existing projects and in a clean test project (as shown in the screenshot above, relative links are all pointing to file:///C:... locations. The links work properly in rendered HTML.

During the build, the same error gets thrown four times (the test project has only 3 pages), which seems like the same thing experienced in #42:

ERROR: No anchor #/.:pdf-export-test for internal URI reference
ERROR: No anchor #/.:pdf-export-test for internal URI reference
ERROR: No anchor #/.:pdf-export-test for internal URI reference
ERROR: No anchor #/.:pdf-export-test for internal URI reference

There is no file called pdf-export-test in the test project, but that is the H1 on the index.md page.

I'd be happy to provide the test project if it would be helpful. I could take a stab at a PR but I'm still learning my way around the code (and know nothing about WeasyPrint, unfortunately).

And lastly, this project is a lifesaver! Thank you so much for your work and active support. It is greatly appreciated.

CaptainQuirk commented 5 years ago

On my part, trying out the 0.5.3 version didn't solve my problem in #42.

I still get No anchor #cp/show/:charge-de-communication for internal URI reference for the markdown construct En tant que [Chargé de communication](../glossaire.md#charge-de-communication)

:+1: for the appreciation of the whole project

zhaoterryy commented 5 years ago

I'd be happy to provide the test project if it would be helpful. I could take a stab at a PR but I'm still learning my way around the code (and know nothing about WeasyPrint, unfortunately).

Yes please provide an example, my project here doesn't reproduce this issue. Thank you!

erilot commented 5 years ago

Here's the test project I'm using. I was curious if it was a Windows issue so opened the project on a Linux/Ubuntu desktop but am seeing the same behavior; PDFs are created successfully but links are pointing to local files instead of locations within the PDF. I also get errors for each head tag in the project, as above (this one is slightly different than my original report because I re-created everything from scratch).

ERROR: No anchor #/.:pdf-export-test-project for internal URI reference
ERROR: No anchor #/.:pdf-export-test-project for internal URI reference
ERROR: No anchor #/.:pdf-export-test-project for internal URI reference
ERROR: No anchor #/.:pdf-export-test-project for internal URI reference
ERROR: No anchor #/.:subheading for internal URI reference

Other details that may be useful:

Project: test.zip

Generated PDF: combined.pdf

Verbose build output (or most of it anyway, it filled up my buffer so we're missing the beginning) console-output.txt

Thanks again for looking into it!

zhaoterryy commented 5 years ago

I found the issue. For the time being, use_directory_urls must be set to false. https://www.mkdocs.org/user-guide/configuration/#use_directory_urls

Need to write a separate href builder for directory urls.

erilot commented 5 years ago

Sorry to drop this, was away for a couple of weeks!

This workaround fixes one problem -- I no longer get pointed at local files -- but it looks like there was another issue hiding behind that one.

Now that the local file links are fixed (or worked around), some links work, but some links just render as styled text that doesn't go anywhere.

I've expanded my test project to show these individual cases. If I can add test cases that would be helpful for you, I'm happy to build it out further. Also if this looks like a totally different issue to you, we can close this off and start a new one.

Revised test project: pdf-link-test-project.zip

Rendered PDF: test.pdf

Build output (not verbose this time because whoa): output.txt

zhaoterryy commented 5 years ago

@erilot try updating to v0.5.5, that should fix those issues.

majkinetor commented 5 years ago

Not only broken, but unclickable.

sebastienlevert commented 5 years ago

I found the issue. For the time being, use_directory_urls must be set to false. https://www.mkdocs.org/user-guide/configuration/#use_directory_urls

Need to write a separate href builder for directory urls.

Is there any work planned for supporting directory urls? Please let me know how we can help on getting this awesome feature in :)

Not only broken, but unclickable.

I'm also experiencing the same with the latest version 0.5.5. Is there any setting we have to put in place to make this work?

CaptainQuirk commented 4 years ago

@zhaoterryy @erilot any news on this ?

I'm still having issues with links containing anchors and several ../ in their paths

erilot commented 4 years ago

@CaptainQuirk sorry, forgot to watch my notifications. I cobbled together a solution for this (actually completely rebuilt the path generator) and it works for our team, but I wasn't able to submit a PR here and then forgot about it.

I've forked this project and updated it with my code, you're welcome to use it (the fork is not registered with pypi so you can't use pip to install it, you'll need to install it manually or copy the plugin files over this install.

https://github.com/erilot/mkdocs-pdf-export-plugin

@zhaoterryy I would be happy to submit this as a PR here but i think you have to allow that.

zhaoterryy commented 4 years ago

@erilot You should be able to submit a PR, I've accepted other's before. If you're still unable to then I can manually create one myself from your repo.

Thanks!!

erilot commented 4 years ago

@zhaoterryy you're totally right, I don't know what I did wrong before.

PR is here: https://github.com/zhaoterryy/mkdocs-pdf-export-plugin/pull/64

majkinetor commented 4 years ago

FYI, I created docker mkdocs framework which uses this plugin among other things.

You can view generated demo output here:

and download pdf

You can see that first links aren't clickable but later on second page so called magic links are clickable.

See requirements for dependency details.

igorcavalcante commented 4 years ago

I found the issue. For the time being, use_directory_urls must be set to false. https://www.mkdocs.org/user-guide/configuration/#use_directory_urls

Need to write a separate href builder for directory urls.

Thanks, it solved my problem today!

fletort commented 3 years ago

ANy news ? I used the use_directory_urls to false, but the error is always here for subdirectory link....

FlorianHeigl commented 2 months ago

The PR seems stuck... I also still get this kind of problems (anchor used in file in subfolder), too tired to try out why the patch has a conflict :(