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

Support relative file URIs in hyperlinks when using CLI #532

Closed
noverby opened this Issue Nov 9, 2017 · 3 comments

Comments

Projects
None yet
2 participants
@noverby

noverby commented Nov 9, 2017

For example when converting the following html to a pdf, it should be possible to make the hyperlink refer to the relative URI and not the absolute URI:

<a href="external-file.pdf">File</a>

What I get: "file://absolute-path/external-file.pdf"
What I want: "external-file.pdf"

I have tried to change the --base-url argument, but it does not remove the absolute path if I set it to ""(empty).

So I looked it up in the code, and it is fairly easy to change, but I just wanted to make sure that there is interest in including this feature. If there are indeed interest I can make a pull request.

Relative file URIs are also what Prince outputs by default.

@noverby noverby changed the title from Support relative file paths in links to Support relative file URIs in hyperlinks Nov 9, 2017

@liZe

This comment has been minimized.

Show comment
Hide comment
@liZe

liZe Nov 10, 2017

Member

Hmmm… Really looks like #437, I'll take a look.

Member

liZe commented Nov 10, 2017

Hmmm… Really looks like #437, I'll take a look.

@liZe liZe added the feature label Nov 16, 2017

@liZe liZe changed the title from Support relative file URIs in hyperlinks to Support relative file URIs in hyperlinks when using CLI Nov 16, 2017

@liZe

This comment has been minimized.

Show comment
Hide comment
@liZe

liZe Nov 16, 2017

Member

Unfortunately, what you want is currently impossible using the CLI:

  • HTML finds base_url from the document when using a file,
  • the CLI uses '.' instead of None as default base_url value when using stdin, and
  • base_url is transformed into an absolute path when it's different from None (even if it's '').

Even if these 3 choices may look strange when looked at carefully, I think that they are actually really good when they're used without thinking (and that's what most CLI users do). I don't want to change this behavior.

So you currently have to use HTML(string='<a href="external-file.pdf">File</a>') to get what you want.

A solution would be to transform --base-url="" into base_url = None, and keep base_url = '.' when --base-url is not set. You would then be able to get relative URIs using weasyprint --base-url="" - output.pdf < input.html. What do you think about that?

Member

liZe commented Nov 16, 2017

Unfortunately, what you want is currently impossible using the CLI:

  • HTML finds base_url from the document when using a file,
  • the CLI uses '.' instead of None as default base_url value when using stdin, and
  • base_url is transformed into an absolute path when it's different from None (even if it's '').

Even if these 3 choices may look strange when looked at carefully, I think that they are actually really good when they're used without thinking (and that's what most CLI users do). I don't want to change this behavior.

So you currently have to use HTML(string='<a href="external-file.pdf">File</a>') to get what you want.

A solution would be to transform --base-url="" into base_url = None, and keep base_url = '.' when --base-url is not set. You would then be able to get relative URIs using weasyprint --base-url="" - output.pdf < input.html. What do you think about that?

@noverby

This comment has been minimized.

Show comment
Hide comment
@noverby

noverby Nov 16, 2017

@liZe That would be nice. Thank you 👍

noverby commented Nov 16, 2017

@liZe That would be nice. Thank you 👍

@liZe liZe closed this in 3961774 Nov 16, 2017

@liZe liZe added this to the v0.42 milestone Nov 16, 2017

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