Skip to content

feat(markdown): resolve embedded asset URLs - #7

Open
henrycunh wants to merge 1 commit into
firecrawl:mainfrom
henrycunh:hcunha/asset-resolver
Open

feat(markdown): resolve embedded asset URLs#7
henrycunh wants to merge 1 commit into
firecrawl:mainfrom
henrycunh:hcunha/asset-resolver

Conversation

@henrycunh

@henrycunh henrycunh commented Aug 4, 2026

Copy link
Copy Markdown

Summary

  • add Rust MarkdownOptions and to_markdown_bytes_with_options for mapping embedded AssetId values to resolved URLs
  • expose the same capability in Node as the optional third argument to toMarkdownBytes
  • render resolved embedded images as ordinary Markdown images at their original document positions
  • preserve the existing alt-text fallback for unresolved assets

Motivation

Document ingestion pipelines often need to extract embedded assets, upload them to their own storage, and then reference those URLs in the final Markdown. Today they can read the bytes through toDocument, but preserving each image's original position requires reimplementing or copying the Markdown serializer.

The new option keeps serialization inside anydoc:

const document = await toDocument(bytes)
const assetUrls = Object.fromEntries(await Promise.all(
  document.assets.map(async (asset) => [
    asset.id,
    await upload(asset.data, asset.mediaType),
  ])
))

const markdown = await toMarkdownBytes(bytes, null, { assetUrls })

Rust callers can use MarkdownOptions::asset_urls with to_markdown_bytes_with_options.

Backward compatibility

  • the existing Rust to_markdown_bytes API is unchanged
  • the Node options argument is optional
  • missing options, an empty map, and unresolved asset ids retain the current output byte-for-byte
  • PDFs are unchanged because they already emit Markdown directly

Validation

  • cargo fmt --all --check
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo test --locked (173 unit tests, robustness test, and 8 snapshot tests passed; one local-samples test remains ignored as expected)
  • cd node && npm run build && npm test (14/14 passed)
  • verified the regenerated TypeScript declaration supports both legacy calls and format = null with options

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

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.

1 participant