|
6 | 6 | from functools import partial |
7 | 7 | from pathlib import Path, PurePath |
8 | 8 | from typing import Callable, Iterable, Optional |
9 | | -from urllib.parse import unquote |
| 9 | +from urllib.parse import unquote, urlparse |
10 | 10 |
|
11 | 11 | from markdown_it import MarkdownIt |
12 | 12 | from markdown_it.token import Token |
@@ -1128,8 +1128,9 @@ async def stream_markdown(self) -> None: |
1128 | 1128 | return updater |
1129 | 1129 |
|
1130 | 1130 | def on_markdown_link_clicked(self, event: LinkClicked) -> None: |
1131 | | - if self._open_links: |
| 1131 | + if self._open_links and is_http_url(event.href): |
1132 | 1132 | self.app.open_url(event.href) |
| 1133 | + event.stop() |
1133 | 1134 |
|
1134 | 1135 | @staticmethod |
1135 | 1136 | def sanitize_location(location: str) -> tuple[Path, str]: |
@@ -1628,8 +1629,9 @@ async def forward(self) -> None: |
1628 | 1629 | self.post_message(self.NavigatorUpdated()) |
1629 | 1630 |
|
1630 | 1631 | async def _on_markdown_link_clicked(self, message: Markdown.LinkClicked) -> None: |
1631 | | - message.stop() |
1632 | | - await self.go(message.href) |
| 1632 | + if not is_http_url(message.href): |
| 1633 | + message.stop() |
| 1634 | + await self.go(message.href) |
1633 | 1635 |
|
1634 | 1636 | def watch_show_table_of_contents(self, show_table_of_contents: bool) -> None: |
1635 | 1637 | self.set_class(show_table_of_contents, "-show-table-of-contents") |
@@ -1657,3 +1659,9 @@ def _on_markdown_table_of_contents_selected( |
1657 | 1659 | block = self.query_one(block_selector, MarkdownBlock) |
1658 | 1660 | self.scroll_to_widget(block, top=True) |
1659 | 1661 | message.stop() |
| 1662 | + |
| 1663 | + |
| 1664 | +def is_http_url(url: str) -> bool: |
| 1665 | + """Check if a URL is an HTTP or HTTPS URL.""" |
| 1666 | + parsed = urlparse(url) |
| 1667 | + return parsed.scheme in ("http", "https") |
0 commit comments