orzih/mkdocs-with-pdf

Download PDF missing with mkdocs-material 8

fottsia opened this issue · 4 comments

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!

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

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

#88 (comment)

thanks a lot , it's working for me.