emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Musings on creating an HTML-based WYSIWYG mode


From: Lars Ingebrigtsen
Subject: Musings on creating an HTML-based WYSIWYG mode
Date: Tue, 01 May 2018 16:54:51 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

I'm not going to implement this any time soon, but I wondering how much
work it would be to create a WYSIWYG mode for Emacs based on
round-tripping through shr.

I think most people who have approached this subject before have said
"just use some text properties and store as enriched text and there you
go", but it's just not sufficient: If you're writing a <ol> list, then
you want this to be rendered as it should be, and it should be rendered
as the recipient is likely to read the text.  Otherwise it's not very
WYSIWYG, is it?

So: The serialisation format would be HTML.  Whenever a user types
something, Emacs generates HTML, asks shr to render it, and then present
the user with the results.  This would, of course, potentially be
horrifically slow, but we could envision strategies to only re-render
parts of the buffer/document.

Let's say the user is typing away at something resembling this
paragraph, and then decides to make "typing" bold, so the user would go
back to that work, mark it and issue whatever command there is for "make
this bold".  The mode would do the change to the HTML document, ask shr
to re-render it, and then display the results.

This is, of course, not like what Emacs does normally when editing text,
and would break a lot of invariants that people are used to.  We can
preserve basic things like point and mark easily enough (by inserting
special constructs into the HTML that allows us to find and restore them
after re-generating the buffer), but I'm sure there's oodles of stuff
that will stop working with such a radical approach.  But perhaps that's
OK?

Inserting images and the like into the buffer would be unproblematic --
just add a few new dired commands like "copy image to WYSIWYG clipboard"
and then yank from that "clipboard" into the buffer.  This presents
further interesting questions about the serialisation format...  but we
could, for instance, use MIME for that: multipart/related with the
images stashed as cid: links.

"External" images are simpler, of course.

The WYSIWYG clipboard would also be necessary for when cutting and
yanking text: If you're killing text starting from the middle of a link
and ending up in the middle of an <ol> link, you have to ensure that you
end up with something similar when you yank this mess somewhere else.
And you have to ensure that everything remains valid around where you
killed the region, too.

And then there's always the interesting subject of tables, or rather:
Side-by-side continuous regions.  Making editing commands work in those
circumstances may be, er, interesting...

So here's what I think: I think somebody (i.e., me) should try
implementing this.  I think there are so many unknowns here that it's
difficult to say whether this is a workable way of doing WYSIWYG in
Emacs before you have something semi-working and get a grip on how this
would feel in practice.  

But like I said, I don't have time at the moment.  :-)

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





reply via email to

[Prev in Thread] Current Thread [Next in Thread]