From 73a8d373e3b664720a7e8eb2ef18fb4f06d66794 Mon Sep 17 00:00:00 2001 From: Carsten Allefeld Date: Sat, 18 Jan 2025 17:02:52 +0000 Subject: [PATCH 1/4] Option --disable-wmf writes image embed code for wmf files --- pptx2md/parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pptx2md/parser.py b/pptx2md/parser.py index edcc10a..f0d3e1b 100644 --- a/pptx2md/parser.py +++ b/pptx2md/parser.py @@ -164,7 +164,7 @@ def process_picture(config: ConversionConfig, shape, slide_idx) -> Union[ImageEl picture_count += 1 # normal images - if pic_ext != 'wmf': + if config.disable_wmf or pic_ext != 'wmf': return ImageElement(path=img_outputter_path, width=config.image_width) # wmf images, try to convert, if failed, output as original From d40bba3bc7b1a40e157250507dd335781bb65f48 Mon Sep 17 00:00:00 2001 From: Carsten Allefeld Date: Sat, 18 Jan 2025 18:29:00 +0000 Subject: [PATCH 2/4] Take file extension from shape.image.filename instead of shape.image.ext --- pptx2md/parser.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pptx2md/parser.py b/pptx2md/parser.py index f0d3e1b..d3a441b 100644 --- a/pptx2md/parser.py +++ b/pptx2md/parser.py @@ -152,7 +152,10 @@ def process_picture(config: ConversionConfig, shape, slide_idx) -> Union[ImageEl file_prefix = ''.join(os.path.basename(config.pptx_path).split('.')[:-1]) pic_name = file_prefix + f'_{picture_count}' - pic_ext = shape.image.ext + if shape.image.filename: + pic_ext = shape.image.filename.split('.')[-1] + else: + pic_ext = shape.image.ext if not os.path.exists(config.image_dir): os.makedirs(config.image_dir) @@ -164,7 +167,7 @@ def process_picture(config: ConversionConfig, shape, slide_idx) -> Union[ImageEl picture_count += 1 # normal images - if config.disable_wmf or pic_ext != 'wmf': + if config.disable_wmf or (pic_ext != 'wmf' and pic_ext != 'emf'): return ImageElement(path=img_outputter_path, width=config.image_width) # wmf images, try to convert, if failed, output as original From 38ebeaccacf1bb68b28cd74cfbbeddbfb0e4e183 Mon Sep 17 00:00:00 2001 From: Carsten Allefeld Date: Sat, 18 Jan 2025 19:30:34 +0000 Subject: [PATCH 3/4] Use SHA1 for image file name --- pptx2md/parser.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/pptx2md/parser.py b/pptx2md/parser.py index d3a441b..d1a90d9 100644 --- a/pptx2md/parser.py +++ b/pptx2md/parser.py @@ -44,8 +44,6 @@ logger = logging.getLogger(__name__) -picture_count = 0 - def is_title(shape): if shape.is_placeholder and (shape.placeholder_format.type == PP_PLACEHOLDER.TITLE or @@ -148,10 +146,7 @@ def process_picture(config: ConversionConfig, shape, slide_idx) -> Union[ImageEl if config.disable_image: return None - global picture_count - - file_prefix = ''.join(os.path.basename(config.pptx_path).split('.')[:-1]) - pic_name = file_prefix + f'_{picture_count}' + pic_name = shape.image.sha1 if shape.image.filename: pic_ext = shape.image.filename.split('.')[-1] else: @@ -164,7 +159,6 @@ def process_picture(config: ConversionConfig, shape, slide_idx) -> Union[ImageEl img_outputter_path = os.path.relpath(output_path, common_path) with open(output_path, 'wb') as f: f.write(shape.image.blob) - picture_count += 1 # normal images if config.disable_wmf or (pic_ext != 'wmf' and pic_ext != 'emf'): From ec63733544e8b200561734aa5b49a80a1214774b Mon Sep 17 00:00:00 2001 From: Carsten Allefeld Date: Tue, 23 Dec 2025 21:18:47 +0000 Subject: [PATCH 4/4] Personal preferences for Quarto formatter --- pptx2md/outputter.py | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/pptx2md/outputter.py b/pptx2md/outputter.py index 3beadd6..2ab46e5 100644 --- a/pptx2md/outputter.py +++ b/pptx2md/outputter.py @@ -361,31 +361,18 @@ def put_elements(elements: List[SlideElement]): self.put_para(":::") if slide_idx < len(presentation_data.slides) - 1 and self.config.enable_slides: - self.put_para("\n---\n") + self.put_para("\n***\n") self.close() def put_header(self): - self.ofile.write('''--- -title: "Presentation Title" -author: "Author" -format: - revealjs: - slide-number: c/t - width: 1600 - height: 900 - logo: img/logo.png - footer: "Organization" - incremental: true - theme: [simple] ---- -''') + pass def put_title(self, text, level): - self.ofile.write('#' * level + ' ' + text + '\n\n') + self.ofile.write('\n\n' + '#' * level + ' ' + text + '\n\n') def put_list(self, text, level): - self.ofile.write(' ' * level + '* ' + text.strip() + '\n') + self.ofile.write(' ' * level + '- ' + text.strip() + '\n') def put_para(self, text): self.ofile.write(text + '\n\n') @@ -403,13 +390,13 @@ def put_table(self, table): self.ofile.write('\n'.join([gen_table_row(row) for row in table[1:]]) + '\n\n') def get_accent(self, text): - return ' _' + text + '_ ' + return ' *' + text + '* ' def get_strong(self, text): return ' __' + text + '__ ' def get_colored(self, text, rgb): - return ' %s ' % (rgb_to_hex(rgb), text) + return ' [%s]{style="color:%s"} ' % (text, rgb_to_hex(rgb)) def get_hyperlink(self, text, url): return '[' + text + '](' + url + ')'