forked from geosolutions-it/MapStore2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
geosolutions-it#9383: Re-enable PDF generation (geosolutions-it#9973)
- Loading branch information
1 parent
feffd53
commit 273103b
Showing
6 changed files
with
64 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# It is for mkdocs-with-pdf plugin | ||
# this file is resplosible for rendering the export pdf icon in case ENABLE_EXPORT_PDF = 1 in build environment | ||
|
||
import logging | ||
|
||
from bs4 import BeautifulSoup | ||
from mkdocs.structure.pages import Page | ||
|
||
|
||
def inject_link(html: str, href: str, | ||
page: Page, logger: logging) -> str: | ||
"""Adding PDF View button on navigation bar(using material theme)""" | ||
def _icon_tag(): | ||
return BeautifulSoup('<span class="pdf-icon"></span>', 'html.parser') | ||
|
||
logger.info(f'(hook on inject_link: {page.title})') | ||
soup = BeautifulSoup(html, 'html.parser') | ||
# you can change the icon location by specify the class name of the dom element that you want to append to | ||
# Find the DOM element with class "export-pdf-li" | ||
export_pdf = soup.find(class_='export-pdf-li') | ||
nav = soup.find(class_='md-header-nav') | ||
if export_pdf: | ||
a = soup.new_tag('a', href=href, title='PDF', target="_blank", **{'class': 'md-tabs__link'}) | ||
# Append an img tag with a local image source | ||
a.append(_icon_tag()) | ||
a.append("Export PDF") | ||
export_pdf.append(a) | ||
return str(soup) | ||
else: | ||
if not nav: | ||
# after 7.x | ||
nav = soup.find('nav', class_='md-header__inner') | ||
if nav: | ||
a = soup.new_tag('a', href=href, title='PDF', target="_blank", **{'class': 'md-header__button md-header-nav__button md-icon'}) | ||
a.append(_icon_tag()) | ||
a.append("Export PDF") | ||
nav.append(a) | ||
return str(soup) | ||
|
||
return html |