-1

edit html option on Stackoverflow

Does wagtail CMS support the ability to edit rich text html code as seen in the screenshot?

sine1son
  • 1
  • 1

1 Answers1

1

No, editing HTML source is not available from Wagtail's built-in Draftail rich text editor. This is because its internal representation of the edited text is not HTML, but its own data structure where entities like links and inline styles are tracked alongside the text, rather than part of the text itself. There isn't a direct correspondence between things that can be represented in this data structure, and things that can be written as HTML.

(Alternative rich text editors might be available as third-party packages that do offer HTML source editing, but I'm not aware of the status of whether they're actively maintained.)

This might seem like a needless restriction, but there are good technical reasons behind it:

  • It means that images and page links (and anything else that references other objects managed by Wagtail) can be stored as database IDs instead of URLs, so that if those objects change URL as a result of user edits, it won't result in a broken link.
  • When pasting content from a Word document, there will often be unwanted formatting embedded in it, such as setting the font to Times New Roman. Having a data format that distinguishes between the meaningful 'structural' aspects of the content (headings, links, bold / italic spans...) and the cosmetic ones (style attributes) ensures that these are stripped out.
  • Some things we want to represent in rich text, such as Youtube embeds, don't have known predictable HTML representations. It's useful for the data format to be able to store these as "a video embed for URL X" rather than "an <iframe> tag with some obscure collection of attributes" - if it was stored as the latter, you'd run into issues of how far a user can edit the HTML before it ceases to be recognisable as a Youtube embed.
gasman
  • 23,691
  • 1
  • 38
  • 56