Convert Marp Markdown files to polished PPTX presentations
Project description
Marp PPTX Post-Processing: Status & Next Steps
1. Marp HTML Structure (Key Concepts)
Slides:
- Each slide is represented by a
<svg data-marpit-svg ...>element. - Inside each SVG, there are one or more layers, each as a
<foreignObject>with width/height attributes. - Each
<foreignObject>contains a<section>element, which holds the content for that layer.
Headers:
- If a slide has a header, a
<header>element is placed under the<section>element. - Split background images are never placed in the header.
Marpit Advanced Backgrounds:
- Advanced backgrounds (true and split) are always placed in a
<div data-marpit-advanced-background-container="true">. - This div can contain one or more
<figure>elements, each with a background image. - The direction (horizontal/vertical) is set by
data-marpit-advanced-background-direction. - Split backgrounds are indicated by attributes like
data-marpit-advanced-background-spliton the<section>.
2. What We're Trying to Achieve
We want to post-process a Marp-exported PowerPoint (.pptx) so that all background images specified with Marp’s advanced image syntax are visually correct in the exported .pptx. This includes:
- True backgrounds (
): Fill the slide, appear behind content, and match Marp’s CSS background-size/position logic (cover, contain, auto, etc.). - Multiple backgrounds (
x N, withhorizontal/vertical): Stack images in the correct order and direction, matching Marp’s advanced backgrounds.- Split backgrounds (
![bg left],![bg right],![bg left:33%], etc.): Place the image as a foreground element in a defined region (not as a slide-wide background), shrinking the content area as Marp does. Onlyleftandrightsplit directions are supported (nottoporbottom).
- Split backgrounds (
- Cropping and placement: All cropping, scaling, and placement (e.g.,
right:35%,left:38% 70%,w:100% h:50%) should visually match Marp’s HTML/PDF output.
Reference: Marpit image syntax documentation
3. What We've Done So Far
-
HTML Parsing:
- The script parses Marp HTML output, extracting slide backgrounds, split info, image URLs, and layout instructions, by walking the SVG/foreignObject/section/container/figure structure.
- It builds a slide model for PPTX generation, replacing the old markdown/image logic.
-
True Backgrounds & Multiple Backgrounds:
- Images fill the slide or are stacked horizontally/vertically, matching Marp's stacking logic.
-
Advanced Background Scaling:
- Implemented full support for Marp's
background-sizeproperty, parsed from the generated HTML. - Supported keywords:
cover(fills the area, cropping if necessary),containandfit(scales to fit within the area),auto(uses original image size), and percentage values (e.g.,50%, which scales the image relative to the container).
- Implemented full support for Marp's
-
Split Backgrounds:
- Split backgrounds (left, right, with percentage) are placed in the correct region and cropped to fill only the split space. Only
leftandrightsplit directions are supported. - Multiple images in a split region are distributed equally within the split space (always horizontally), matching Marp's stacking logic.
- Split backgrounds (left, right, with percentage) are placed in the correct region and cropped to fill only the split space. Only
-
Debugging and Logging:
- Extensive debug logging shows all image shapes, sizes, and the matching process for troubleshooting.
-
Robust Image Mapping: Refactored the processing logic to map all images from the Marp HTML (including headers, content, and backgrounds) one-to-one with the picture shapes in the PPTX slide. This ensures that transformations are applied only to the correct background shapes, preventing unintended modifications to other images on the slide.
4. CLI & Pipeline Automation
The script has been refactored into a full command-line interface to automate the entire Marp to post-processed PPTX pipeline.
- End-to-End Automation: The script now orchestrates the three main steps of the conversion process:
- HTML Generation: It calls
npx @marp-team/marp-clito convert the source Markdown file into an HTML file. - Initial PPTX Generation: It uses the same CLI tool to create a raw, editable PPTX file (
*_raw.pptx). - Post-Processing: It runs the existing background image processing logic on the generated HTML and raw PPTX files.
- HTML Generation: It calls
- File Management:
- Smart Naming: Automatically creates an intermediate
_raw.pptxfile and saves the final output as<input_name>.pptx. - Automatic Cleanup: Deletes the intermediate HTML and
_raw.pptxfiles by default to keep the workspace clean. - Keep Intermediates: A
--debugflag is available to prevent cleanup for debugging purposes.
- Smart Naming: Automatically creates an intermediate
- Improved Usability:
- CLI Arguments: The script now uses
argparsefor robust handling of command-line arguments, including the input file, output file, and other options. - Help Documentation: A
--helpcommand provides clear instructions on how to use the script and its available options. - Enhanced Typing: Static typing has been improved throughout the codebase for better maintainability and reliability.
- CLI Arguments: The script now uses
5. Testing
The new CLI simplifies testing significantly. To process a Marp Markdown file, run the script with the input file path.
Set the name of the Marp markdown file:
$MARP_MARKDOWN_FILE = "sample.marp.md"
Run the end-to-end processing pipeline with a single command:
uv run marp_pptx_postprocess.py ./${MARP_MARKDOWN_FILE}
The script will handle the intermediate steps and produce a final, post-processed PPTX file named sample.marp.pptx.
To inspect the final output:
explorer "${MARP_MARKDOWN_FILE}.pptx"
To run the pipeline and keep the intermediate files for debugging:
uv run marp_pptx_postprocess.py ./${MARP_MARKDOWN_FILE} --debug
This will leave the following files for inspection:
${MARP_MARKDOWN_FILE}.html${MARP_MARKDOWN_FILE}_raw.pptx${MARP_MARKDOWN_FILE}.pptx(final output)
6. Next Steps (Advanced Placement)
Recent Progress
- Implemented a fix to widen all text boxes by 4cm (1133 pixels) to prevent unwanted text wrapping in headings when viewed in LibreOffice.
- This adjustment ensures that headings display correctly without wrapping issues.
The next major step is to handle explicit width and height parameters for background images, which are specified in the markdown but not always available in the final HTML background-size property.
-
Parameters to Support:
- Explicit
widthandheight: Keywords likewidth: 300pxorh: 50%. - Shorthand
wandh: e.g.,w:300px. - Positional arguments: e.g.
![bg 50%]or![bg 300px 200px]. The script will need to parse the original markdown to get these.
- Explicit
-
Goal: Correctly position and scale images that use these markdown-specific parameters.
-
Content Area Shrinking:
- For split backgrounds, shrink the content area as Marp does, so content is not covered by split backgrounds.
Install and run tool
Run as module without installing:
python -m marp2pptx --help
Install locally and run:
uv pip install -e .
marp2pptx --help
to unsinstall:
uv pip uninstall marp2pptx
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file marp2pptx-0.1.2.tar.gz.
File metadata
- Download URL: marp2pptx-0.1.2.tar.gz
- Upload date:
- Size: 36.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.15 {"installer":{"name":"uv","version":"0.9.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f40dbe2c607e0b53217f7568911449a4b86c31c0264f8be08bf504e854dd6e1
|
|
| MD5 |
b958bb0db61f8a0283c00aba2db1b558
|
|
| BLAKE2b-256 |
e69bd20a1500e41d002d887d1c1cbc6d87c2c1090ea1fa9ca47f7b70256c5cfd
|
File details
Details for the file marp2pptx-0.1.2-py3-none-any.whl.
File metadata
- Download URL: marp2pptx-0.1.2-py3-none-any.whl
- Upload date:
- Size: 26.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.15 {"installer":{"name":"uv","version":"0.9.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8693921cdb1f7c378be05e00b2e0002ec1c7100b8bee5c73f4465e9afda3ab7e
|
|
| MD5 |
c2b4ac72e9d7c32cfa4d67454ea9c5b7
|
|
| BLAKE2b-256 |
90cb7e1dbff107191269a8bef6c1f84751c5bc8b1347594df51839d7cb57403a
|