I have a scenario where I have to read the pagesource of the html page and save it as a string. I have to retreive this page source in tinyMCE. When i setcontent of tinyMCE to this string i get \r \n. I want them to appear as line breaks not as string. I tried replacing the strings with but it didn't help. Please if anyone could help
tinyMCE.init({
// General options
mode: "specific_textareas",
theme: "advanced",
width: "100%",
plugins: "pagebreak,paste,fullscreen,visualchars",
entity_encoding: "raw",
remove_linebreaks: false,
init_instance_callback: "customTinyMceInit",
// Theme options
theme_advanced_buttons1: "code,|,bold,italic,underline,|,sub,sup,|,charmap,|,fullscreen,|,bullist,numlist,|,pasteword",
theme_advanced_buttons2: "",
theme_advanced_buttons3: "",
theme_advanced_buttons4: "",
theme_advanced_toolbar_location: "top",
theme_advanced_toolbar_align: "left",
theme_advanced_statusbar_location: "bottom",
valid_elements: "i,sub,sup",
invalid_elements: "p, script",
editor_deselector: "mceOthers"
});
function customTinyMceInit(inst) {
if (window.opener != null && !window.opener.closed) {
var parent = $(window.opener.document).contents();
var Id = queryString["Id"];
var Result = [];
$.ajax({
type: "POST",
url: "/Modules/Management/OnlineTemplateCreation.aspx/GetTemplateByContentId",
data: "{'Id':"+Id+"}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
Result.push(data.d);
alert(Result[0]);
tinyMCE.getInstanceById("RichTextBox").setContent(Result[0]);
}
});
apply source formatting in init
tinyMCE.init({
...
apply_source_formatting : true
});
Try to replace '\r \n' characters with '< br >' in your response data.
function replaceLineBreaks(data) {
var replacedData = data.replace("\r \n", "<br>");
return replacedData;
}
Then try this:
tinyMCE.getInstanceById("RichTextBox").setContent(replaceLineBreaks(Result[0]));
Hope this helps.
This works for [email protected]
tinyMCE.init({
forced_root_block: false,
});
SOURCE: https://www.tinymce.com/docs/configure/content-filtering/#forced_root_block
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With