Support Marpit  syntax for slide background images#131
Merged
jongalloway merged 3 commits intomainfrom Mar 15, 2026
Merged
Support Marpit  syntax for slide background images#131jongalloway merged 3 commits intomainfrom
 syntax for slide background images#131jongalloway merged 3 commits intomainfrom
Conversation
Co-authored-by: jongalloway <68539+jongalloway@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
jongalloway
March 14, 2026 23:35
View session
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds Marpit-style background image support via Markdown image alt text (), promoting those images to SlideStyle.BackgroundImage so they render as full-slide backgrounds rather than inline image elements.
Changes:
- Update the core Markdown parser to detect
images (case-insensitivebg) and set the slide background image accordingly, removing those images from slide elements. - Update/extend parser and renderer tests to assert the new
![bg]background behavior and precedence withbackgroundImagedirectives. - Update documentation to describe the supported subset and precedence rules for background images.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/MarpToPptx.Tests/PptxRendererTests.cs | Adjusts/extends renderer assertions so ![bg] results in a background picture (empty Description) and validates directive-vs-syntax behavior. |
| tests/MarpToPptx.Tests/ParserTests.cs | Updates the prior “bg keyword as alt text” expectation to “sets slide background”, and adds a suite of ![bg] parser behavior tests (precedence, element removal, case-insensitivity, first-only). |
| src/MarpToPptx.Core/Parsing/MarpMarkdownParser.cs | Implements promotion of  images to SlideStyle.BackgroundImage and skips adding those images as inline elements. |
| doc/marp-markdown.md | Documents  support, limitations (modifiers not parsed, first-only), and background image precedence. |
You can also share your feedback on Copilot code review. Take the survey.
| foreach (var element in ParseElements(cleaned)) | ||
| foreach (var element in allElements) | ||
| { | ||
| if (bgImages.Contains(element)) |
Comment on lines
+116
to
+125
| // Promote any  images to slide background image. | ||
| // Only exact "bg" alt text (case-insensitive) is recognized in this slice. | ||
| // A directive-specified backgroundImage always takes precedence. | ||
| var bgImages = allElements | ||
| .OfType<ImageElement>() | ||
| .Where(img => IsBgAltText(img.AltText)) | ||
| .ToList(); | ||
|
|
||
| if (bgImages.Count > 0 && string.IsNullOrWhiteSpace(effectiveStyle.BackgroundImage)) | ||
| { |
Owner
|
@copilot apply changes based on the comments in this thread |
…ntax promotion Co-authored-by: jongalloway <68539+jongalloway@users.noreply.github.com>
Contributor
Author
Both issues from the review are fixed in 05985e7:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
was treated as a normal inline image instead of a slide background. This adds parser recognition of thebgalt-text marker and wires it into the existing background rendering path.How it works
is now promoted toSlideStyle.BackgroundImageduring parsing and removed from the slide element list — the image renders identically to a<!-- backgroundImage: url -->directive.Changes
Parser (
MarpMarkdownParser.cs)ParseElements(), collects anyImageElementwith alt text exactly"bg"(case-insensitive)SlideStyle.BackgroundImageunless a directive has already set itbg-marker elements from the slide element listPrecedence
<!-- backgroundImage: ... -->/ front-matter) >syntax > theme CSSappear on one slide, only the first is used; split-background layouts are not yet supportedTests
Docs (
doc/marp-markdown.md)bg cover,bg contain,bg left,bg right, percentage sizing, split layouts)