Skip to main content
Image persistence saves network-dependent images from Markdown as local files and rewrites their destinations as relative paths. Use it to archive SoMark results, import Markdown into a RAG system or knowledge base, migrate documents to another server or office platform, or view documents on an intranet or offline. This reduces the document’s dependency on remote image URLs, network availability, and access permissions.

Method 1: Request a ZIP during parsing

This method requires the fewest steps. Use it when you have not parsed the document yet or can parse it again. output_formats is an array. It can contain only zip (the ZIP contains the Markdown and images), or it can request both json and zip. After parsing, the API returns the ZIP download URL in data.result.outputs.zip.
1

Prepare the request

Prepare the source document and a SoMark API key. Do not store a real API key in your code repository.
2

Request ZIP and image file output

Include zip in output_formats. When output_formats includes zip, element_formats.image can only be set to file. The example below requests both zip and json outputs:
Python
3

Submit the document and wait

Call the sync parsing endpoint and inspect code in the response. A value of 0 means the request succeeded.
4

Download and inspect the ZIP

Read the URL from data.result.outputs.zip, download and extract the archive, then confirm that it contains Markdown and image files.ZIP URL in the response:ZIP URL in the responseMarkdown and image files after extraction:Markdown and image files after extraction
View the output_formats parameter reference

Method 2: Use the image persistence Skill

Use the somark-localize-images Skill when you already have a .md or .markdown file whose Markdown images or HTML <img> elements still use HTTP(S) URLs. The current implementation is version 1.4.0. It requires Python 3.8 or later and Pillow>=9.4.0,<11.0.0.
1

Install the dependency

Install the dependency from the Skill directory you received:
2

Trigger the Skill with natural language

In a Skill-capable agent, enter a prompt such as:
3

Process one file

You can also run the bundled script directly:
If you omit -o, the script creates a directory beside the input using the source filename. For example, result.md defaults to result/.
4

Process a directory

Pass a directory to recursively process all .md and .markdown files. Each document receives an isolated package:
Batch mode continues after an individual document fails. It returns a nonzero exit code and lists the failed files. Do not put the batch output directory inside the input directory.
Before:
Remote image link before processing After:
Local relative image link after processing A single-file package has this structure:
To verify the result, confirm that the command exits with code 0, target images in main.md use ./images/image_NNN.jpg, and every referenced image exists and is nonempty. Finally, open main.md in a local Markdown viewer and confirm that the images render. Persisted Markdown images rendered offline
The Skill detects image formats from their content, decodes each image, and re-encodes every output as JPEG. Transparent areas use a white background. A repeated URL is downloaded once. The Skill writes the new main.md only after every image succeeds, and it never modifies the source Markdown.

Download and file protection options

  • Each HTTP request has a 60-second timeout and 3 retries by default. For a slow network, use --workers 2 --timeout 120 --retries 5.
  • Each image has a default 100 MB size limit. Use --max-image-mb to change it.
  • Use the repeatable --allowed-host <domain> option to restrict downloads. Redirect destinations are checked too.
  • The Skill refuses to overwrite existing Markdown or images with different content. Use --force only when replacement is intentional.
  • The Skill creates a directory package and does not create a ZIP automatically. Compress the verified output separately when needed.

Method 3: Reuse Python code directly

The following is a simplified example for the common single-Markdown-file workflow. It supports HTTP(S) images in Markdown and HTML <img> elements, converts downloaded images to JPEG, writes main.md and images/image_NNN.jpg, and leaves the source Markdown unchanged. Compared with the full Skill, this example omits directory batch processing, domain allowlists, concurrent downloads, maximum image size limits, fenced-code protection, and --force replacement. It refuses to use an existing output directory so that it cannot silently overwrite files. Install the dependency:
Save this complete script as localize_somark_images.py:
Run it:

How to choose

  • You have not parsed the document yet: request a ZIP during parsing.
  • You already have Markdown and use an agent tool: use the image persistence Skill.
  • You need to integrate or modify the logic: reuse the Python code.