What's the easiest way to escape HTML rich text syntax in Unity? - unity3d

Unity texts have that feature where certain HTML-style tags can be used to format text, like <b></b> for bold and <color=#ff0000></color> for colored text. Sometimes I see some Unity games display user-provided text (like a nickname or a chat message) and they are not escaped, which means the formatting tags get applied if the user types in those tags. Asking for those devs (I don't dev myself), what's the best/easiest way to escape those tags? Are there built-in functions for that, or should they write/import a new function?
Edit: Yes I did look up "C# HTML escaping" and found a function that escapes < into <, but Unity doesn't render < as < and I got <color=#ff0000> nonsense in the Unity scene. Yes I do realize there is a tick box that disables rich text but there is also a use case where, for example, you actually want to use user-provided text within a rich text context.

Both Text and TMP_Text (TextMeshPro and TextMeshProUGui) have according field Rich Text in the Inspector or via code it is Text.supportRichtText and TMP_Text.richText. By default they come enabled.
Yes I do realize there is a tick box that disables rich text but there is also a use case where, for example, you actually want to use user-provided text within a rich text context.
So quite simple
Enable this option in use cases where you want to allow that rich text tags change the format
Disable this option if you do not want it.
As said you can even switch this on runtime via code when needed.
If you want to further prevent your users from being able to putting certain symbols into input fields at all use the according input type and input validation settings (see e.g. InputField)

Related

Display static, selectable text in GTK app

I am trying to build a small GTK 4 app where the user inputs some data, the program does some computations, and it outputs results in a tabular format.
Currently, I have implemented this using a GtkGrid with Label objects showing the results. This works, but a major downside is that the text is not selectable by the user.
Is there a standard Gtk interface for outputting static, selectable text or tables? For example, in the Firefox (whose Linux version is based on GTK) settings page, you can use the cursor to select all the explanatory text.
Searching for "text" in the GTK documentation brings me to the Text Widget Overview page, which is all about multiline text editing. But I don't want my output to be editable—I just want the user to be able to highlight the text and paste it somewhere else if they want.
GtkLabel has a "selectable" property which does just that. It's also mentioned in a separate section of the GtkLabel docs

Creating a Rich Text Editor in Flutter

I am planning to create a rich text editor in Flutter for a personal application. I know there are already some options like zefyr. However, it is still in dev preview and I want to build something a bit different.
The features of the text editor will be that users can add images, bolden text, add lists, italicize text, etc. Just basic text editor things.
Where I am having issues is in the text input side of things. The flutter default text input only allows one style of text per text field. So that would pose a great challenge when it comes to inline styling. Also, a text field cannot have an image inside it, so that is another problem.
If anyone has any ideas on how to go about this, it will be great for a start.
So, I am really asking for the approach to create the editor because it is not as simple as creating one in html

How to use Rich Text Editor in AEM web page

I am creating a form, and in that I need to input some text and I want to use Rich Text editor in it.
When that page is published, then the user must be able to enter the text using that rich text format, i.e. Bold, italics, bullet number list etc .
How can i use the AEM rich text editor in it. I know I can include any other free editor available in the market.
I like to know that how can I use the rich text editor which is used in dialog by AEM?
You need to use a existing richtext editor in front end side like a field in the form. For example: wysihtml5

need to style input from a form with css in real time

Ok im struggling to find anything on this as im probably searching the wrong keywords.
I have a backed form thats use to display content on a page. When entering the details i want to be able to use a basic text editor to style the text, like bold, bullets, underline.
On top of that i would also like to allow them to wrap section in paragraph tabs, apply a certain style i.e style id="x".
Its more for backend so it doesnt have to be really user friendly but if there was an uncomplicated way of showing the styles in the form as i apply them, basically a WYSIWYG view. If not i will settle for applying the styles without having to see all the hmtl and css tags in the editor but when the information is passed via the INSERT query it will show pass all the relevant code like My Style and so on.
Now im quite happy to spend the time learning how to do this if you point me in the right direction but i have no idea what keywords to search. Ideally if there is a script out there i can just edit to my needs would be great too rather than starting from scratch.
Finally since im learning php and mysql still keeping it dumbed down will help and also since my values im passing is going to be full of characters the code wont like what functions should i look up to pass the code and content into the database to avoid breaking the code
I'm not entirely sure what you mean, but it seems you can achieve what you want using an editor like for example TinyMCE in combination with JQuery?
With JQuery you can show/hide items and ander your css like
$("p").mouseover(function () {
$(this).css("color","red");
});

Text editing best practices (with tags, etc.)

I want to create a text field with some text, that is styled with tags. Think of MS Word, some ext is bold, some is a headline, etc. The tags that style the text are not visible to the user, he just sees the text in bold.
How do I preserve these tags? I mean when I backspace over the closing bold-tag, for example, how do I preserve that and prevent that the rest of the text is now bold until the end?
I guess this is a pretty basic question for experiences programmers. Are there any algorithms or best practices? This problem surely has been solved before, any pointers?
(If this is of any concern, I develop for the iPhone OS and the text field will be a UITextView, but my question is more general I guess.)
Thanks in advance!
Rather than thinking of the styles as open/close tags embedded in the text, think of them in terms of NSRanges and adjust them accordingly.
As of 3.2 you can use NSAttributesString. Even if you roll your own, it is a good reference.
An attribute is applied to a range of characters. When characters are added or removed, the ranges are adjusted accordingly.
Tags are for a flattened format like HTML or RTF. In memory during editing you need complex data structures like DOM or NSAttributedString.