Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • JessicaGUA 11 posts 122 karma points
    Jul 10, 2024 @ 10:30
    JessicaGUA
    0

    Umbraco 14 : Rich Text Editor displaying unicode characters

    Update : changing from IContent to IPublishedContent seems to solve this issue. I don't really get the difference and when to use one or another...



    Hi everyone,

    First of all, this is my first time ever posting on a forum because I'm new to development (started in January). Please excuse my lack of experience and if my request may seems dumb. Plus, excuse my grammar/vocabulary errors, I'm French...


    So, I have a problem when I try to display the content of my Rich text Editor. It renders unicodes and HTML tags. I solved the HTML tags' problem by using a Regex. But I don't know what to use for unicodes.

    For example :

    • Text editor contains : Retour en photo du Workshop consacré aux retours d’expériences
    • What is rendered : {"markup":"\u003Cp\u003ERetour en photo du Workshop consacr\u00E9 aux retours d\u2019exp\u00E9riences

    Some context elements; I identify my Document with:

    IContent latestNews = _contentService.GetPagedOfType(
            newsItemTypeId,
            0,
            500,
            out total,
            null
        ).OrderByDescending(x => x.GetValue("publishedDate"))
        .FirstOrDefault();
    

    I display it with:

    string latestNewsContent = Regex.Replace(latestNews.GetValue("content").ToString(), @"<[^>]*>", String.Empty);
    @latestNewsContent
    

    PLEASE : comment with details and a maximum of explanations because, I repeat, I am a newbie... Thank you in advance and feel free to reach me for further informations.

  • Yakov Lebski 591 posts 2346 karma points
    Jul 10, 2024 @ 13:40
    Yakov Lebski
    1

    I think it encoder issues

    in Startup.cs under ConfigureServices or before services.AddUmbraco or in Composer add

         var settings = new TextEncoderSettings(UnicodeRanges.All);
     services.AddSingleton(HtmlEncoder.Create(settings));
    
  • JessicaGUA 11 posts 122 karma points
    Jul 11, 2024 @ 05:36
    JessicaGUA
    100

    Thanks for your message, I will try it. For the moment, changing for a IPublishedContent and looking for Value("content") seems to display the content as expected. Thanks again, have a nice day !

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Jul 11, 2024 @ 09:05
    Sebastiaan Janssen
    2

    Please don't do this Startup.cs modification, this is not the problem! 😅 Instead, Nik has explained the problem nicely.

  • Nik 1614 posts 7260 karma points MVP 7x c-trib
    Jul 10, 2024 @ 14:50
    Nik
    3

    Hi Jessica,

    Firstly, welcome to Our and the Umbraco community :-)

    I wanted to address your additional query around IContent and IPublishedContent.

    The simple rule of thumb is that IContent is what is used by the Umbraco back office and customisations that integrate with that part of the system to update content data. Where as IPublishedContent is what should be being used on the front end of the site, in your Razor Views etc.

    IContent and IMedia represents the raw values of content and media and are accessed via the ContentService and MediaService respectively. These access data via the database directly.

    IPublishedContent represents both Content and Media, and they come from the Published Content Cache (currently NuCache). They are much more performant when querying and rendering out data but they are essentially read-only versions of the currently published data. They also take advantage of Property Value Converters that convert database stored data into more render/user friendly data for the front end - and example of this is the MultiNodeTreePicker property editor. In the database this stores the UDI's of the picked content, however the Property Value Converter will convert it to a list of IPublishedContent.

    Hopefully that helps with your understanding of when you should find yourself using each type? If you have more questions, feel free to ask.

    Thanks

    Nik

  • JessicaGUA 11 posts 122 karma points
    Jul 11, 2024 @ 05:41
    JessicaGUA
    1

    Hey Nik,

    Thank you so much for your kindness through this detailed message. Every explanation is so much appreciated and made some things more easy to understand and use in code.

    I will definitely deeper for every term you have used because I am not really familiar with every single ones... But things are clearer now, thank you so much for that.

    Have a nice day, and again, thanks for the kindness in your explanations and the time you took to write those down.

    Jessica

Please Sign in or register to post replies

Write your reply to:

Draft