Automatically Added <p> Tags in Limited RichText Field

Vote:
 

I am working with a TestBlock in Optimizely CMS 12 and trying to configure the Title field with limited RichText settings. The Title field is defined as follows:

[CultureSpecific]
[Required]
[Display(Name = "Title", Order = 20, GroupName = CmsTabNames.Content)]
public virtual XhtmlString Title { get; set; }

My goal is to prevent TinyMCE from wrapping the content in <p> tags. However, despite configuring the forced_root_block setting, TinyMCE still automatically adds <p> tags when I add text to the field. Below is the configuration I am using:

context.Services.Configure<TinyMceConfiguration>(config =>
{
    // Text Styles
    var textStyles = new
    {
        title = "Text",
        items = new object[]
        {
            new { title = "Small Text", block = "small" },
            new { title = "Blockquote", block = "blockquote" }
        }
    };

    // Default configuration
    config.Default()
        .Height(200)
        .AddEpiserverSupport()
        .ContentCss("/assets/css/editor.css")
        .AddPlugin("table")
        .RemovePlugin("paste")
        .AddExternalPlugin("powerpaste", "/plugins/powerpaste/plugin.js")
        .Menubar("edit table")
        .AddSetting("paste_enable_default_filters", false)
        .AddPlugin("epi-link code epi-image-editor epi-dnd-processor epi-personalized-content media wordcount anchor textcolor colorpicker preview paste")
        .Toolbar("formatselect styleselect | bold italic underline strikethrough subscript superscript | alignleft aligncenter alignright alignjustify | numlist bullist indent outdent | " +
                 "table | epi-link anchor | image epi-image-editor media | epi-personalized-content | removeformat | searchreplace fullscreen preview | code | help")
        .StyleFormats(textStyles)
        .BlockFormats("Paragraph=p;Heading 1=h1;Heading 2=h2;Heading 3=h3;Heading 4=h4;Heading 5=h5;Heading 6=h6");

    // Limited RichText settings
    var limitedRichTextSettings = config.Default().Clone()
        .AddEpiserverSupport()
        .ContentCss("/assets/css/editor.css")
        .AddSetting("forced_root_block", "")
        .AddSetting("force_br_newlines", false)
        .AddSetting("force_p_newlines", false)
        .AddSetting("statusbar", false)
        .AddPlugin("code wordcount preview") // add epi-link anchor if links are needed
        .Toolbar("bold italic underline subscript superscript | code") // add epi-link anchor if links are needed
        .BlockFormats("");

    config.For<TestBlock>(m => m.Title, limitedRichTextSettings);
});

Problem: Even with these settings, the editor still wraps the content in <p> tags.

Could someone advise on how to properly configure TinyMCE to prevent it from adding these <p> tags in this context?

#326887
Edited, Aug 12, 2024 5:38
Vote:
 

Hi,

Actually, empty value for "force_root_block" is invalid => Still get "p" as default value in this case. "force_br_newlines" and "forced_p_newlines" seems be legacy. You can use this setting to use "br" instead of "p" once breaking new line

 config.Default().Clone()
     .AddSetting("newline_behavior", "linebreak");
#327419
Aug 13, 2024 13:03
Kumar - Aug 13, 2024 16:17
Still it's adding

tag

Binh Nguyen Thi - Aug 13, 2024 16:57
You meant that p tag is still being added?
Kumar - Aug 14, 2024 6:04
Yes still it's adding "p" tag
Binh Nguyen Thi - Aug 14, 2024 6:10
Not sure what you mean about this "
" tag
I said that we can change p tag by "br" tag once breaking new line by my suggestion. If you do not want to have any new line inserted include either "br" or "p" then it seems impossible. It is WYSWYG. When you enter to make new line then it should be displayed as a new line by inserting "br", or "p" or "div" or other tag.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.