Skip to content

Commit f118d97

Browse files
committed
♻️ Refactor(quarto_reportview): Update _generate_image_content method to use html code instead of md
This was added to support absolute paths, the md code did not recognize absolute paths
1 parent 7f668f8 commit f118d97

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,5 +127,5 @@ UML_diagrams/
127127
Graphical_abstract/
128128
docs/presentations/
129129
test.py
130-
vuegen/yaml_generator.py
131-
MicW2Graph_config.yaml
130+
vuegen/config_generator.py
131+
example_data/MicW2Graph/MicW2Graph_config.yaml

vuegen/quarto_reportview.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ def _generate_markdown_content(self, markdown) -> List[str]:
475475

476476
def _generate_image_content(self, image_path: str, alt_text: str = "", width: int = 650, height: int = 400) -> str:
477477
"""
478-
Adds an image to the content list in a centered format with a specified width.
478+
Adds an image to the content list in an HTML format with a specified width and height.
479479
480480
Parameters
481481
----------
@@ -484,20 +484,25 @@ def _generate_image_content(self, image_path: str, alt_text: str = "", width: in
484484
width : int, optional
485485
Width of the image in pixels (default is 650).
486486
height : int, optional
487-
Height of the image in pixels (default is 500).
487+
Height of the image in pixels (default is 400).
488488
alt_text : str, optional
489489
Alternative text for the image (default is an empty string).
490490
491491
Returns
492492
-------
493493
str
494-
The formatted image content.
494+
The formatted HTML image content.
495495
"""
496-
# Check if the image path is a URL or a local file path
497496
if is_url(image_path):
498-
return f"""![{alt_text}]({image_path}){{ width={width}px height={height}px fig-align="center"}}\n"""
497+
src = image_path
499498
else:
500-
return f"""![{alt_text}]({os.path.join('..', image_path)}){{ width={width}px height={height}px fig-align="center"}}\n"""
499+
src = os.path.abspath(image_path)
500+
501+
# Return the HTML content
502+
return f"""
503+
<div style="text-align: center;">
504+
<img src="{src}" alt="{alt_text}" width="{width}" height="{height}" />
505+
</div>\n"""
501506

502507
def _show_dataframe(self, dataframe, is_report_static, static_dir: str = STATIC_FILES_DIR) -> List[str]:
503508
"""

0 commit comments

Comments
 (0)