Images In Leo Nodes - A Way To Make Them Work

15 views
Skip to first unread message

Thomas Passin

unread,
Oct 23, 2024, 7:25:00 PM10/23/24
to leo-editor
I think many of us would like to be able to stick images into Leo nodes.  It's easy to insert one.  You get the text cursor for the insertion point, give it the image URL, and call insertImage().  The editor component will let you cut and paste the image without any other code being written.

For Leo nodes the main problem I see is how to restore the image when the outline is saved and re-opened.  To get a text representation of the editor's contents, one calls toPlainText() on the editor. There is no image encoded in the plain text, but Qt does insert a special marker character in place. This unicode character will not be used in any normal text.  On save, we can add the image url for a marker right after it, perhaps like this (using "x" to represent the marker):

x[[image1.png]]

When we want to reload the outline, we scan though the node, pick up these markers, and remove the URL string, get the cursor for that position, and use it to insert the image.

The parts of this scheme that I have tested so far are to insert an image and to observe the special marker character in the toPlainText() output. The other steps seem doable, but you never know for sure until you get into the details.

Edward K. Ream

unread,
Oct 23, 2024, 7:40:31 PM10/23/24
to leo-e...@googlegroups.com
I remember doing exactly what you describe above several years ago. I gave up in frustration, but I don't remember why.

Edward
Reply all
Reply to author
Forward
0 new messages