normanlorrain / mdpdf

Python command line application to convert Markdown to PDF.
MIT License
51 stars 10 forks source link

Relative links within the pdf #6

Open elenalape opened 3 years ago

elenalape commented 3 years ago

To support GitHub flavoured markdown (along with #1), it would be nice to allow for relative links within the document. As a temporary solution, currently I'm changing them in the md file to web URLs using regex, and then passing it to mdpdf. Using sed:

#!/bin/bash
sed -i -e -r "s/(#[^ ][^\)]*)\)/https:\/\/example.org\/dir\1\)/g" file.md &
mdpdf -o file.pdf file.md

which finds bits such as #example-relative-link) and replaces them with https://example.org/dir#example-relative-link)

normanlorrain commented 3 years ago

It's something I've come across before (I see I left a TODO in the source). It would require maintaining a list of these links, and resolving them to their targets. I'm not sure CommonMark's AST code gives those targets.

https://spec.commonmark.org/0.29/#example-497

More information here and here

elenalape commented 3 years ago

What do you think about using some regex to remove relative links then completely, so that no errors are thrown? I could work on that change. Also, could remove the fancy badges (#1).

normanlorrain commented 3 years ago

I like that idea. "Explicit is better than implicit" etc.

If you want to take it on that would be great.

elenalape commented 3 years ago

@normanlorrain do you have any advice on how to get the dev environment set up besides cheatsheet? I'm having issues with the fitz/PyMuPDF imports (which you must have also had to navigate!) and would appreciate some pointers.

normanlorrain commented 3 years ago

I've updated the package. Sorry for the glitch, I missed some changes to PyMuPDF in their latest version.

If you upgrade your installation: pip install --upgrade mdpdf it should work now.