TinyMCE custom format breaks ability to set style? - html

I have a textarea that I want to add a simple wysiwyg editor. I chose TinyMCE but don't need all of the options available so I was using a sample from their page (http://www.tinymce.com/tryit/custom_formats.php) that just had the basic simple formatting options I was looking for.
The problem I'm having is that with the code below the editor shows up but clicking styles (i.e., Bold, Underline, etc.) doesn't update the window. It appears to update the underlying HTML style (although popping the embedded HTML editor window also doesn't seem to work here), but I don't see a style change. But, if I comment out the "formats: " block, it does work. This was testing on Chrome, Firefox, and IE.
I downloaded the tinymce package and have things in a folder like so:
sample\
sample\tiny_mce
sample\tiny_mce\langs
sample\tiny_mce\plugins
sample\tiny_mce\themes
sample\tiny_mce\utils
sample\tiny_mce\license.txt
sample\tiny_mce\tiny_mce.js
sample\tiny_mce\tiny_mce_popup.js
sample\tiny_mce\tiny_mce_src.js
sample\index.html (see code below)
I took the content of the downloaded archive \jscripts* folder and moved it up to the root of my path. My HTML is:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
<head>
<title>TinyMCE Test</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<!-- OF COURSE YOU NEED TO ADAPT NEXT LINE TO YOUR tiny_mce.js PATH -->
<script type="text/javascript" src="tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
tinyMCE.init({
// General options
mode : "textareas",
theme : "advanced",
plugins : "table,inlinepopups",
// Theme options
theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,|,table,removeformat,code",
theme_advanced_buttons2 : "",
theme_advanced_buttons3 : "",
theme_advanced_buttons4 : "",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : true,
// Example content CSS (should be your site CSS)
//content_css : "/js/tinymce/examples/css/content.css",
// Style formats
style_formats : [
{title : 'Bold text', inline : 'b'},
{title : 'Red text', inline : 'span', styles : {color : '#ff0000'}},
{title : 'Red header', block : 'h1', styles : {color : '#ff0000'}},
{title : 'Example 1', inline : 'span', classes : 'example1'},
{title : 'Example 2', inline : 'span', classes : 'example2'},
{title : 'Table styles'},
{title : 'Table row 1', selector : 'tr', classes : 'tablerow1'}
],
formats : {
alignleft : {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes : 'left'},
aligncenter : {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes : 'center'},
alignright : {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes : 'right'},
alignfull : {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes : 'full'},
bold : {inline : 'span', 'classes' : 'bold'},
italic : {inline : 'span', 'classes' : 'italic'},
underline : {inline : 'span', 'classes' : 'underline', exact : true},
strikethrough : {inline : 'del'},
customformat : {inline : 'span', styles : {color : '#00ff00', fontSize : '20px'}, attributes : {title : 'My custom format'}}
}
});
</script>
</head>
<body>
<!-- OF COURSE YOU NEED TO ADAPT ACTION TO WHAT PAGE YOU WANT TO LOAD WHEN HITTING "SAVE" -->
<form method="post" action="show.php">
<p>
<textarea name="content" cols="50" rows="15">This is some content that will be editable with TinyMCE.</textarea>
<input type="submit" value="Save" />
</p>
</form>
</body>
</html>
Any ideas what I'm doing wrong? The example on their site seems to work fine so I'm assuming there's some sort of config problem on my end. Really I'm just looking for a textarea editor that will give me some basic HTML formatting options, I don't even need anything really fancy. Thanks for any help!

The default behavior of TinyMCE for bold, italic, underline is to use the html entities associated with the formatting. Example: <strong></strong>, <em></em>, and a span with inline style for underline.
It seems the Formats block of code is overriding this action by instead wrapping your selection in a span with a class name defined by the "classes" property.
In order to have your styles render with the formats block as seen above you need to add a style sheet with definitions for .bold, .italic, .underline and so on.
TinyMCE renders its UI on top of a textarea using iframes if I recall correctly so while simply linking a stylesheet will work for your front end, in order for this to show in the edit box you need to link to the stylesheet through the tinyMCE.init() object.
Using your folder structure, add a stylesheet \sample\tiny_mce\style.css, define your styles within, then below the formats block of code add: content_css: "\sample\tiny_mce\style.css". This will load the style sheet into the tinyMCE edit interface and you should then see your style definitions applied.
it should look like:
...
// Style formats
style_formats : [
{title : 'Bold text', inline : 'b'},
{title : 'Red text', inline : 'span', styles : {color : '#ff0000'}},
{title : 'Red header', block : 'h1', styles : {color : '#ff0000'}},
{title : 'Example 1', inline : 'span', classes : 'example1'},
{title : 'Example 2', inline : 'span', classes : 'example2'},
{title : 'Table styles'},
{title : 'Table row 1', selector : 'tr', classes : 'tablerow1'}
],
content_css : "tiny_mce/style.css"
...

Related

how to add internal style to the wysiwyg editor in react

I'm using tinymce editor in react app like above.
I'm trying to show
an editor to edit the HTML page which has many styles with flexbox in
internal styling.
But this editor does not support internal styling and removes all
styling forcing me to add it as inline styling
I don't want inline styling when user submits the page
. By the way I'm using initialvalue to provide my HTML template.
But internal styling works on normal html/css/js mode example
here.
export default function App() {
const editorRef = useRef(null);
const log = () => {
if (editorRef.current) {
console.log(editorRef.current.getContent());
}
};
return (
<>
<Editor
onInit={(evt, editor) => editorRef.current = editor}
initialValue={htmlTemplate}
init={{
height: 500,
menubar: false,
extended_valid_elements:
'style[*],div[class|contenteditable|ref|data|style]',
plugins: [
'advlist autolink lists link image charmap print preview anchor',
'searchreplace visualblocks code fullscreen',
'insertdatetime media table paste code help wordcount'
],
toolbar: 'undo redo | formatselect | ' +
'bold italic backcolor | alignleft aligncenter ' +
'alignright alignjustify | bullist numlist outdent indent | ' +
'removeformat | help',
content_style: 'body { font-family:Helvetica,Arial,sans-serif; font-size:14px }'
}}
/>
<button onClick={log}>Log editor content</button>
</>
);
}
If you would like to apply CSS to editor content, you can do so with the content_css option (for internal styles) or the content_style option (for external stylesheets) in your config:
https://www.tiny.cloud/docs/tinymce/6/add-css-options/#content_css 
https://www.tiny.cloud/docs/tinymce/6/add-css-options/#content_style
These options allow you to apply styling to editor content, but that styling is not then injected inline to the editor content. If you want it applied to the content when it is rendered later, you will need to load the same CSS/styling there too.

How do we display a view in ExtJS using browser's console

Is there any way to display our view without creating any button clicks events in controller
Console view
give your view xtype and id to the Viewport items and then paste the code into the console
Ext.Viewport.add({
xtype : 'panel',
itemId : 'testingOverlay',
showAnimation : {
type : 'popIn',
duration : 250,
easing : 'ease-out'
},
hideAnimation : {
type : 'popOut',
duration : 250,
easing : 'ease-out'
},
height : '630px',
width : '335px',
left : '210px',
top : '205px',
items : [{
xtype : 'viewXtype',
id : 'viewId'
}],
});
You can also use renderTo property, if you specify renderTo:Ext.getBody() it will render the content or replace Ext.getBody() with html element.
But in real applications you will need a viewport this is better than renderTo
Fiddle Sample Code
Ext.create('Ext.panel.Panel',{
title:'Test Panel',
width:400,
height:500,
renderTo:Ext.getBody()
});

tinymce html5 editor

I used tinymce(3.5.8 version) editor as html5 editor. Now i want features to add video and audio tags.
function doTinyMCECleanUp(frm, id)
{
var c = frm[id].value;
c = c.replace(/ </source>/gim, '');
c = c.replace(/</source>/gim, '');
// comment this out if 'html' not 'xhtml'
c = c.replace(/]*)>/gim, '');
frm[id].value = c;
}
tinyMCE.init({
mode : "textareas",
theme : "advanced",
plugins : "visualblocks,inlinepopups,mediahtml5,media",
theme_advanced_buttons1 : "bold,italic,underline,strikethrough,styleselect,justifyleft,justifycenter,justifyright,justifyfull,|,visualblocks,code,mediahtml5,media",
theme_advanced_buttons2 : "",
theme_advanced_buttons3 : "",
theme_advanced_buttons4 : "",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : true,
content_css : "/js/tinymce/examples/css/content.css",
visualblocks_default_state: true,
extended_valid_elements : "video[*]",
// Schema is HTML5 instead of default HTML4
schema: "html5",
template_external_list_url : "tinymce/examples/lists/template_list.js",
external_link_list_url : "tinymce/examples/lists/link_list.js",
external_image_list_url : "tinymce/examples/lists/image_list.js",
media_external_list_url : "tinymce/examples/lists/media_list.js",
// End container block element when pressing enter inside an empty block
end_container_on_empty_block: true,
// HTML5 formats
style_formats : [
{title : 'h1', block : 'h1'},
{title : 'h2', block : 'h2'},
{title : 'h3', block : 'h3'},
{title : 'h4', block : 'h4'},
{title : 'h5', block : 'h5'},
{title : 'h6', block : 'h6'},
{title : 'p', block : 'p'},
{title : 'div', block : 'div'},
{title : 'pre', block : 'pre'},
{title : 'section', block : 'section', wrapper: true, merge_siblings: false},
{title : 'article', block : 'article', wrapper: true, merge_siblings: false},
{title : 'blockquote', block : 'blockquote', wrapper: true},
{title : 'hgroup', block : 'hgroup', wrapper: true},
{title : 'aside', block : 'aside', wrapper: true},
{title : 'figure', block : 'figure', wrapper: true}
],
setup : function(ed) {
ed.onSubmit.add(function(ed, e) {
doTinyMCECleanUp(e.target, ed.id);
});
},
});
I tried a lots with 2 plugin mediahtml5 and media.
When i use media plugin. If i add video tags it insert flashobject with video tags.
And also when i update the content video tags goes out. I can't see it anywhere any html source editor. i can see only flash object source.
when i use mediahtml5 plugin i can add videos into editor but can not see into html view source editor.
Can anybody please help me .
Have a look at the tinymce settings valid_elements and valid_children.
Tinymce stips out html tags that do not match the configuration/ are invalid.
Add the 'extend_valid_elements' to your tiny mce initalization. For example:
$('#my_textarea').tinymce({
...
extended_valid_elements: "audio[id|class|src|type|controls]",
...
})
The example above allows you to insert 'audio' tags with the desired element properties in the tiny mce editor.
Note: I use tiny mce jquery plugin but it's the same thing for the regular tiny mce.

HTML : How to retain formatting in textarea?

I am using HTML textarea for user to input some data and save that to App Engine's model
The problem is that when I retrieve the content it is just text and all formatting is gone
The reason is because in textarea there is no formatting that we can make
Question:
is there any way to retain the format that user provides?
is there any other element(other than textarea), that i'll have to use?(which one?)
P.S I am very new to area of web development and working on my first project
Thank you
What you want is a Rich Text Editor. The standard HTML <textarea> tag only accepts plain text (even if the text is or includes HTML markup). There are a lot of example out there (including some listed on the page linked) but I would highly recommend using a prepackaged one for this. Coding your own is fairly complicated for people who are new, and even for a lot who have some experience. Both TinyMCE and CKEditor are very common ones, but there are many others as well.
A text box is like wordpad, you cant format it, if you paste in from word or any other formatted text it will wipe all the formatting and you will be left with just the text.
You need add an editor to the text areas, I use TinyMCE, but there are many other out there too.
To implement you need to have all the source (which you can get from TinyMCE) in your web directory.
Here's an example which you can try:
Add this the the head section of your page:
<script language="javascript" type="text/javascript" src="/js/tiny_mce/tiny_mce.js"></script>
<script language="javascript" type="text/javascript">
tinyMCE.init({
theme : "advanced",
mode: "exact",
elements : "elm1",
theme_advanced_toolbar_location : "top",
theme_advanced_buttons1 : "bold,italic,underline,strikethrough,separator,"
+ "justifyleft,justifycenter,justifyright,justifyfull,formatselect,"
+ "bullist,numlist,outdent,indent",
theme_advanced_buttons2 : "link,unlink,anchor,image,separator,"
+"undo,redo,cleanup,code,separator,sub,sup,charmap",
theme_advanced_buttons3 : "",
height:"350px",
width:"600px"
});
</script>
<script type="text/javascript">
tinyMCE.init({
// General options
mode : "textareas",
theme : "advanced",
plugins : "autolink,lists,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
// Theme options
theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,pagebreak,|,insertfile,insertimage",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : true,
// Skin options
skin : "o2k7",
skin_variant : "silver",
// Example content CSS (should be your site CSS)
content_css : "css/example.css",
// Drop lists for link/image/media/template dialogs
template_external_list_url : "js/template_list.js",
external_link_list_url : "js/link_list.js",
external_image_list_url : "js/image_list.js",
media_external_list_url : "js/media_list.js",
// Replace values for the template plugin
template_replace_values : {
username : "Some User",
staffid : "991234"
}
});
</script>
Then to call the textarea:
<textarea name="content" style="width:100%">YOUR TEXT HERE</textarea>
NB: You need to download and have in your directory the js files for <script language="javascript" type="text/javascript" src="/js/tiny_mce/tiny_mce.js"></script>
Hope this helps!
This won't solve the case when you want somebody to be able to format their text (e.g. with WYSIWYG bold buttons etc.), but if you want to be able to accept pre-formatted HTML (e.g. copy and paste from other HTML source such as a webpage), then you can do this:
<form ...>
<label>Paste your HTML in the box below</label>
<textarea style='display:none' id='foo'></textarea>
<div id='htmlsource' contenteditable style='border:solid 1px black;padding:1em;width:100%;min-height:2em;' ></div>
<input type='submit' />
</form>
<script>
jQuery(function(){
jQuery('form').submit( function(e) {
jQuery('textarea').val( jQuery('#htmlsource').html() );
});
});
</script>
This uses a contenteditable div element which you can format to look like an input box and will accept pasted HTML, and a hidden textarea#foo which will be populated with the pasted HTML just before the form is submitted.
Note that this is not an accessible solution as it stands.
Depending on your goal for the programm it could already be sufficient to just add "pre" tags left and right to the input of your textarea. for example if your code submits to a form whatever is inside a textarea and than echos it in the target File this would already work.
> File 1:
>
> <form action="Output.php" methode=post>
> <textarea name="Input"></textarea>
> </form>
>
> File Output.php
>
> $UserInput = $_POST["Input"];
> $UserInput = "<pre>" . $UserInput . "</pre>"
> echo $UserInput
this already will retain all Enters for example that where used in the original user input and echo them correctly
If you retrieve the content from the App Engine Saving the Content with the pre tags added already in most cases does the trick

CKEditor remove spaces/tabs from between headings

CKEditor does this whenever I add a heading tag:
<h2>
Mai 2010</h2>
How can I remove the new line and spaces after the h2 starting tag, please?
The way to do this without modifying CKEditor's source is to do the following:
CKEDITOR.on( 'instanceReady', function( ev )
{
ev.editor.dataProcessor.writer.setRules( 'p',
{
indent : false,
breakBeforeOpen : true,
breakAfterOpen : false,
breakBeforeClose : false,
breakAfterClose : true
});
});
For more information see:
http://cksource.com/forums/viewtopic.php?f=6&t=14493
http://docs.cksource.com/CKEditor_3.x/Developers_Guide/Output_Formatting
This is the default CKEDITOR behavior for a lot of tag.
To avoid it, open the ckeditor.js file and search for this:
n.setRules('title',{indent:false,breakAfterOpen:false});
and add this rule:
n.setRules('h2',{indent:false,breakAfterOpen:false});
You can add this rule for each tag you want