orzih / mkdocs-with-pdf

Generate a single PDF file from MkDocs repository.
MIT License
325 stars 76 forks source link

Download PDF missing with mkdocs-material 8 #88

Open fottsia opened 2 years ago

fottsia commented 2 years ago

Hi, with the new mkdocs-material 8.0.0, the "download PDF" link at the footer no longer shows up. Thank you for this plugin, much appreciated!

hpsems commented 2 years ago

Same Problem here. Have you found a solution or workaround yet?

nicolasb29 commented 2 years ago

Hi,

It seems that css class changed from md-footer-copyright to md-copyright

https://github.com/orzih/mkdocs-with-pdf/blob/f2e78d8c8ecb505636ba31a4830646038a78accd/mkdocs_with_pdf/themes/material.py

nicolasb29 commented 2 years ago

Hi,

I have found a workaround : add a file pdf_event_hook.py (experimental feature) with this contant

import logging

from bs4 import BeautifulSoup
from mkdocs.structure.pages import Page

def inject_link(html: str, href: str,
                page: Page, logger: logging) -> str:

    logger.info(f'(hook on inject_link: {page.title})')
    soup = BeautifulSoup(html, 'html.parser')
    footer = soup.select('.md-copyright')
    nav = soup.find(class_='md-header-nav')
    if footer and footer[0]:
        container = footer[0]

        container.append(' ... ')
        a = soup.new_tag('a', href=href, title='PDF',
                         download=None, **{'class': 'link--pdf-download'})
        a.append('download PDF')

        container.append(a)

        return str(soup)

    return html
samzong commented 2 years ago

https://github.com/orzih/mkdocs-with-pdf/issues/88#issuecomment-1018590667

thanks a lot , it's working for me.