Skip to content

feat: passing the resolveImageSrc parameter#1186

Open
separatrixxx wants to merge 2 commits into
mainfrom
DOCSTOOLS-6078-md-editor
Open

feat: passing the resolveImageSrc parameter#1186
separatrixxx wants to merge 2 commits into
mainfrom
DOCSTOOLS-6078-md-editor

Conversation

@separatrixxx

@separatrixxx separatrixxx commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Added resolveImageSrc hook.

The host application may store files outside the browser-accessible filesystem (for example, VSCode webview). The relative path ./img.png is not resolved there; the image is not displayed. The callback allows the host to convert src to a displayable URL without changing the Markdown source. resolveImageSrc only affects the displayed src in <img>. Node attributes and serialization in markup
use the original path. ImgSettingsButton and the serializer read node.attrs, so the original path is not distorted.

Summary by Sourcery

Introduce configurable image src resolution for the ImgSize extension to support non-browser-accessible file locations.

New Features:

  • Add resolveImageSrc option to the ImgSize extension to allow hosts to transform image src values before rendering.

Enhancements:

  • Propagate extension options into ImgSize node views via ImgSizeNodeViewOpts, enabling custom image src resolution without changing stored node attributes.

@sourcery-ai

sourcery-ai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds a configurable resolveImageSrc hook to the ImgSize extension so hosts can transform image src values at render time without changing stored node attributes or serialized markup, by threading extension options into the image node view plugin and React node view.

File-Level Changes

Change Details Files
Make ImgSizeNodeView plugin accept options and pass them through reactNodeViewFactory into the ImageNodeView component.
  • Refactor imgSizeNodeViewPlugin into a curried function that takes ImgSizeNodeViewOpts and then ExtensionDeps.
  • Update reactNodeViewFactory call to be generic over ImgSizeNodeViewOpts.
  • Provide extensionOptions to the node view via reactNodeViewFactory configuration.
packages/editor/src/extensions/yfm/ImgSize/plugins/ImgSizeNodeView/index.ts
Introduce ImgSizeNodeViewOpts and use resolveImageSrc to transform the rendered image src while keeping node attrs intact.
  • Define ImgSizeNodeViewOpts type with an optional resolveImageSrc callback.
  • Update ImageNodeView React component props to accept ReactNodeViewProps with ImgSizeNodeViewOpts.
  • Compute src from node attrs via extensionOptions.resolveImageSrc when provided, falling back to the raw src.
packages/editor/src/extensions/yfm/ImgSize/plugins/ImgSizeNodeView/NodeView.tsx
Expose resolveImageSrc in ImgSize extension options and wire it into the node view plugin.
  • Extend ImgSizeOptions with a resolveImageSrc option and document its behavior in comments.
  • Pass opts.resolveImageSrc into imgSizeNodeViewPlugin when registering the plugin in the ImgSize extension.
packages/editor/src/extensions/yfm/ImgSize/index.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 reviewed your changes and they look great!


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 Jul 21, 2026

Copy link
Copy Markdown

Storybook Deployed

@gravity-ui

gravity-ui Bot commented Jul 21, 2026

Copy link
Copy Markdown

🎭 Playwright Report

@makhnatkin

Copy link
Copy Markdown
Collaborator

@separatrixxx Hi! We need to add a new story for the image plugin and create a WYSIWYG demo. Please also add a Diplodoc parameter so we can see the markup mode in the preview.

@makhnatkin makhnatkin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

add demo plz

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