This is a migrated thread and some comments may be shown as answers.

Need Enter key to insert br instead of p tag

11 Answers 1366 Views
Editor
This is a migrated thread and some comments may be shown as answers.
JohnVS
Top achievements
Rank 1
JohnVS asked on 18 Feb 2014, 03:20 PM
I have used a couple other WYSIWYG editors, like CKEditor, and they have a setting to change what the Enter key does. By default, it enters a <p> tag for a new paragraph. But in situations like with HTML emails, you can't use <p> tags, since they don't render consistently in email readers. Instead, you have to use <br /> tags to space things out. At least with CKEditor, there is a setting to change the Enter key's behavior, but I don't see any option for this with Kendo Editor. Is this available, or can it be available? Thanks.

(for reference, here is some explanation of CKEditor's setting: http://stackoverflow.com/questions/3339710/how-to-configure-ckeditor-to-not-wrap-content-in-p-block )

11 Answers, 1 is accepted

Sort by
0
Alex Gyoshev
Telerik team
answered on 19 Feb 2014, 08:30 AM
Hello John,

You can use the defaultTools array to setup the editor tools prior to its initialization. This jsBin sample shows how to completely disable the paragraph command.

Regards,
Alex Gyoshev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
JohnVS
Top achievements
Rank 1
answered on 24 Feb 2014, 10:36 PM
We are using the ASP.NET MVC Wrappers. Is there a way to do this with those wrappers? Or a way to do it after the wrapper has setup the Editor?
0
Alex Gyoshev
Telerik team
answered on 25 Feb 2014, 07:26 PM
Hello John,

You need to use the same JavaScript code, just after the Kendo UI script reference. The wrappers themselves do not provide a method for achieving this. 

Regards,
Alex Gyoshev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Bob
Top achievements
Rank 1
answered on 14 Jul 2014, 07:32 PM
Hi, can you please provide a syntax example for this comment?

"You need to use the same JavaScript code, just after the Kendo UI script reference. The wrappers themselves do not provide a method for achieving this. "
0
Alex Gyoshev
Telerik team
answered on 15 Jul 2014, 12:53 PM
Hello Bob,
  1. Include the Kendo UI scripts, via a script tag
         <script src="kendo.all.min.js"></script>
  2. Change the default handling of the paragraphs in the editor
          var defaultTools = kendo.ui.Editor.defaultTools;
          defaultTools["insertLineBreak"].options.shift = false;
          delete defaultTools["insertParagraph"].options;
  3. Initialize the editor, either with the server-side wrappers or the client-side jQuery plug-in
         @Html.Kendo().Editor() ...
Regards,
Alex Gyoshev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Andrew
Top achievements
Rank 1
answered on 20 Feb 2015, 05:32 PM
Hi Alex,

I did what you instructed to do when using the MVC wrappers and it worked, but when I used the unordered list tool after changing the defaults for the enter key the bullet points started at the top of my text instead of where the cursor was. I have attached a screenshot.

Thank you,
Andrew
0
Alex Gyoshev
Telerik team
answered on 24 Feb 2015, 01:42 PM

Hello Andrew,

Indeed, in this scenario list items are broken with Shift-enter, because this is the responsibility for the paragraph command. If the enter key breaks the list items, this would mean that no line breaks can be used in the list items. What are your expectations about this editing mode?

Regards,
Alex Gyoshev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Dion
Top achievements
Rank 1
answered on 17 Mar 2016, 02:52 PM

Hi Alex,

We would like the following markup when disabling paragraphs but still use a (un)ordered list.

Is this possible with the latest version of the Editor?

Some generic text Some generic text Some generic text Some generic text
<br />
<br />
generic text above unordered list generic text above unordered list generic text above unordered list
<br />
<br />
<ul>
<li>list item 1</li>
<li>list item 2</li>
<li>list item 3</li>
</ul>
<br />
generic text below unordered listt generic text below unordered list

 

cheers, Dion

0
Alex Gyoshev
Telerik team
answered on 18 Mar 2016, 12:36 PM

Hello Dion,

No, this is a limitation of this approach. Line breaks are to be nested (semantically) in the unordered list. If you don't need to have paragraphs in the editor content, keep the default configuration for line breaks and post-process the paragraphs, converting them to <br> tags.

Regards,
Alex Gyoshev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Vince
Top achievements
Rank 1
answered on 23 Mar 2018, 08:41 PM

We implemented this solution, but it take away the ability to justify text. For example, let say I have the words in the editor...

left

right

And I highlight the word left and choose Left Justify and then I highlight the word right and choose Right Justify. Both line get wrapped in a div that is styled to justify right. Is there a way to make the new line char <br /> without taking away the ability to justify each line, because right now it justifies the entire document.

Thanks,

Vince

0
Dimitar
Telerik team
answered on 27 Mar 2018, 12:54 PM
Hello Vince,

The text justifying tools are block commands which apply the format on the entire block and not just the selection (inline format), thus leading to the observed behavior. The same test can be performed in MS Word and you will notice that the behavior is the same as in the Kendo UI Editor.

A suggestion approach to handle this scenario could be to shift the behavior as follows:
<script>
  var defaultTools = kendo.ui.Editor.defaultTools;
 
  defaultTools["insertLineBreak"].options.shift = false;
  defaultTools["insertParagraph"].options.ctrl = true;    
 
  // Initialize the editor ...  
</script>

This way, when enter is pressed a <br> tag will be inserted, but the main difference is that with ctrl + enter, a <p> tag will be inserted which now enables you to insert a block element that allows the current selection to be formatted only and gives the user the ability to decide which approach to use.

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Editor
Asked by
JohnVS
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
JohnVS
Top achievements
Rank 1
Bob
Top achievements
Rank 1
Andrew
Top achievements
Rank 1
Dion
Top achievements
Rank 1
Vince
Top achievements
Rank 1
Dimitar
Telerik team
Share this question
or