5

When creating a Tumblr post, and using the HTML editor option, when I add specific HTML attributes to elements, the TinyMCE rich text editor strips nearly everything off.

i.e. this:

<span class="something" data-random="foobar">

becomes this:

<span class="something">

and this is unaffected:

<span class="something" title="foobar">

So can I either 1) disable this scrubbing (which is ridiculous, at least how it's currently implemented) or 2) get a list of all valid attributes so I can choose the best semantic choice?

Nathan Loyer
  • 1,339
  • 10
  • 20

3 Answers3

10

This was killing me too. And searching google for any tumblr dev help more complicated than "how do I edit text color", oy vey. I wouldn't wish it on anyone.

Tumblr users don't have any control of the html or js that runs the control panel, and so can't add any files that alter TinyMCE configuration. But you can just turn it off. In the Dashboard tab of your Tumblr settings, you'll find a Text Editor section. Selecting plain html or Markdown will deactivate TinyMCE and allow you to post forms, data attributes, and any non-whitelist html to your heart's content.

mavit
  • 619
  • 6
  • 13
RobW
  • 10,184
  • 4
  • 41
  • 40
  • Arguably none of these have hit on the right answer — `data-random: foobar` will still be stripped from posts when displayed on the dash, so style settings such as `style="white-space: pre-line;"` to soften line wrap on `
    ` elements isn't possible. If anyone has the allowed dashboard HTML that'd be useful
    – Louis Maddox Jul 07 '14 at 09:33
0

Using Markdown sounds like a good alternative, but I’ve read somewhere that it has problems with embedded iframes. If it works for you, then that’s fluffy. I haven’t tested it yet.

However, what you can do if you don’t want to forgo TinyMCE is the following.

tinymce.activeEditor.schema.setValidElements('*[*]')

This tells the active editor that now all elements are valid.

Unfortunately, as soon as you close and reopen the edit window, the freshly started editor will strip them again, so I wrote a little Greasemonkey script that sets the valid_elements automatically at the initialization of the editor.

// ==UserScript==
// @name        Lift TinyMCE tag restrictions
// @namespace   http://claviger.net
// @include     *.tumblr.com/*
// @version     1
// @grant       none
// ==/UserScript==

if (typeof tinyMCE !== 'undefined') {
    tinyMCE.onAddEditor.add(function(mgr, ed) {
        ed.settings.valid_elements = '*[*]';
    });
}

It works pretty well for me, but I think in rare cases there’s a race condition going on between the Greasemonkey script and the actual initialization of TinyMCE. I assume the latter must sometimes run before the first and thwart my little hack. It hasn’t happened the last twenty or so times I reloaded the page, though, and if it happens, just reload without saving. (Maybe someone has an idea how to avoid this?)

By the way, the class attribute doesn’t seem to get stripped, so as another alternative, you could define something like .alignleft in your blog’s theme and use it for the images. Then it wouldn’t look like much in TinyMCE, but the visitor or the blog would see the pretty version.

Dawn Drescher
  • 901
  • 11
  • 17
0

1) Stripping elements can be turned off using the following tinymce init parameter cleanup:false,

2) The default definition of valid html elmements can be found here: http://www.tinymce.com/wiki.php/Configuration:valid_elements

In order to keep data-random as an attribute of span you will need to set the valid_children init parameter as follows

valid_children: "body[p|ol|ul|hr]" +
",span[a|b|i|u|sup|sub|img|data-random|#text]" +
",a[span|b|i|u|sup|sub|img|#text]", //...
Thariama
  • 50,002
  • 13
  • 138
  • 166
  • Thanks for the information, but I mentioned in my post that I'm using Tumblr to create a post, so I'm pretty sure I don't have access to change TinyMCE properties. Am I incorrect? If so, where would I set these properties? – Nathan Loyer Dec 08 '11 at 20:29
  • i am sure you can somehow set tinymce properties, but i am not familiar with tumblr, so i do not know how to set this. I suggest you have a closer look on how the tinymce init code gets executed. – Thariama Dec 09 '11 at 13:25
  • 1
    Tumblr doesn't give its users any control over the control panel html or js, so you can't set those params unfortunately. – RobW Apr 29 '12 at 18:09