Skip to content

Conversation

@CesareIsHere
Copy link

📝 Description

Implements bidirectional image support for ParchmentMarkdownCodec. Previously, images were silently dropped during Markdown encoding. Now images are preserved in both directions: Markdown ↔ Parchment.

✨ What's New

  • Decode: !altBlockEmbed.image(url)
  • Encode: BlockEmbed.image(url)![](url)
  • Round-trip: Images maintain data integrity through conversions

🛠️ Implementation

Decoder

  • Added _imageRegExp pattern and _handleImage() method
  • Processes images before other block elements

Encoder

  • Enhanced handleLine() to detect image embeds specifically
  • Converts to ![](url) format while skipping other embeds

🧪 Tests Added

  • Basic image parsing (with/without alt text)
  • Multiple images
  • Images with surrounding text
  • Encoding and round-trip conversion

📋 Example

// Decode
final doc = parchmentMarkdown.decode('![](https://example.com/img.jpg)');

// Encode
final markdown = parchmentMarkdown.encode(docWithImage);
// Output: "![](https://example.com/img.jpg)\n\n"

✅ Backward Compatible

  • All existing functionality unchanged
  • Other embeds still skipped during encoding
  • All existing tests pass

@codecov
Copy link

codecov bot commented Jun 30, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.78%. Comparing base (5847b01) to head (28f33c4).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #521      +/-   ##
==========================================
+ Coverage   88.69%   88.78%   +0.08%     
==========================================
  Files          63       63              
  Lines       10855    10940      +85     
==========================================
+ Hits         9628     9713      +85     
  Misses       1227     1227              

☔ 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.

@CesareIsHere CesareIsHere marked this pull request as draft July 2, 2025 22:21
@amantoux
Copy link
Member

amantoux commented Aug 1, 2025

@CesareIsHere Thank you for this PR. It is still marked as draft, is this intended?

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.

2 participants