Skip to content

Commit

Permalink
Merge pull request #10 from MartenBE/issue-9-fix-anchor-links
Browse files Browse the repository at this point in the history
Don't process anchor links
  • Loading branch information
MartenBE authored Nov 6, 2024
2 parents dd91dc9 + 2300cdc commit ff911c5
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,11 @@ plugins:
- `theme` can also be configured as a [Reveal.js built-in theme](https://revealjs.com/themes/), e.g. `black`, `white`, `league`, `solarized`, `dracula`, ... .
- `highlight_theme` can also be configured as a [highlight.js built-in theme](https://highlightjs.org/examples), e.g. `monokai`, `obsidian`, `tokyo-night-dark`, `vs`, ... .
- `revealjs` can contain all [Reveal.js options](https://revealjs.com/config/).

## Contributing

You can run the tests with `poetry` and `pytest`:

```bash
poetry run pytest
```
17 changes: 12 additions & 5 deletions src/mkslides/markupgenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
REVEALJS_RESOURCE,
REVEALJS_THEMES_RESOURCE,
)
from .urltype import URLType

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -259,7 +260,7 @@ def __copy_local_files(
for m in regex.finditer(markdown):
location = m.group("location")

if not self.__is_absolute_url(location):
if self.__get_url_type(location) == URLType.RELATIVE:
image = Path(md_file.parent, location).resolve(strict=True)
self.__copy_to_output_relative_to_md_root(image, md_root_path)

Expand All @@ -269,7 +270,7 @@ def __copy_theme(
theme: str,
default_theme_resource: Traversable | None = None,
) -> Path | str:
if self.__is_absolute_url(theme):
if self.__get_url_type(theme) == URLType.ABSOLUTE:
logger.info(
f'Using theme "{theme}" from an absolute URL, no copy necessary',
)
Expand Down Expand Up @@ -300,7 +301,7 @@ def __copy_theme(
return relative_theme_path

def __copy_favicon(self, file_using_favicon_path: Path, favicon: str) -> Path | str:
if self.__is_absolute_url(favicon):
if self.__get_url_type(favicon) == URLType.ABSOLUTE:
logger.info(
f'Using favicon "{favicon}" from an absolute URL, no copy necessary',
)
Expand Down Expand Up @@ -380,5 +381,11 @@ def __copy_file(self, source_path, destination_path) -> None:
f'{action} file "{source_path.absolute()}" to "{destination_path.absolute()}"',
)

def __is_absolute_url(self, url: str) -> bool:
return bool(urlparse(url).scheme)
def __get_url_type(self, url: str) -> URLType:
if url.startswith("#"):
return URLType.ANCHOR

if bool(urlparse(url).scheme):
return URLType.ABSOLUTE

return URLType.RELATIVE
6 changes: 6 additions & 0 deletions src/mkslides/urltype.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from enum import Enum

class URLType(Enum):
ANCHOR = "anchor"
ABSOLUTE = "absolute"
RELATIVE = "relative"
6 changes: 6 additions & 0 deletions tests/test_files/someslides.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,9 @@ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor i
:thumbsup: <!-- checking aliases https://www.webfx.com/tools/emoji-cheat-sheet/ -->

---

## Don't try to parse anchor links

[Go to anchor](#anchor)

---

0 comments on commit ff911c5

Please sign in to comment.