comwes / mkpdfs-mkdocs-plugin

Converts your mkdocs documentation in PDF, to be shared with users
https://comwes.github.io/mkpdfs-mkdocs-plugin
GNU General Public License v3.0
103 stars 36 forks source link

File system links #8

Closed avarone-github closed 3 years ago

avarone-github commented 5 years ago

Generated PDF contains file system links instead of internal links. This is mkdocs.yml:

site_name: Test

nav:
    - Home: index.md
    - Topic one: one.md
    - Topic two: two.md

plugins:
    - search
    - mkpdfs

These are the .md file contained in the docs folder:

index.md:

# Home page

This is the home page.

one.md:

# Topic one

This topic has only a link to [topic two](two.md).

two.md:

# Topic two

This topic has some text and a link to [topic one](one.md).

See combined.pdf file: TOC links are OK, links contained inside the pages point to a kind of file system path (e.g., file:///E|/mkpdfs_test/two/) which is not good. All link inside the static HTML site are OK, link syntax is allowed.

avarone-github commented 5 years ago

After further investigations, it seems to me the problem has to do with the is_doc function inside prprocessor/links/util.py and the use of os.path instead of posixpath inside the same file when working under Windows. The is_doc doesn't recognize an href ending with a slash (default document) as a "document". The normalize_href function, in its turn, replaces slashes with "operating system slashes" (i.e., under Windows, backslashes), which seems not good for subsequent links operations. In the is_doc function I tried and change line 14 from:

htmlfile = ext.startswith('.html')

to:

htmlfile = ext.startswith('.html') or href.endswith('/')

in order to recognize default documents as legitimate "documents". I also replaced import os with import posixpath and replaced all references to os.path with references to posixpath. This seems to solve the problem, but I would greatly appreciate a feedback from the authors.

comwes commented 4 years ago

@avarone-github,

Quite busy currently, we'll look into this issue as soon as possible and come back to you with a feedback on the suggested fix.

KR, Gerry Ntabuhashe

trogper commented 4 years ago

this change does not work well. I get many anchor errors. Some links in the document work, some not. The TOC is half-broken.
In docs folder structure I have dokumentacia_k_produktu, caste_problemy and dokumentacia_k_zdrojovemu_kodu directly in docs, not nested as can be seen in the errors

ERROR   -  Content discarded: target points to undefined anchor "('string', '#dokumentacia_k_produktu/prirucky/pouzivatelska_prirucka/obmedzovace/#mkpdf-dokumentacia_k_produktu/prirucky/pouzivatelska_prirucka/obmedzovace/:')"
ERROR   -  Content discarded: target points to undefined anchor "('string', '#dokumentacia_k_produktu/prirucky/pouzivatelska_prirucka/analyza_moonscript_projektov/#mkpdf-dokumentacia_k_produktu/prirucky/pouzivatelska_prirucka/analyza_moonscript_projektov/:')"
ERROR   -  Content discarded: target points to undefined anchor "('string', '#dokumentacia_k_produktu/dokumentacia_k_zdrojovemu_kodu/#mkpdf-dokumentacia_k_produktu/dokumentacia_k_zdrojovemu_kodu/:')"
ERROR   -  Content discarded: target points to undefined anchor "('string', '#dokumentacia_k_produktu/caste_problemy/#mkpdf-dokumentacia_k_produktu/caste_problemy/:')"
ERROR   -  No anchor #dokumentacia_k_produktu/dokumentacia_k_zdrojovemu_kodu/#mkpdf-dokumentacia_k_produktu/dokumentacia_k_zdrojovemu_kodu/: for internal URI reference
ERROR   -  No anchor #dokumentacia_k_produktu/dokumentacia_k_zdrojovemu_kodu/#mkpdf-dokumentacia_k_produktu/dokumentacia_k_zdrojovemu_kodu/: for internal URI reference
ERROR   -  No anchor #dokumentacia_k_produktu/caste_problemy/#mkpdf-dokumentacia_k_produktu/caste_problemy/: for internal URI reference
ERROR   -  No anchor #dokumentacia_k_produktu/caste_problemy/#mkpdf-dokumentacia_k_produktu/caste_problemy/: for internal URI reference
comwes commented 3 years ago

@avarone-github problem seems to be fixed by #35 which is part of the upcoming release