I have a configuration (I didn't want it to be wrapped in a paragraph) where I expect newlines in the editor to be submitted as
var richtexteditorConfig = {
selector: 'textarea.tinymce',
forced_root_block: "",
menubar: false,
inline: false,
remove_linebreaks: false,
force_br_newlines: true,
force_p_newlines: false,
convert_newlines_to_brs: true,
branding: false,
plugins: [
'link'
],
toolbar: [
'undo redo | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | numlist bullist | forecolor backcolor casechange permanentpen formatpainter removeformat link' ],
valid_elements: 'p[style],strong,em,span[style],a[href],ul,ol,li',
valid_styles: {
'*': 'font-size,font-family,color,text-decoration,text-align'
}
};
tinymce.init(richtexteditorConfig);
However when I submit the form using a frame it strips out those newlines. It keeps some stuff like bolding and colors but I always lose the newlines. Is there somemething magical I need to do, it needs to be submitted with teh rest of the elements and right now I am just doing:
dojo.require('dojo.io.iframe');
dojo.io.iframe.send({
url: 'MyUrl',
handleAs: "text",
method: 'POST',
form: dojo.byId(formid),
load: function(response, ioArgs){
eval(response);
return response;
},
error: function(response, ioArgs){
console.log('error sending ' + response);
return response;
}
});
seems like it is the
forced_root_block: ""
causing all the problems.
Related
I am configuring TinyMCE inline toolbar and I have set 3 toolbars, one above the other like this:
tinymce.init({
selector: '#myeditablediv',
inline: true,
plugins: ['link', 'lists', 'advlist'],
toolbar1: ' fontfamily fontsize forecolor | advancedButton ',
toolbar2: ' fontfamily fontsize bold italic underline strikethrough forecolor backcolor link',
toolbar3: ' alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | superscript subscript | insert-character ',
setup: (editor) => {
editor.ui.registry.addButton('advancedButton', {
text: 'Avanzado',
onAction: (_) => {
// hide toolbar 2 and 3 here
}
});
},
I want to hide toolbar2 and toolbar3 when clicking "advancedButton" on toolbar1. I tried setting an id to get to them or accessing like "editor" on onAction(). Nothing worked. Please help!
the variable in double brackets comes from a Jinja/Flask template
here is the value of that variable, it is string
'<div id="item" >test</div>'
<script type="text/javascript">
tinymce.init({
selector: 'textarea',
setup: function (editor) {
editor.on('init', function (e) {
editor.setContent("{{editor_content|safe}}");
});
},
plugins: [
'advlist autolink autoresize link image imagetools lists charmap print preview hr anchor pagebreak spellchecker',
'searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking',
'save table directionality template paste codesample'
],
imagetools_toolbar: "rotateleft rotateright | flipv fliph | editimage imageoptions",
toolbar: 'insertfile undo redo paste | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | print preview media fullpage | forecolor backcolor emoticons | codesample',
images_upload_url: '{{ url_for("imageuploader") }}',
automatic_uploads: true,
images_reuse_filename: false,
images_upload_base_path: '/static/uploads',
visualblocks_default_state: true,
forced_root_block : 'p',
});
</script>
My code fails, this is what the browser console shows
Uncaught SyntaxError: missing ) after argument list
{{editor_content|safe}} instructs Jinja not to escape the code as it should be HTML
Update
More troubleshooting shows me that this is OK
"<div id='test'>sdsdsd</div>"
while this is not
'<div id="test">sdsdsd</div>'
How do I get around this because the source of the content of my editor uses " and not '
Turns out that inconsistent use of " in the initialization string is causing this issue
You should use " within tags for properties and you should use ' when initializing the editor
editor.setContent('{{editor_content|safe}}');
I made a tinymce fiddle about this problem: http://fiddle.tinymce.com/O0gaab
I add a custom element "custom-block" and a custom plugin to insert that element.
tinymce.PluginManager.add('custom', function(editor, url) {
editor.addButton('custom', {
text: 'CUSTOM',
onclick: function() {
// Open window
editor.windowManager.open({
title: 'Custom plugin',
body: [
{type: 'textbox', name: 'src', label: 'SRC'},
{type: 'label', name: 'title', text: 'Insert content bellow:'},
{type: 'textbox', name: 'content', multiline: true, style: 'width:500px;height:100px;'}
],
onsubmit: function(e) {
console.log(e.data);
editor.insertContent('<custom-block src="' + e.data.src + '">' + e.data.content + '</custom-block>');
}
});
}
});
});
tinymce.init({
selector: "textarea",
plugins: [
"advlist autolink lists link image charmap print preview anchor",
"searchreplace visualblocks code fullscreen",
"insertdatetime media table contextmenu paste custom"
],
toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | custom",
//valid_elements: "+*[*]", //when using this option trying to allow everything get an error "Cannot read property 'src' of undefined"
extend_valid_elements: "custom-block[src]",
custom_elements: "custom-block"
});
The element, get inserted correctly but without the src attribute.
From the documentation I though that extend_valid_elements: "custom-block[src]" would allow src attribute on a custom-block but it gets stripped everytime.
I also tried to set valid_elements to everything(+*[*]) just in case, but then gets worse because at inserting, I get an error: "Cannot read property 'src' of undefined".
I am making any mistake or what is the problem?
The name of the configuration option is extended_valid_elements so you simply named it wrong in your configuration. It should be:
extended_valid_elements: "custom-block[src]"
I have updated your fiddle (http://fiddle.tinymce.com/O0gaab/1) and things appear to work.
When you copy and paste from a word document in to the tinyMCE editor sometimes there are unwanted <p> tags:
<p> </p>
<div class="starpasspro-example-question">
<p><strong>Example: Levels of strategy</strong></p>
<p>Microsoft is one of the world’s largest organisations, providing corporate solutions to businesses throughout the world to help them realise their fullest potential. At Microsoft, there are three levels of strategy as follows:</p>
</div>
<p> </p>
Here the code that generates I want to remove the <p> tags any way to do that ?
Add these Lines in your tinymce.init({ });
Example:
tinymce.init({
forced_root_block : "",
force_br_newlines : true,
force_p_newlines : false,
});
it will be helpful.
Add into your tinymce.yml file
forced_root_block : ""
force_br_newlines : true
force_p_newlines : false
Yes, this is possible. There is a secure way to remove all that html elements you want to removed (you may define what to keep). It is by using the tinymce config params paste_preprocess and a custom function strip_tags. Check it out here.
Add this to your functions.php file and the standard p-tags
tags will be removed by adding some parameters to the tiny_mce_before_init hook. If you want to see how it works, you can read further on this page: https://codex.wordpress.org/TinyMCE
////////////////////////////////////////////////////////////////////////
//////////REMOVE STANDARD <P> FROM TINYMCE EDITOR/////////////////////////
///////////////////////////////////////////////////////////////////////
function my_format_TinyMCE( $in ) {
$in['forced_root_block'] = "";
$in['force_br_newlines'] = TRUE;
$in['force_p_newlines'] = FALSE;
return $in;
}
add_filter( 'tiny_mce_before_init', 'my_format_TinyMCE' );
USE HtmlEncode="false" in BoundField
<asp:BoundField DataField="PostContent" HtmlEncode="false" />
Thanks to Prahalad Gaggar!
I had the same problem and I solved it by reading this topic: https://stackoverflow.com/a/22397116/14491024
here is my code with each time adding <p<br/<br/</p so annoying)
function HTMLeditor( parameters) {
$('#exampleModalCenter').modal('show');
tinymce.init({
height: 500,
selector: ".modal-body",
theme: 'modern',
plugins: [
'advlist autolink lists link image charmap print preview hr anchor pagebreak',
'searchreplace wordcount visualblocks visualchars code fullscreen',
'insertdatetime media nonbreaking save table contextmenu directionality',
'emoticons template paste textcolor colorpicker textpattern imagetools'
],
toolbar1: 'insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image',
toolbar2: 'print preview media | forecolor backcolor emoticons ',
image_advtab: true,
setup: function (editor) {
editor.on('init', function (e) {
editor.setContent(parameters);
});
}
});
}
And here is with problem SOLVED:
function HTMLeditor( parameters) {
$('#exampleModalCenter').modal('show');
tinymce.init({
height: 500,
selector: ".modal-body",
theme: 'modern',
plugins: [
'advlist autolink lists link image charmap print preview hr anchor pagebreak',
'searchreplace wordcount visualblocks visualchars code fullscreen',
'insertdatetime media nonbreaking save table contextmenu directionality',
'emoticons template paste textcolor colorpicker textpattern imagetools'
],
toolbar1: 'insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image',
toolbar2: 'print preview media | forecolor backcolor emoticons ',
image_advtab: true,
//remove <p><br /><br /></p>
forced_root_block: "" ,
force_br_newlines: true,
force_p_newlines: false,
setup: function (editor) {
editor.on('init', function (e) {
editor.setContent(parameters);
});
}
});
}
Below is my current Tinymce configuration which will remove all the style/formatting/html tags and paste as a plain text,
but my customer want to paste the table into it. So I would like improve my tinymce to be able to paste the table (only) when we copy and paste from ms word.
tinyMCE.init({
theme: "advanced",
mode: "exact",
elements: "txtTextbox1",
plugins : "paste,table,directionality,preview,iespell,wordcount,style",
theme_advanced_buttons1: "bold,italic,underline,|,cut,copy,paste,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,|,undo,redo,|,preview,iespell",
theme_advanced_buttons2: "tablecontrols,|,link,unlink",
//theme_advanced_buttons3: "tablecontrols,|,link,unlink",
theme_advanced_toolbar_location: "top",
theme_advanced_toolbar_align: "left",
theme_advanced_statusbar_location: "bottom",
force_p_newlines: false,
force_br_newlines: true,
forced_root_block: '',
paste_convert_middot_lists: false,
paste_text_sticky: true,
paste_strip_class_attributes: "all",
paste_remove_styles: true,
paste_remove_spans: true,
paste_block_drop: true,
paste_text_sticky_default: true,
setup: function (ed) {
ed.onInit.add(function (ed) {
ed.pasteAsPlainText = true;
ed.controlManager.setActive("pastetext", true);
});
}
});
EDITED
below is my final code
tinyMCE.init
({
theme: "advanced",
mode: "exact",
elements: "txtTextbox1",
plugins : "paste,table,directionality,preview,iespell,wordcount,style",
theme_advanced_buttons1: "bold,italic,underline,|,cut,copy,paste,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,|,undo,redo,|,preview,iespell",
theme_advanced_buttons2: "tablecontrols,|,link,unlink",
theme_advanced_toolbar_location: "top",
theme_advanced_toolbar_align: "left",
theme_advanced_statusbar_location: "bottom",
force_p_newlines: false,
force_br_newlines: true,
forced_root_block: '',
paste_convert_middot_lists: false,
paste_preprocess : function(pl, o)
{
o.content = strip_tags( o.content,'<table><tr><td>' );
},
});
function strip_tags (str, allowed_tags)
{
}
The solution is to use paste_preprocess. In this SO-thread you will find a way to paste as plain text, but to keep tables define table, tbody, td, tr to be not stripped out when pasted
I find a solution for copy - paste tinyMCE 4.0
if you using this basic example source
<script type="text/javascript">
tinymce.init({
selector: "textarea",
plugins: [
"advlist autolink lists link image charmap print preview anchor",
"searchreplace visualblocks code fullscreen",
"insertdatetime media table contextmenu paste moxiemanager"
],
toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image"
});
</script>
remove " paste " option from plugins section;
like this;
plugins: [
"advlist autolink lists link image charmap print preview anchor",
"searchreplace visualblocks code fullscreen",
"insertdatetime media table contextmenu moxiemanager"
],
Now you can paste (everything ms word , html page etc..) to tinyMCE editor
maybe ,might be help