On Tue, May 1, 2018 at 4:54 PM, Lars Ingebrigtsen wrote: > 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
    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
      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 > > > > The question is if it is worth the effort? To me the greatest benefit of a WYSIWYG editor would be if I could edit in the "finished" website eg. sort of like editing the elements in the developer tools of chrome/firefox. That means CSS has to be supported, and potentially also javascript. If a website is only HTML it is easy enough for me to visualize how it is going to look. Besides HTML rarely stands alone now a day, it is most likely consumed by some tool and or combined with CSS (or something compiled to CSS) and javascript (or something compiled to javascript). And in a lot of cases i do not edit actual HTML but some templating system complicating the issue even further. I personally think something like skewer where a browser is updated to reflect the current state is a lot more useful, though I havent found a way to make it work fluidly when doing more complex backends. Building a WYSIWYG editor in Emacs sounds like a complicated affair and I am not sure it is really worth it as editing plain standalone HTML is becoming a niche thing. It could be useful for HTML emails though!