Skip to content

feat: add native styling support for fenced div blocks (:::classname)#65

Merged
forest6511 merged 1 commit into
mainfrom
feature/fenced-div-support
Mar 15, 2026
Merged

feat: add native styling support for fenced div blocks (:::classname)#65
forest6511 merged 1 commit into
mainfrom
feature/fenced-div-support

Conversation

@forest6511
Copy link
Copy Markdown
Owner

Summary

  • Implements Issue Feature Request: Native styling support for fenced div blocks (workbook/exercise zones) #63: fenced div blocks (:::classname ... :::) can now be styled natively via YAML preset configuration, eliminating the need for post-processing scripts
  • Background shading is applied to all child paragraphs, headings, lists, and table body cells
  • Optional top/bottom separator borders delimit the zone boundary
  • 282 → 287 tests passing (5 new unit tests)

YAML configuration example

Styles:
  FencedDivs:
    try:
      BackgroundColor: "F2F2F2"
      BorderTopColor: "AAAAAA"
      BorderTopSize: 4
      BorderBottomColor: "AAAAAA"
      BorderBottomSize: 4
    hint:
      BackgroundColor: "EBF5FB"

Markdown usage

:::try
**Exercise heading**

| Item | Fill in |
|------|---------|
| Today's event |  |

Write above, then proceed to the next step.
:::

Implementation notes

  • Markdig.UseAdvancedExtensions() already includes UseCustomContainers() — no parser change needed
  • TableStyle.BodyCellBackgroundColor (nullable) applies div background to table body cells
  • When a div starts/ends with a table, invisible spacer paragraphs carry the separator borders
  • Unrecognized class names render without visual treatment (graceful degradation)

Test plan

  • AddFencedDiv_WithParagraphOnly_ShouldApplyBackgroundAndBorders
  • AddFencedDiv_WithMultipleParagraphs_TopBorderOnFirstBottomBorderOnLast
  • AddFencedDiv_WithNoBorderColors_ShouldApplyOnlyBackground
  • AddFencedDiv_WithTableBodyCell_ShouldApplyBackgroundShading
  • AddFencedDiv_WithEmptyContent_ShouldAddNoParagraphs

Closes #63

Implements Issue #63. Fenced div blocks (:::classname ... :::) can now be
styled via YAML preset configuration without post-processing scripts.

## YAML configuration

    Styles:
      FencedDivs:
        try:
          BackgroundColor: "F2F2F2"
          BorderTopColor: "AAAAAA"
          BorderTopSize: 4
          BorderBottomColor: "AAAAAA"
          BorderBottomSize: 4
        hint:
          BackgroundColor: "EBF5FB"

## Implementation

- FencedDivStyle / FencedDivContent models (Core)
- FencedDivClassConfig + FencedDivs dict in StyleConfiguration (Styling)
- ApplyFencedDivStyle() in StyleApplicator
- AddFencedDiv() in OpenXmlDocumentBuilder:
  - Background shading on all child paragraphs/headings/lists
  - Top separator border on first block, bottom on last block
  - Body cell background shading on tables (via TableStyle.BodyCellBackgroundColor)
  - Spacer paragraphs injected when div starts/ends with a table
- CustomContainer case in Program.cs (Markdig UseAdvancedExtensions already
  includes UseCustomContainers, so no parser change required)
- 5 new unit tests: 282 → 287 passing

Closes #63
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 15, 2026

Codecov Report

❌ Patch coverage is 50.92025% with 80 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.06%. Comparing base (c92d362) to head (fd3c050).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...kdownToDocx.Core/OpenXml/OpenXmlDocumentBuilder.cs 58.87% 36 Missing and 8 partials ⚠️
.../MarkdownToDocx.Styling/Styling/StyleApplicator.cs 0.00% 20 Missing ⚠️
...arkdownToDocx.Styling/Models/StyleConfiguration.cs 16.66% 10 Missing ⚠️
...src/MarkdownToDocx.Core/Models/FencedDivContent.cs 37.50% 5 Missing ⚠️
...n/src/MarkdownToDocx.Core/Models/FencedDivStyle.cs 93.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #65      +/-   ##
==========================================
- Coverage   94.21%   89.06%   -5.15%     
==========================================
  Files          25       27       +2     
  Lines        1209     1372     +163     
  Branches      142      174      +32     
==========================================
+ Hits         1139     1222      +83     
- Misses         41      113      +72     
- Partials       29       37       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@forest6511 forest6511 merged commit eb706b1 into main Mar 15, 2026
1 of 3 checks passed
@forest6511 forest6511 deleted the feature/fenced-div-support branch March 15, 2026 23:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Native styling support for fenced div blocks (workbook/exercise zones)

1 participant