Repository navigation
feat(content): a rewrite_link hook and embedded image helpers for the reader (0.4.3) - #10
Merged
Merged
Conversation
… reader (0.4.3) A caller that mirrors memos to another system has to recognise the images a memo embeds and decide what they become, without parsing HTML or Markdown itself. EasyVista's editor keeps a pasted image as an attachment of the request and embeds it as <img src="@@EMBEDDED_IMAGE_PATH@@<DOCUMENT_ID>">, which the reader wrote as an image that displays nowhere else. - from_transport(..., rewrite_link=callback) calls the callback with a Link for each link and image met outside code, an image before the link around it (enclosing_href). Its answer is written: None keeps the reader's output, a str is literal text escaped as a text node, a Link replaces the target, and an empty href drops a link (content kept) or writes an image as its text. Without the argument a read is unchanged, byte for byte. - The callback lives in a ContextVar, so threads and tasks each read with their own, and a read inside a callback has its own. What it raises reaches the caller unchanged: carried past the reader's ValueError text fallback, which would otherwise have taken a callback's ValueError for markdownify's and quietly dropped the body's formatting. - document_id_of(src) and document_image(document_id, alt=...): the second is spelled by the reader itself, so from_transport(to_transport(x)) == x. Measured on one instance on 2026-10-07: an image written that way through the API displays, for an attachment pasted in the editor and for one uploaded with add_document. The upload's id has another shape than a pasted one's; the id class covers both. Tests: test_rewrite_link.py (none-answer parity over the round-trip corpus, offer order, each answer kind, code skipped, exceptions, threads, nesting, helpers). 21 mutants of the new guards, all killed. Full suite 2304 passed; mypy, ruff, sync lint and sphinx -W clean. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #10 +/- ##
==========================================
+ Coverage 98.93% 98.96% +0.03%
==========================================
Files 40 40
Lines 2617 2694 +77
==========================================
+ Hits 2589 2666 +77
Misses 28 28 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Why
A caller that mirrors memos into another system has to recognise the images a memo embeds and decide what they become, without parsing HTML or Markdown itself. EasyVista's editor keeps a pasted image as an attachment of the request and embeds it as
<img src="@@EMBEDDED_IMAGE_PATH@@<DOCUMENT_ID>">. The reader wrote that as an ordinary image, which displays nowhere but in EasyVista.What
from_transport(..., rewrite_link=callback)calls the callback with aLinkfor each link and image met outside code. An image is offered before the link around it, which it names asenclosing_href, and an embedded image carries itsdocument_id. The answer is written:None: the reader's own output;str: literal text, escaped as a text node, so it cannot become markup;Link: replaces the target;Linkwith an emptyhref: drops a link (its content is kept), or writes an image as its text.ContextVar. Threads and tasks each read with their own, and a read inside a callback has its own too.ValueErrortext fallback, which would otherwise take a callback'sValueErrorfor markdownify's and quietly drop the body's formatting. An answer of another type raisesTypeError.document_id_of(src)anddocument_image(document_id, alt=...). The second is spelled by the reader itself, sofrom_transport(to_transport(x)) == x.Link,RewriteLinkandEasyvistaContentConverter.EMBEDDED_IMAGE_PREFIXare now exported.docs/content.rst) and CHANGELOG updated; the version is 0.4.3.Measured on one instance on 2026-10-07: an image written that way through the API displays, both for an attachment pasted in the editor and for one uploaded with
add_document. An upload'sDOCUMENT_IDhas a different shape from a pasted image's, and the accepted id characters cover both.The GLPI twin is baraline/glpi_python_client#42 (0.6.3).
Verification
test_rewrite_link.py: 208 tests.sphinx -Wall clean.🤖 Generated with Claude Code