Skip to content

Commit

Permalink
fix: fixed formatting issues in preprocessor part
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgenwigg committed Oct 4, 2023
1 parent d0ee030 commit 4d173ae
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
1 change: 1 addition & 0 deletions mkpdfs_mkdocs/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
"""Defines api for the mkpdfs plugin."""
from .mkpdfs import Mkpdfs
1 change: 1 addition & 0 deletions mkpdfs_mkdocs/preprocessor/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
"""Defines api for the preprocessor module."""
from .prep import get_combined, get_separate
1 change: 1 addition & 0 deletions mkpdfs_mkdocs/preprocessor/links/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
"""Defines api for the preprocessor.links module."""
from .transform import transform_href, transform_id
from .util import get_body_id, rel_pdf_href, replace_asset_hrefs
25 changes: 15 additions & 10 deletions mkpdfs_mkdocs/preprocessor/prep.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Main preprocessor module."""
import os

from bs4 import BeautifulSoup
Expand All @@ -13,26 +14,30 @@


def get_combined(soup: BeautifulSoup, base_url: str, rel_url: str):
for id in soup.find_all(id=True):
id["id"] = transform_id(id["id"], rel_url)
"""Returns combined href."""
for entry in soup.find_all(id=True):
entry["id"] = transform_id(entry["id"], rel_url)

for a in soup.find_all("a", href=True):
if urls.url_is_absolute(a["href"]) or os.path.isabs(a["href"]):
a["class"] = "external-link"
for link in soup.find_all("a", href=True):
if urls.url_is_absolute(link["href"]) or os.path.isabs(link["href"]):
link["class"] = "external-link"
continue

a["href"] = transform_href(a["href"], rel_url)
link["href"] = transform_href(link["href"], rel_url)

soup.attrs["id"] = get_body_id(rel_url)
soup = replace_asset_hrefs(soup, base_url)
return soup


def get_separate(soup: BeautifulSoup, base_url: str):
# transforms all relative hrefs pointing to other html docs
# into relative pdf hrefs
for a in soup.find_all("a", href=True):
a["href"] = rel_pdf_href(a["href"])
"""Transforms relative hrefs into PDF href.
Transforms all relative hrefs pointing to other html docs
into relative pdf hrefs.
"""
for link in soup.find_all("a", href=True):
link["href"] = rel_pdf_href(link["href"])

soup = replace_asset_hrefs(soup, base_url)
return soup

0 comments on commit 4d173ae

Please sign in to comment.