TinyMCE and Piranha CMS not allowing me to set <style> tags as valid elements :( - tinymce

I'm trying to add <style>// custom css here</style> into the tiny mce editor but currently it deletes the style tags and anything in between them on save.
I am trying to set valid_elements: "style" and/or custom_elements: "sabioStyle", and/or extended_valid_elements: "style". I've also tried: "[]" according to tiny's docs but it seems to have no effect on anything. I see that the init function:
piranha.editor.addInline = function (id, toolbarId) {
tinymce.init({
selector: "#" + id,
browser_spellcheck: true,
fixed_toolbar_container: "#" + toolbarId,
menubar: false,
branding: false,
statusbar: false,
inline: true,
convert_urls: false,
plugins: [
piranha.editorconfig.plugins
],
width: "100%",
autoresize_min_height: 0,
toolbar: piranha.editorconfig.toolbar,
extended_valid_elements: piranha.editorconfig.extended_valid_elements,
block_formats: piranha.editorconfig.block_formats,
style_formats: piranha.editorconfig.style_formats,
file_picker_callback: function(callback, value, meta) {
// Provide file and text for the link dialog
if (meta.filetype == 'file') {
piranha.mediapicker.openCurrentFolder(function (data) {
callback(data.publicUrl, { text: data.filename });
}, null);
}
// Provide image and alt text for the image dialog
if (meta.filetype == 'image') {
piranha.mediapicker.openCurrentFolder(function (data) {
callback(data.publicUrl, { alt: "" });
}, "image");
}
}
});
$("#" + id).parent().append("<a class='tiny-brand' href='https://www.tiny.cloud' target='tiny'>Powered by Tiny</a>");
};
Piranha uses sets extended_valid_elements: piranha.editorconfig.extended_valid_elements but my dev tools are not showing the value that I type in editorconfig.json...
editorconfig.json
devTools
I've tried everything their docs say, I have a question open on github with Piranha as well.. Any suggestions would be great! Thanks

See the complete answer here: https://github.com/PiranhaCMS/piranha.core/issues/1663

Related

TinyMCE 5 not cleaning attributes from tags

TinyMCE 5 just won't clean all the attributes from tags. It leaves stuff like "data-gps-track, data-controller, aria-label:"" ". It cleans stuff like "href, style, class". Any idea what's the problem here?
tinymce.init({
selector: "#mytextarea",
plugins: "paste, code",
toolbar: "edit, code",
paste_block_drop: false,
paste_tab_spaces: 2,
paste_as_text: cleantext,
valid_elements: "a,code,p",
});
You can try pasting stuff off StackOverflow, where these attributes are present.
I have ended up using an answer from this StackOverflow answer.
I have also added a filter for clearing aria attributes to the regex.
var stripDataAttributes = function (html) {
var tags = html.match(/(<\/?[\S][^>]*>)/gi);
tags.forEach(function (tag) {
html = html.replace(
tag,
tag.replace(
/(data-.+?=".*?")|(data-.+?='.*?')|(data-[a-zA-Z0-9-]+)|(aria-.+?=".*?")|(aria-.+?='.*?')|(aria-[a-zA-Z0-9-]+)/g,
""
)
);
});
return html;
};
tinymce.init({
selector: "#mytextarea",
plugins: "paste, code",
toolbar: "edit, code",
paste_block_drop: false,
paste_tab_spaces: 2,
paste_as_text: cleantext,
valid_styles: {
"*": "",
p: "color",
},
// https://www.tiny.cloud/docs-4x/configure/content-filtering/
// valid_elements: "*[*|-href]",
// https://www.tiny.cloud/docs-3x/reference/Configuration3x/Configuration3x#valid_elements/
// jen pozor na mezery (když jsem měl valid_elements: "a, code, p" , tak mi to nešlo!)
paste_preprocess: function (plugin, args) {
args.content = stripDataAttributes(args.content);
// args.content = args.content.replace(cleanElements, "$1>");
},
});

TinyMCE | Paste as plain Text + Blank Lines

I would like to know if there is anyway to keep paste_as_text: true,
But keep the blank lines / new lines, when paste something to TinyMCE.
I´m uploading my code below. Already searched alot on web, and didn´t found any answer.
Thanks for anyone help.
Try to pase this text:
"this text you should
paste to the editor for testing"
-> You see, the blank line between the phrases, is not pasting
tinymce.init({
selector: '#mytextarea',
height: "calc(100vh - 90px)",
width: "100%",
plugins: "paste",
paste_as_text: true,
force_br_newlines: true,
force_p_newlines: false,
forced_root_block: 'div',
setup: function (editor) {
editor.on('init', function (e) {
editor.setContent('');
editor.getBody().style.fontSize = '13px';
editor.getBody().style.fontFamily = 'Arial';
});

Orchard CMS Bootstrap CSS Classes in Html Editor

We have an Orchard CMS 1.8 site that has been deployed and the content is now managed by the customer. One thing they are having a problem with is adding Bootstrap UI CSS classes to their content in the Html editor.
For example, they have some content and want to create a link to a "Register Now" page. It's easy enough to create the anchor tag using the toolbar buttons but without knowledge of HTML how would they turn that anchor tag into a Bootstrap button without diving into the HTML.
Also knowing that Bootstrap likes to combine classes like the following, how could a content manager pick a combination of styles from the Html Editor toolbar.
Register Now
Does anyone have a recommendation for customizing TinyMCE to make bootstrap classes more accessible to a content manager?
Thanks,
Brian
In Your Theme; add a ResourceManifest and create a reference to a Javascript file.
manifest.DefineScript("OrchardTinyMce").SetVersion("1.1").SetUrl("orchard-tinymce.js").SetDependencies("TinyMce");
this js file will be a TinyMCE customisation override. Make sure the ScriptName is the same and the version is always higher than the one at use in the TinyMCE module.
var mediaPlugins = ",|";
if (mediaPickerEnabled) {
mediaPlugins += ",mediapicker";
}
if (mediaLibraryEnabled) {
mediaPlugins += ",medialibrary";
}
tinyMCE.init({
theme: "advanced",
schema: "html5",
mode: "specific_textareas",
editor_selector: "tinymce",
plugins: "fullscreen,searchreplace,inlinepopups" + mediaPlugins.substr(2),
theme_advanced_toolbar_location: "top",
theme_advanced_toolbar_align: "left",
theme_advanced_buttons1: "search,replace,|,cut,copy,paste,|,undo,redo" + mediaPlugins + ",|,link,unlink,charmap,emoticon,codeblock,|,bold,italic,|,numlist,bullist,formatselect,blockquote,styleselect,|,code,fullscreen,",
theme_advanced_buttons2: "",
theme_advanced_buttons3: "",
theme_advanced_resizing : true,
convert_urls: false,
content_css: "/Themes/[*YOUR-THEME-NAME*]/Styles/custom.css",
valid_elements: "*[*]",
// shouldn't be needed due to the valid_elements setting, but TinyMCE would strip script.src without it.
extended_valid_elements: "script[type|defer|src|language]"
});
As you can see, now you can customise TinyMCE at will. Take note of the content_css property. That css file will be used in your Editor.
I use it all the time, so my clients can really have a true WYSIWYG experience.
One way to do this is to add bootstrap styles into style_formats in tinymce configuration.
Here is one way to do it by adding to orchard-tinymce.js
style_formats: [
{
title: 'Typography', items: [
{
title: 'Body Copy', items: [
{ title: 'Lead Body Para', block: 'p', classes: 'lead' }
]
},
{
title: 'Inline Text', items: [
{ title: 'Small', inline: 'small' },
{ title: 'Highlight', inline: 'mark' },
{ title: 'Deleted', inline: 'del' },
{ title: 'Strikethrough', inline: 's' },
{ title: 'Insert', inline: 'ins' }
]
},
Complete implementation is here:
https://www.bhavindoshi.com/blog/bootstrap-style-formats-in-tinymce-orchard-or-other-cms

Flowplayer Menu plugin issue

I am trying to implement bit rate selection like in flowplayer like in youtube. One option should be 'auto' and others manual. I am using a smil file to load my videos. Flowplayer documentation http://flash.flowplayer.org/plugins/flash/menu.html shows using the menu plugin. I cannot do it using that method since the url path is generated at run time. So I have use smil for menu creation and it works.I just mention the smil file name and the menu plugin loads the bit rates from the smil seamlessly. I am not exactly sure how this works though.
This is the code
clip: {
url:"<?php echo getxml(); ?>",
autoPlay: true,
provider: 'rtmp',
scaling:"fit",
urlResolvers: [ 'smil', 'bwcheck','brselect' ],
onStart: function() {
}
},
plugins: {
smil: {
url: "flowplayer.smil/flowplayer.smil-3.2.8.swf"
},
bwcheck: {
url: "flowplayer.bwcheck/flowplayer.bwcheck-3.2.11.swf",
serverType: 'wowza',
dynamic: true,
dynamicBuffer:true,
netConnectionUrl: 'rtmp://itl.bc-s.cdn.bitgravity.com/cdn',
checkOnStart: true,
rememberBitrate: true,
onStreamSwitchBegin: function(newItem, currentItem) {
$f().getPlugin('content').setHtml("Will switch to: " + newItem.streamName +" from " + currentItem.streamName);
},
onStreamSwitch: function(newItem) {
$f().getPlugin('content').setHtml("Switched to: " + newItem.streamName);
}
},
menu: {
url: "http://releases.flowplayer.org/swf/flowplayer.menu-3.2.12.swf",
items: [
{ label: " Auto", enabled: true, index: 0,toggle:true , selected:true},
],
onSelect: function(item) {
if(item.index == 0){
$f().getPlugin('bwcheck').enableDynamic(true);
$f().getPlugin('content').setHtml("Auto Mode Slected : Best bit rate will be selected according to your bandwidth");
}
else{
$f().getPlugin('bwcheck').enableDynamic(false);
$f().getPlugin('content').setHtml("Manual bit rate selection activated");
}
}
},
brselect: {
url: "http://releases.flowplayer.org/swf/flowplayer.bitrateselect-3.2.13.swf",
menu: true,
},
As you can see from the code I placesd a single item like this
{ label: " Auto", enabled: true, index: 0,toggle:true , selected:true},
By default auto mode is selected and I have to give a tick mark to the menu item 'Auto'. This was also achieved using the parameter 'selected'. But the problem is that the bit rate being played when the file starts playing in the auto mode is also selected and that too gets a tick mark like this.
http://tinypic.com/r/2nkt9fl/6
I need to disable that. The switching is happening and functionality is implemented but the user gets the wrong idea. There is a property by the name 'group' and I guess I will have to make all the items as a part of the group. A combination of the 'group' , 'selected' and 'toggle' property should be able do this but I cannot implement it.

How to allow custom uppercase tags in TinyMCE

Does anyone know how to allow having custom uppercase tags in TinyMCE? It seems that TinyMCE doesn't like uppercase tags, even though they have been declared as valid. Here is my TinyMCE config:
tinyMCE.init({
mode: "specific_textareas",
theme: "advanced",
language: "en",
theme_advanced_toolbar_location: "top",
theme_advanced_toolbar_align: "left",
theme_advanced_statusbar_location: "bottom",
theme_advanced_buttons1: "bold,italic,|,sub,sup,|,charmap,|,table,|,code",
theme_advanced_path: false,
theme_advanced_resizing: true,
plugins: "fullscreen,paste,table",
paste_auto_cleanup_on_paste : true,
relative_urls: false,
width: "300",
height: "300",
theme_advanced_resizing_min_height : "10",
force_br_newlines : true,
force_p_newlines : false,
forced_root_block : '',
entity_encoding: "raw",
valid_elements : "B/strong,I/em,SUP/sup,SUB/sub",
extended_valid_elements: "CUSTOM"
})
Typing something like
<CUSTOM>this is a custom tag</CUSTOM>
doesn't work because <CUSTOM> gets stripped off.
If I change the init script to extended_valid_elements: "custom", then it works fine - I can type
<custom>this is a custom tag</custom>
and the <custom gets preserved.
Doesn't anyone know any workaround?
Thanks!
Here is a description of how to do that (the reverse works analogue): http://www.codingforums.com/archive/index.php/t-148450.html
You should use the tinymce onInit event and to change the tags back to Uppercase use onSubmit or onSave (alternatively you may change the content back before submitting your content on any other suitable location of code).
To add this handlers use the tinymce setup configuration parameter
setup : function(ed) {
ed.onInit.add(function(ed, evt) {
$(ed.getBody()).find('p').addClass('headline');
// get content from editor source html element
var content = $(ed.id).html();
// tagname to lowercase
content = content.replace(/< *\/?(\w+)/g,function(w){return w.toLowerCase()});
ed.setContent(content);
});
ed.onSubmit.add(function(ed, evt) {
$(ed.getBody()).find('p').addClass('headline');
// get content from edito
var content = ed.getContent();
// tagname to toUpperCase
content = content.replace(/< *\/?(\w+)/g,function(w){return w.toUpperCase()});
// write content to html source element (usually a textarea)
$(ed.id).html(content );
});
},