enhancement
major
defect
major
minor
minor
#29699
TL-Script: htmlText(htmlSource($text), images) drops the images of a stored structured text, since it does not accept the "ref:" references it writes itself
Problem
htmlText(html, images) (#29683, HtmlFunctions.text) stores an <img src="name"> that names one of the given images as the image reference <img src="ref:name">. htmlSource(text) (HtmlFunctions.source) returns that stored source unchanged, ref: included.
A script that rewrites a stored text (reads its source, changes it, writes it back with the same images) therefore calls
htmlText($changed, images: $attachments)
with a source whose image elements say src="ref:name". text() matches the src values only against the plain names of the given images, so none of them is referenced: every image is dropped, and the elements keep pointing at ref:name references the new structured text does not have. The written-back text shows no images.
Seen in the TL Development app (snapshot build 43): the Trac sync's pass 3 rewrites stored ticket descriptions and comments (cross-reference links) through htmlText(…, images: …). It has to turn every ` src="ref:` back into ` src="` before the call, or the images synced in pass 1 are lost.
Expected
htmlText(source, images) accepts a src="ref:name" as a reference to the given image name just like src="name", so that htmlText(htmlSource($t), images) round-trips a stored structured text. (There is also no function answering the images of a structured text, e.g. htmlImages($t); with one, a script could write back a changed source with the text's own images instead of reassembling them.)
Lösung
htmlText(source, images) akzeptiert Bildverweise: Ein <img src="ref:name"> verweist wie <img src="name"> auf das angegebene Bild name; das Bild bleibt erhalten, das Element behält den Verweis. Ein ref:-Verweis auf ein nicht angegebenes Bild bleibt unverändert. Die Änderung liegt in I18NStructuredTextUtil.linkImageSources und gilt damit auch für den Dokumentations-Import (ImportCommand).
Neue TL-Script-Funktion htmlImages(text) (HtmlFunctions.images): liefert die Bilder eines strukturierten Textes als Dictionary Name → Binärwert (leer für einen Text ohne Bilder). Damit lässt sich ein gespeicherter Text geändert zurückschreiben:
htmlText(htmlSource($text) ..., images: htmlImages($text))
Test
- test.com.top_logic.layout.wysiwyg.ui.TestHtmlFunctions, TestHtmlFunctionsScript