Hi!
I was trying to add support in the "Full HTML" text filter by adding them to the "Block Formats" option under the CSS fieldset (see image 1) but it didn't work.
Image 1:
When the block format selector is expanded in the wysiwyg, the new elements that were added do not display text. Upon clicking one of the label-less added elements, the editor does not update the current line and/or selected text's wrapping element to be what was chosen.
In the image below, you see the expanded select box and the blue stripe is where my mouse cursor was hovering when I took the screen shot.
Image 2:
I confirmed that TinyMCE version 3.5.4.1 (which is the version I installed) is capable of adding new block level elements. The page where the settings that need to be used can be found is TinyMCE HTML5 Formats.
The image below shows how the dropdown should look when it is working properly.
Image 3:
The code below includes the settings as copied from the page linked to above. Note the section starting with "// HTML5 formats".
tinyMCE.init({
// General options
mode : "textareas",
theme : "advanced",
plugins : "visualblocks,inlinepopups",
// Theme options
theme_advanced_buttons1 : "bold,italic,underline,strikethrough,styleselect,justifyleft,justifycenter,justifyright,justifyfull,|,visualblocks,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,
content_css : "/js/tinymce/examples/css/content.css",
visualblocks_default_state: true,
// Schema is HTML5 instead of default HTML4
schema: "html5",
// 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}
]
});
I tried looking into the code in tinymce.inc to try and find a clue as to where the problem might be but was unable to find anything...
I hope someone can help me out with this!
Thank you very much to the maintainers of this module!
Comment | File | Size | Author |
---|---|---|---|
#9 | wysiwyg_tinymce_block_formats-1665986-9.patch | 297 bytes | skylord |
#8 | wysiwyg_customisations.zip | 2.78 KB | igorski |
#3 | wysiwyg_customisations.zip | 1.46 KB | anandkp |
TinyMCE_HTML5_Formats_Dropdown.jpg | 212.07 KB | anandkp | |
TinyMCE_Block_Wrapper_Dropdown_Expanded.jpg | 250.6 KB | anandkp |
Comments
Comment #1
TwoDThe Block Formats list sets the theme_advanced_blockformats setting, not the style_formats setting, which was added later.
We don't have a GUI widget to control TinyMCE's style_formats setting yet, but you can control it using a small custom module until we do by implementing hook_wysiwyg_editor_settings_alter().
sites/default/modules/custom/custom.info:
sites/default/modules/custom/custom.module:
Comment #2
anandkp CreditAttribution: anandkp commentedThat's awesome TwoD! Thank you very much for that!
Just a short while ago I came close to the same realisation... I'd found out that I was looking at the wrong dropdown. In the buttons settings, the box I thought would allow me to add wrappers is called "Block Formats" when, yes in fact, the dropdown I'd been hoping to update was called "Styles".
I had come up with a solution wherein the User could misappropriate the "Block Formats" text field to specify additional block wrapper elements... The code below demonstrates how I was using the elements defined there and adding them to the TinyMCE settings... this workaround was added directly to the tinymce-3.js file:
I'll move this stuff into a custom module as recommended by you.
I guess I should move this issue into feature requests... It would be really great if we could have a form area for TinyMCE were you could specify additional block elements that can act as wrappers.
Incidentally, there is one other setting worth noting in this issue and that's the "visualblocks" plugin. I added that in directly into the tinymce.inc file... I guess I'll be moving that out as well. The Visual Blocks plugin displays dashed-line wrappers that represent HTML block elements so that the editor can get a clearer idea about element nesting.
I'm new to Drupal and the community in general TwoD... could you tell me what you would the next step for this issue should be? I've noted in some posts/issues that the OP is asked to update the issue to be a feature request but I have no idea as to whether that's appropriate here and even if it is, I have no idea of how to do that...
Thank you very much for your help!
Comment #3
anandkp CreditAttribution: anandkp commentedFor ease of access, I've created the custom module as recommended by TwoD above including the modification that allows access to the "Visual Blocks" plugin that was added from version 3.5.x.x for TinyMCE.
Hope that the custom module will prove useful to others who want to enable the use of HTML5 elements for their Users...
Cheers!
Comment #4
sunErr. That style_formats looks fairly similar to the one of CKEditor?
http://www.tinymce.com/wiki.php/Configuration:style_formats
http://docs.cksource.com/CKEditor_3.x/Developers_Guide/Configuration/Styles
We just extended the API to allow to configure this specifically for CKEditor Styles:
#1650416: Allow editor specific changes to be made to the profile settings form
#746524: No Font Styles for CKeditor
Now, the syntax/settings of TinyMCE appear to be almost exactly the same... ;)
Comment #5
alanom CreditAttribution: alanom commentedRight, let's summarise.
If you want a) HTML5 block elements or b) Wrapper elements (e.g. a div with lots of paragraphs in it) in TinyMCE in Drupal, you can force them in as Styles that appear in the dropdown usually controlled by the CSS Styles box in the WYSIWYG module form.
You can do this two ways:
If you want to hard-code in a wrapper element that also has a class, it could look like this (note the slightly counter-intuitive 'classes' / string combo):
(tip for non-HTML5 wrappers: non-wrapper divs within a wrapper div are applied to the whole div. Non-wrapper
<p>
s within a wrapper div apply only to that paragraph)The stuff about Visual Blocks is a separate bonus TinyMCE feature, adding a button that toggles dotted-line outlining of block elements. It's an alternative to adding visual cues to using a custom TinyMCE stylesheet defined in the WYSIWYG module CSS Settings form. Using one or the other is a good idea so your users can see the scope of wrapper elements intuitively.
Comment #5.0
alanom CreditAttribution: alanom commentedCorrecting name of file I looked in to find clues as to what the problem is.
Comment #6
suldan CreditAttribution: suldan commentedHello,
Is something new happening on this issue? I gave the module wysiwyg_customisations a try and it worked - thanks a lot. But I was wondering why we are mixing up block formats and styles? Wouldn't it be better to have the new html5 elements in the block formats dropdown?
Just replacing style_formats with block_formats in wysiwyg_customisations.module didn't do the trick.
When using this module I am missing my custom styles. Can't I have both?
Greetings
suldan
Comment #7
TwoDNot much going on here, no. Not had time to dig into this.
If you're using TinyMCE 3, the block formats setting is called theme_advanced_blockformats, and it's also available for customization through hook_wysiwyg_editor_settings_alter(). Just note that since it's controllable via the editor profile GUI, it may already have a value (a string of comma-separated block tags).
If you're using Wysiwyg with the patch for TinyMCE 4, you can add the block_formats setting separately using the same hook.
Note that the block_formats setting takes a string, unlike the style_formats setting which takes an array.
Comment #8
igorski CreditAttribution: igorski commentedThe plugin from #3 has an issue which I have fixed now.
Comment #9
skylord CreditAttribution: skylord commentedBTW, solved this issue with simple patch (attached) - after it block formats override works well for me in TinyMCE4.
Comment #11
TwoDThanks for the patch @skylord, good catch!
I think I'm going to close this as "fixed" with this committed. The settings customization i mentioned in #7 still works and gives you total control of all editors which supports swapping out a block element's type like this.
The concerns mentioned in #6 about mixing "block formats" and "styles" I don't think I can really do much about without making things more confusing. As it currently is, the GUI widgets map to specific editor settings and tries to use their default values and functinality as established by the developers of each editor. If we go in and override these by say making an active choice to impose limitations on the profile GUI (say only allowing or defaulting to only using non-block element stuff in the styles area because that's already covered by another setting, etc), I think we'd end up having to make more and more tweaks until "everyone" is happy with the defaults, which is probably impossible. Sticking with what the editor does by default and not forcibly setting values on options that we haven't consciously touched in the GUI is a lot easier and would be much easier to stick with as the libraries evolve.