Customizing images in richtext fields - wagtail

I've added a caption field to a custom image model with the help of this and this. How do I show that caption field in images that are in a richtext field?

This is possible by defining a custom image format - in this case, you'd need to create a subclass of Format that overrides the image_to_html method. There's an example of this here: https://github.com/torchbox/verdant-rca/blob/d9ede994dbd1ef68eaa159ec930fd89a351c1329/django-verdant/rca/image_formats.py#L4-L25
However, I'd strongly recommend using StreamField for this kind of mixed content instead. Images with captions are at the upper end of what's practical within a rich text field, and the behaviour can be a bit glitchy (for example, it's difficult to insert text after an image that's at the end of the field, or before an image at the beginning). It's also not great for separation of content and presentation. With StreamField, your text and image are represented as distinct objects in the admin, and within the template you have full control over the HTML used for them.

Related

Is there a way to view/edit source of richtext in Wagtail?

edit html option on Stackoverflow
Does wagtail CMS support the ability to edit rich text html code as seen in the screenshot?
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.

Maintain semantic Information in WPF FlowDocument

How can i add semantic information to e.g. Run and Paragraph Elements e.g. to mark s.th as headlines or code?
This tagging should also survive save and reload of documents in preferable RTF.
I finally decided to use The Tag Attribute and to Store The document in xaml instead of rtf

WindowsForm custom DataGridViewColumn

I have a Windows Form application where I need to represent in a DataGridView or ListView a list of items which consist of two label and an image. The text of the labels and the image depends on the property values of the object which the row refers to.
Reading many topics it seems that it's easier with the DataGridView defining a new type of column. I followed this topic and this ones but I can't reach the desired output.
Do you have any suggestions or idea?
Thanks!

Is WPF's FlowDocument content user-editable?

I understand and have read about using WPF's FlowDocument to create an XML style document on screen, but is the content presented editable by the user, or is it read only? And, if so, how is this done?
My question mostly centres around the use of the listitem control because it would be nice to be able to edit the order of the list items presented for use in my program, rather than me having to create my own custom control(s).
Regards.
FlowDocuments as objects are editable, if they can be edited in the UI depends on the controls that use them. If you use them in a Page they are not, if you use them in a RichTextBox they are.

Emulating hyperlink functionality in datawindow text fields

The idea is rather simple. Some datawindow (not web datawindow) varchar fields contain detailed descriptions. I was wondering if it is possible to provide the following (wikipedia-like) functionality to users: The ability to click (or dbl-click or whatever) on specific words of the text, while reading (which somehow should be indicated as clickable - it would be perfect if they could be colored blue but I don't think this is possible) and open a relevant window (or response). Do you think something like this could be implemented?
To achieve the colour, you could use a rich text edit style if you're using PB 11.5.
For the hyperlink functionality, I'd try to leverage the Clicked event, trying to identify with SelectedStart() what word has been clicked and then whether or not it is a hyperlink. The column would need to have TabOrder so that a click would place the cursor in the text.
Good luck,
Terry.
if you use a RTF datawindow you can insert hyperlinks (in whatever colour or style you wish)

Resources