Skip to content

Commit

Permalink
Added support for escaped links in Markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
MartenBE committed Sep 11, 2024
1 parent c8fc161 commit 507c3dd
Show file tree
Hide file tree
Showing 7 changed files with 218 additions and 3 deletions.
183 changes: 182 additions & 1 deletion poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ python-frontmatter = "^1.1.0"
PyYAML = "^6.0.2"
rich = "^13.8.0"
click = "^8.1.7"
jsonschema = "^4.23.0"

[tool.poetry.group.dev.dependencies]
bumpver = "^2023.1129"
Expand Down
8 changes: 8 additions & 0 deletions src/mkslides_reveal/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@


class Config:
schema = {
"type": "object",
"properties": {
"price": {"type": "number"},
"name": {"type": "string"},
},
}

def __init__(self) -> None:
with DEFAULT_CONFIG_RESOURCE.open() as f:
self.__config = yaml.safe_load(f)
Expand Down
10 changes: 9 additions & 1 deletion src/mkslides_reveal/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@
MD_LINK_REGEX = re.compile(
r"""
\[.*?\] # Alt text
\((?P<location>.*?)\) # Image location
\((?P<location>[^()<>]*?)\) # Location without angle brackets
""",
re.VERBOSE,
)

MD_ESCAPED_LINK_REGEX = re.compile(
r"""
\[.*?\] # Alt text
\(<(?P<location>[^<>]*?)>\) # Location with mandatory angle brackets
""",
re.VERBOSE,
)
Expand Down
8 changes: 7 additions & 1 deletion src/mkslides_reveal/markupgenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
HTML_BACKGROUND_IMAGE_REGEX,
HTML_IMAGE_REGEX,
LOCAL_JINJA2_ENVIRONMENT,
MD_ESCAPED_LINK_REGEX,
MD_LINK_REGEX,
REVEALJS_RESOURCE,
REVEALJS_THEMES_RESOURCE,
Expand Down Expand Up @@ -244,7 +245,12 @@ def __copy_local_files(
md_root_path: Path,
markdown: str,
) -> None:
for regex in [MD_LINK_REGEX, HTML_IMAGE_REGEX, HTML_BACKGROUND_IMAGE_REGEX]:
for regex in [
MD_LINK_REGEX,
MD_ESCAPED_LINK_REGEX,
HTML_IMAGE_REGEX,
HTML_BACKGROUND_IMAGE_REGEX,
]:
for m in regex.finditer(markdown):
location = m.group("location")

Expand Down
4 changes: 4 additions & 0 deletions tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ def test_process_directory_without_config(setup_markup_generator: Any) -> None:
"img/example-2.png",
"img/example-3.png",
"img/example-4.png",
"img/example-(7).png",
"img/somefolder/example-5.png",
"somefolder/example-6.png",
"test-1.txt",
"test-2.txt",
"test-(3).txt",
],
)

Expand Down Expand Up @@ -71,8 +73,10 @@ def test_process_file_without_config(setup_markup_generator: Any) -> None:
"img/example-1.png",
"img/example-2.png",
"img/example-3.png",
"img/example-(7).png",
"test-1.txt",
"test-2.txt",
"test-(3).txt",
],
)

Expand Down
7 changes: 7 additions & 0 deletions tests/test_files/someslides.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,10 @@ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor i

[](./test-1.txt)
[](test-2.txt)

## Escape using `<` and `>`

![](<./img/example-(7).png>)
![](<https://example.org/example_(1).png>)
[](<./test-(3).txt>)
[](<https://example.org/example_(2).html>)

0 comments on commit 507c3dd

Please sign in to comment.