diff --git a/requirements.txt b/requirements.txt index e3311b2d6ef706d14daa7a3eaca891772f08df08..50a2a25886d63b3221e558e86637355218046e87 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,3 +20,4 @@ rich==13.7.0 # via oneM2M-spec-2-MD-converter (setup.py) typing-extensions==4.8.0 # via python-docx +pillow==10.1.0 diff --git a/spec2md.py b/spec2md.py index b8a1da72e74e573da2c33c115b5af507e7e4c833..dc2441470c1a7347c103308a89ad7c1f746081ab 100644 --- a/spec2md.py +++ b/spec2md.py @@ -26,6 +26,8 @@ from rich import inspect import configparser, zipfile from lxml import etree as ET +from PIL import Image + class Style(IntEnum): example = auto() image = auto() @@ -620,6 +622,7 @@ def processDocuments(documents:list[str], outDirectory:str, skipImageConversion: elif style in docConfig.tablecaption: lines.append('') caption = replaceNL(text).strip() + caption = replaceNL(text).strip() anchor = f'<a name="table_{caption[6:].split(":")[0].strip()}"></a>' if caption.startswith('Table ') and ':' in caption else '' lines.append(f'**{caption}**{anchor}') @@ -824,10 +827,12 @@ def processDocuments(documents:list[str], outDirectory:str, skipImageConversion: cmd = converter cmd = cmd.replace('{infile}', fn).replace('{outdir}', _t) _print(f'Converting EMF file: {fn} to "{format}"', highlight = False) - if (res := subprocess.run(cmd, shell = True, capture_output = True)).returncode != 0: - _print(f'[red]Error running command: {res.stderr.decode("utf-8")}') - _print(f'[red]Please check the configuration file -> section "\[media]" for the converter command: {converter}') - break + + convert(fn, fn[:-4]) + #if (res := subprocess.run(cmd, shell = True, capture_output = True)).returncode != 0: + # _print(f'[red]Error running command: {res.stderr.decode("utf-8")}') + # _print(f'[red]Please check the configuration file -> section "\[media]" for the converter command: {converter}') + # break if not skipImageConversion: if docConfig.emfConverterPng: @@ -842,6 +847,10 @@ def processDocuments(documents:list[str], outDirectory:str, skipImageConversion: progress.stop() +def convert(input:str, output_name:str): + + name=output_name+".png" + Image.open(input).save(str(name)) if __name__ == '__main__':