Skip to content

fix(YfmHtmlBlock): preserve nested html block serialization#1162

Merged
makhnatkin merged 1 commit into
mainfrom
fix-yfm-html-block-serialization
Jun 26, 2026
Merged

fix(YfmHtmlBlock): preserve nested html block serialization#1162
makhnatkin merged 1 commit into
mainfrom
fix-yfm-html-block-serialization

Conversation

@vanilla-wave

@vanilla-wave vanilla-wave commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Serialize YFM HTML block srcdoc line-by-line so nested blockquote and list delimiters are preserved.
  • Treat the parser-provided final newline as structural while preserving intentional trailing blank content.
  • Add regression coverage for blockquote, list item, and trailing blank-line serialization.

Test Plan

  • Containerized targeted Jest: pnpm --filter @gravity-ui/markdown-editor test -- src/extensions/additional/YfmHtmlBlock/YfmHtmlBlock.test.ts
  • Containerized ESLint: pnpm exec eslint packages/editor/src/extensions/additional/YfmHtmlBlock/YfmHtmlBlock.test.ts packages/editor/src/extensions/additional/YfmHtmlBlock/YfmHtmlBlockSpecs/index.tsx
  • git diff --check

Notes

  • Verified the regression by reverting only the serializer change in an isolated container copy and confirming the new nested serialization tests fail.

Summary by Sourcery

Preserve correct markdown serialization of YFM HTML blocks, including nested usage and trailing blank lines.

Bug Fixes:

  • Fix markdown serializer to keep nested YFM HTML blocks inside blockquotes and list items from breaking blockquote/list delimiters.
  • Fix markdown serializer to retain intentional trailing blank lines in YFM HTML block content.

Tests:

  • Add regression tests covering multiline YFM HTML blocks within blockquotes and list items and cases with trailing blank lines in content.

@sourcery-ai

sourcery-ai Bot commented Jun 25, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adjusts Yfm HTML block Markdown serialization to be line-based so nested blockquotes/lists and trailing blank lines are preserved, and adds regression tests around these cases.

File-Level Changes

Change Details Files
Update Yfm HTML block Markdown serializer to emit srcdoc content line-by-line while preserving structural final newline and intentional trailing blank lines.
  • Strip only the parser-provided final newline from srcdoc before serialization to avoid duplicating structural newlines.
  • Write the opening ::: html fence followed by a guaranteed newline.
  • Emit srcdoc text via state.text without rewrapping, then reinsert a newline when srcdoc ends with a newline and the serializer is at a blank position.
  • Ensure a final newline after srcdoc content before writing the closing ::: fence.
  • Close the block as before using state.closeBlock.
packages/editor/src/extensions/additional/YfmHtmlBlock/YfmHtmlBlockSpecs/index.tsx
Extend Yfm HTML block tests to cover serialization inside blockquotes and list items, and to assert preservation of trailing blank lines.
  • Register BlockquoteSpecs and ListsSpecs in the ExtensionsManager used by the test suite so nested structures can be built.
  • Extend builders to include doc, blockquote, bullet list, list item, and yfmHtmlBlock nodes for constructing nested test documents.
  • Add tests for multiline yfmHtmlBlock inside a blockquote and inside a list item to verify proper Markdown serialization.
  • Add tests to confirm trailing blank lines in yfmHtmlBlock content are preserved in both top-level and blockquoted contexts.
packages/editor/src/extensions/additional/YfmHtmlBlock/YfmHtmlBlock.test.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • The newline handling in toMd (stripping with replace(/\n$/, '') and then checking srcdoc.endsWith('\n')) is non-obvious; consider extracting this into a small helper or adding an inline comment to clarify which trailing newlines are treated as structural vs content.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The newline handling in `toMd` (stripping with `replace(/\n$/, '')` and then checking `srcdoc.endsWith('\n')`) is non-obvious; consider extracting this into a small helper or adding an inline comment to clarify which trailing newlines are treated as structural vs content.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@gravity-ui

gravity-ui Bot commented Jun 25, 2026

Copy link
Copy Markdown

Storybook Deployed

@gravity-ui

gravity-ui Bot commented Jun 25, 2026

Copy link
Copy Markdown

🎭 Playwright Report

@vanilla-wave vanilla-wave force-pushed the fix-yfm-html-block-serialization branch from f447993 to a25819f Compare June 25, 2026 10:47
@makhnatkin makhnatkin changed the title fix: preserve nested html block serialization fix(YfmHtmlBlock): preserve nested html block serialization Jun 26, 2026
@makhnatkin makhnatkin merged commit 58dffe0 into main Jun 26, 2026
8 checks passed
@makhnatkin makhnatkin deleted the fix-yfm-html-block-serialization branch June 26, 2026 13:54
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