Repository navigation
feat(content): a rewrite_link hook and document image helpers for the reader (0.6.3) - #42
Merged
Merged
Conversation
… reader (0.6.3) A caller that mirrors bodies to another system has to recognise the documents a body embeds and decide what they become, without parsing HTML or Markdown itself. GLPI's editor embeds a pasted image from front/document.send.php?docid=N, inside a link to the same URL, which the reader wrote as a linked image that displays nowhere but in GLPI. The twin of easyvista-python-client 0.4.3. - 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); a Link whose URL names a document carries its document_id. 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. The raise-site audit allows the private carrier and that re-raise, since the exception is the caller's own. - document_id_of(url): relative, rooted or absolute, under any path, exactly one docid of ASCII digits, above zero. document_image(document_id, alt=..., itemtype=..., items_id=...): the editor's link-wrapped image, spelled by the reader itself; GlpiValidationError on a bad argument. Tests: test_rewrite_link.py (none-answer parity over the round-trip corpus, offer order, the editor's wrap, URL forms accepted and refused, each answer kind, code skipped, exceptions, threads, nesting, helpers). 33 mutants of the new guards, all killed after one URL case was added. Full suite 1989 passed; mypy, ruff, unasync check 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 #42 +/- ##
==========================================
+ Coverage 97.86% 97.92% +0.05%
==========================================
Files 90 90
Lines 3380 3476 +96
==========================================
+ Hits 3308 3404 +96
Misses 72 72 ☔ 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 bodies into another system has to recognise the documents a body embeds or links, and decide what they become, without parsing HTML or Markdown itself. GLPI's editor embeds a pasted image from
front/document.send.php?docid=N, inside a link to the same URL. The reader wrote that as a linked image, which displays nowhere but in GLPI.This is the twin of baraline/easyvista_python_client#10 (0.4.3): the same hook, with each ITSM's own embedded form.
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. ALinkwhose URL names a document carries itsdocument_id; in GLPI that covers links as well as images. 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. That is how the editor's link around an image collapses.ContextVar, so threads, tasks and nested reads each have their own.ValueErrortext fallback. The raise-site audit allows the private carrier and that re-raise, since the exception is the caller's own.document_id_of(url)accepts a relative, rooted or absolute URL, under any path, with exactly onedocidof ASCII digits greater than zero.document_image(document_id, alt=..., itemtype=..., items_id=...)writes the editor's link-wrapped image, spelled by the reader itself. A bad argument raisesGlpiValidationError.LinkandRewriteLinkare now exported.__version__, skills).Verification
test_rewrite_link.py: 219 tests.sphinx -Wall clean.🤖 Generated with Claude Code