Copied to clipboard

Flag this post as spam?

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


  • Alex Lindgren 158 posts 355 karma points
    Jan 17, 2018 @ 18:20
    Alex Lindgren
    0

    Rich Text Editor styles for lists

    Is it possible to have a style in the Rich Text Editor apply directly to an list, such as:

    <ul class="list-breaks"><li>...</li></ul> 
    
  • George 27 posts 109 karma points
    Jan 17, 2018 @ 19:14
    George
    0

    I've found it exceedingly difficult to force a style to attach itself to a particular HTML element. Generally, you end up with something like:

    <div class="list-breaks">
        <ul><li>...</li></ul>
    </div>
    

    I usually just update the CSS to accommodate:

    ul.list-breaks,
    .list-breaks ul {
        // styles here
    }
    
  • Alex Lindgren 158 posts 355 karma points
    Jan 17, 2018 @ 19:48
    Alex Lindgren
    0

    A div around the list element would work. Do you edit that in WYSIWIG mode? When I highlight the list items in the editor and apply a style, I get something like this:

    <ul>
    <li><span class="list-breaks">One</span></li>
    <li><span class="list-breaks">Two </span></li>
    <li><span class="list-breaks">Three</span></li>
    </ul>
    
  • George 27 posts 109 karma points
    Jan 17, 2018 @ 20:38
    George
    0

    Ugh. Yeah, sometimes its tough to get the editor to apply the styles the way you want. If you are careful about how much you select and maybe include a line before and/or after the list, you might get it to work.

    However, something as delicate as this might require you to step outside of the editor. Another approach I often use is to just have a standard list style for WYSIWYG editors and wrap the output in the view with a style. Obviously that limits your ability to have different list styles in the same editor. This would mean having a standard list in the editor and something like this in the view:

    <div class="wysiwyg list-breaks">
        @Umbraco.Field("body")
    </div>
    
  • Nicholas Westby 2005 posts 6843 karma points c-trib
    Jan 17, 2018 @ 23:24
    Nicholas Westby
    3

    I have done this before by modifying ~/config/tinyMceConfig.config like so:

    <?xml version="1.0" encoding="utf-8"?>
    <tinymceConfig>
        <customConfig>
            <config key="style_formats">[
                {
                    "title": "Checkmark List",
                    "selector": "ul",
                    "classes": "rich-text--checkmarks"
                }
            ]</config>
        </customConfig>
    </tinymceConfig>
    

    Just a heads up that the quotes in the JSON matter (I think Umbraco doesn't like it if you use unquoted JSON keys).

    In my case, I was trying to make a UL have checkmarks rather than bullet points. If you also want the styles to appear in the back office, you can edit the CSS file that Umbraco creates for tinyMCE rich text editors to include the styles:

    WYSIWYG Styles

    Remember that you'll have to configure your rich text data type to make use of that stylesheet.

  • Gavin Semple 20 posts 91 karma points
    Feb 12, 2018 @ 12:48
    Gavin Semple
    0

    Your solution worked like a charm Nicholas, thank you.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies