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

[Solved] use get_text() and include line breaks?

3 Answers 166 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Brian Garson
Top achievements
Rank 2
Brian Garson asked on 17 Sep 2009, 06:59 PM
I have 2 rad editors that I'm using to create emails.  The idea is to have one for HTML the other for Plain Text, I've created a custom toolbar button to fetch the data from the HTML editor and insert it into the Plain Text editor.  Is there a way to include the line breaks?

<script type="text/javascript"
//Get Html Content from HTML Editor to The Text Editor -  button on the text editor 
Telerik.Web.UI.Editor.CommandList["GetHtmlContent"] = function(commandName, editor, args) 
   var htmlEditor = $find("<%=HTMLEditor.ClientID%>"); //find the HTML editor 
   
   editor.set_html(htmlEditor.get_text()); //set the new text in Text Editor 
}; 
</script> 

should I be trying to get_html() then converting it to text only somehow?

Thanks!

3 Answers, 1 is accepted

Sort by
0
Brian Garson
Top achievements
Rank 2
answered on 17 Sep 2009, 07:32 PM
I tried this, but I can't seem to get the formatstripper to let me use: "AllExceptNewLines"

<script type="text/javascript"
//Get Html Content button on the text editor 
Telerik.Web.UI.Editor.CommandList["GetHtmlContent"] = function(commandName, editor, args) 
   var htmlEditor = $find("<%=HTMLEditor.ClientID%>"); //find the HTML editor 
   if(confirm("Replace text content?")){ 
        editor.set_html(htmlEditor.get_html()); //replace all content in the Text Editor 
        editor.fire("SelectAll"); 
        editor.fire("FormatStripper", {value : "ALL"}); //strips everything but new lines 
   } 
}; 
</script> 
 

0
Brian Garson
Top achievements
Rank 2
answered on 18 Sep 2009, 08:18 PM
incase anyone is looking for a solution to this, I wrote my own javascript:

<script type="text/javascript"
//Get Html Content button on the text editor 
Telerik.Web.UI.Editor.CommandList["GetHtmlContent"] = function(commandName, editor, args) 
   var htmlEditor = $find("<%=HTMLEditor.ClientID%>"); //find the HTML editor 
   if(confirm("Replace text content?")){ 
        editor.set_html(''); 
        var content = htmlEditor.get_html(); 
        content = content.replace(/<BR>/ig,"#lbr#"); //find all line breaks, replace them temporarily with #lbr# 
        content = content.replace(/(<([^>]+)>)/ig,""); //search and replace all HTML codes with empty 
        content = content.replace(/#lbr#/g,"<BR>");  //put all line breaks back in 
        editor.pasteHtml(content); //replace all content in the Text Editor 
        } 
}; 
</script> 

0
Rumen
Telerik team
answered on 22 Sep 2009, 01:12 PM
Hi Brian,

There is an easier way to strip everything but new lines and it is to pass the following value

ALL_NO_BRAKES to the FormatStripper tool, e.g.

editor.fire("FormatStripper", {value : "ALL_NO_BRAKES"});

Kind regards,
Rumen
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Editor
Asked by
Brian Garson
Top achievements
Rank 2
Answers by
Brian Garson
Top achievements
Rank 2
Rumen
Telerik team
Share this question
or