Repository navigation
Use uploaded image dimensions in Markdown image nodes - #94
Open
MattFisher wants to merge 1 commit into
Open
MattFisher wants to merge 1 commit into
MattFisher wants to merge 1 commit into
Conversation
Local images in Markdown were always recorded as 1456x819 with no byte size or content type, whatever the real file was. Substack's upload response already reports imageWidth, imageHeight, bytes and contentType, so carry those into the image2 node. Dimensions are only used as a valid pair; otherwise the previous placeholder size is kept. Co-Authored-By: Claude <noreply@anthropic.com>
This was referenced Nov 16, 2026
This branch has not been deployed
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.
Local images in Markdown are always recorded as 1456×819 with no byte size or content type, whatever the file really is. This PR takes those values from Substack's upload response instead.
The problem
nodes.captioned_image()hard-codes"width": 1456, "height": 819, "bytes": None, "type": None.Api.get_image()already returns the real values (imageWidth,imageHeight,bytes,contentType), but_captioned_image()inmdrender.pyonly keeps theurl.For example, a 1440×3576 PNG pushed with
from_markdown()was stored as:{"width": 1456, "height": 819, "bytes": null, "type": null}With this change the same image is stored as:
{"width": 1440, "height": 3576, "bytes": 418331, "type": "image/png"}The change
nodes.captioned_image()gains optionalwidth,height,size_bytesandmime_typearguments. The defaults are the old values, so existing callers get the same node as before._captioned_image()passes the upload response's values through for local images.Remote image URLs are untouched: nothing is uploaded for them, so their size is still unknown and they keep the placeholder.
Testing
test_local_markdown_images.pycover the happy path and the fallback for missing, partial, zero, string and boolean dimensions.pytest -q -m "not live" --strict-markers: 298 passed.image/png.Note
#95 touches the lines next to this one in
mdrender.py, so whichever of the two is merged second will need a small rebase. I'm happy to do that.🤖 Generated with Claude Code