-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ NEW: Add
relative-images
option to includes (#237)
This allows for local image references to be located correctly, when including from a file in a sub/super folder. This commit also consolidates some code into `is_external_url`
- Loading branch information
1 parent
08c5dea
commit f057831
Showing
10 changed files
with
134 additions
and
38 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
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 |
---|---|---|
@@ -1,9 +1,34 @@ | ||
import html | ||
from urllib.parse import quote | ||
from typing import Optional, List | ||
from urllib.parse import quote, urlparse | ||
|
||
|
||
def escape_url(raw): | ||
""" | ||
Escape urls to prevent code injection craziness. (Hopefully.) | ||
""" | ||
return html.escape(quote(html.unescape(raw), safe="/#:()*?=%@+,&")) | ||
|
||
|
||
def is_external_url( | ||
reference: str, known_url_schemes: Optional[List[str]], match_fragment: bool | ||
) -> bool: | ||
"""Return if a reference should be recognised as an external URL. | ||
URLs are of the format: scheme://netloc/path;parameters?query#fragment | ||
This checks if there is a url scheme (e.g. 'https') and, if so, | ||
if the scheme is is the list of known_url_schemes (if supplied). | ||
:param known_url_schemes: e.g. ["http", "https", "mailto"] | ||
If None, match all schemes | ||
:param match_fragment: If True and a fragment found, then True will be returned, | ||
irrespective of a scheme match | ||
""" | ||
url_check = urlparse(reference) | ||
if known_url_schemes is not None: | ||
scheme_known = url_check.scheme in known_url_schemes | ||
else: | ||
scheme_known = bool(url_check.scheme) | ||
return scheme_known or (match_fragment and url_check.fragment) |
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 |
---|---|---|
|
@@ -7,4 +7,5 @@ orphan: true | |
Some text with *syntax* | ||
|
||
```{include} subfolder/include2.inc.md | ||
:relative-images: | ||
``` |
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
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