`) in addition to Markdown (``) ([#785](https://github.com/mitmproxy/pdoc/pull/785), @earshinov)
## 2024-12-12: pdoc 15.0.1
diff --git a/pdoc/docstrings.py b/pdoc/docstrings.py
index 5c9dc682..7a4624d3 100644
--- a/pdoc/docstrings.py
+++ b/pdoc/docstrings.py
@@ -63,23 +63,28 @@ def convert(docstring: str, docformat: str, source_file: Path | None) -> str:
def embed_images(docstring: str, source_file: Path) -> str:
+ def local_image_to_data_uri(href: str) -> str:
+ image_path = source_file.parent / href
+ image_data = image_path.read_bytes()
+ image_mime = mimetypes.guess_type(image_path)[0]
+ image_data_b64 = base64.b64encode(image_data).decode()
+ return f"data:{image_mime};base64,{image_data_b64}"
+
def embed_local_image(m: re.Match) -> str:
- image_path = source_file.parent / m["href"]
try:
- image_data = image_path.read_bytes()
- image_mime = mimetypes.guess_type(image_path)[0]
+ href = local_image_to_data_uri(m["href"])
except Exception:
return m[0]
else:
- data = base64.b64encode(image_data).decode()
- return f"![{m['alt']}](data:{image_mime};base64,{data})"
-
- return re.sub(
- r"!\[\s*(?PA happy constant. ✨
+
A happy constant. ✨ pdoc documents constants with their type annotation and default value.
This variable is annotated with a type only, but not assigned to a value.
-We also haven't defined the associated type (Foo) yet,
+We also haven't defined the associated type (Foo) yet,
so the type annotation in the code in the source code is actually a string literal:
<img src="../docs/logo.png" alt="pdoc logo" width="150">
+
+
+262def admonitions(): -263 """ -264 pdoc also supports basic reStructuredText admonitions or GitHub's Markdown alerts: -265 -266 ``` -267 > [!NOTE/WARNING/DANGER] -268 > Useful information that users should know, even when skimming content. -269 -270 .. note/warning/danger:: Optional title -271 Body text +diff --git a/test/testdata/demo_long.py b/test/testdata/demo_long.py index 7b85334e..839ccf0e 100644 --- a/test/testdata/demo_long.py +++ b/test/testdata/demo_long.py @@ -39,14 +39,14 @@ FOO_CONSTANT: int = 42 """ -A happy constant. ✨ +A happy constant. ✨ pdoc documents constants with their type annotation and default value. """ FOO_SINGLETON: "Foo" """ This variable is annotated with a type only, but not assigned to a value. -We also haven't defined the associated type (`Foo`) yet, +We also haven't defined the associated type (`Foo`) yet, so the type annotation in the code in the source code is actually a string literal: ```python @@ -255,6 +255,12 @@ def embed_image(): ```  + + ``` +268def admonitions(): +269 """ +270 pdoc also supports basic reStructuredText admonitions or GitHub's Markdown alerts: +271 272 ``` -273 -274 > [!NOTE] -275 > Hi there! -276 -277 .. warning:: Be Careful! -278 This warning has both a title *and* content. +273 > [!NOTE/WARNING/DANGER] +274 > Useful information that users should know, even when skimming content. +275 +276 .. note/warning/danger:: Optional title +277 Body text +278 ``` 279 -280 .. danger:: -281 Danger ahead. +280 > [!NOTE] +281 > Hi there! 282 -283 """ +283 .. warning:: Be Careful! +284 This warning has both a title *and* content. +285 +286 .. danger:: +287 Danger ahead. +288 +289 """+ ``` + +
""" diff --git a/test/testdata/demo_long.txt b/test/testdata/demo_long.txt index 2d80cf0f..512ec3da 100644 --- a/test/testdata/demo_long.txt +++ b/test/testdata/demo_long.txt @@ -1,7 +1,8 @@
+ str: ... # This is a basic modu…>