Skip to content

Commit 01fdf10

Browse files
committed
Add pandoc.inlines.Image
1 parent cc7618d commit 01fdf10

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

quartodoc/pandoc/inlines.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55

66
import collections.abc as abc
77
from dataclasses import dataclass
8+
from pathlib import Path
89
from typing import TypeAlias, Optional, Sequence
910

1011
from quartodoc.pandoc.components import Attr
1112

1213
__all__ = (
1314
"Code",
1415
"Emph",
16+
"Image",
1517
"Inline",
1618
"Inlines",
1719
"Link",
@@ -170,6 +172,28 @@ def __str__(self):
170172
return f"*{content}*"
171173

172174

175+
@dataclass
176+
class Image(Inline):
177+
"""
178+
Image
179+
"""
180+
181+
caption: Optional[str] = None
182+
src: Optional[Path | str] = None
183+
title: Optional[str] = None
184+
attr: Optional[Attr] = None
185+
186+
def __str__(self):
187+
"""
188+
Return image as markdown
189+
"""
190+
caption = self.caption or ""
191+
src = self.src or ""
192+
title = f' "{self.title}"' if self.title else ""
193+
attr = f"{{{self.attr}}}" if self.attr else ""
194+
return f"![{caption}]({src}{title}){attr}"
195+
196+
173197
# Helper functions
174198

175199
def join_inline_content(content: Sequence[InlineContent]) -> str:

0 commit comments

Comments
 (0)