TinyMCE is tripping out "align" attributes from div tags. I know the solution involves adding div[align] to the extended valid elements. With the TinyMCE module, I used to do this by editing tinymce.module. How would I do this now that I'm using the Wysiwyg API?

Comments

sun’s picture

Dunno. But maybe http://drupal.org/project/wysiwyg_filter might assist you.

jonmower’s picture

What I've done for now is edit tinymce.inc and add the valid element that I want to one of the extended_valid_elements arrays of one of the buttons that I have selected.

I'll try the the wysiwyg_filter at some point, but my impression from poking around there that there is a desire to make it work nicely with Wysiwyg API but that hasn't been achieved yet. Therefore, my guess is that it wouldn't have the effect of allowing elements that tinymce currently strips out...but I don't know for sure.

sun’s picture

Status: Active » Closed (won't fix)

Well, I don't think that Wysiwyg API will support any cryptic configuration options anytime soon.

tyates’s picture

jonmower - Would you mind sharing with a newbie how to add to the extended_valid_elements array in tinymce.inc?

I need tinymce to keep empty div placeholders and have read that adding d[*] to the extended_valid_elements will do the trick. Wysiwyg_filter didn't do it. This ability is a deal killer for us.

Wysiwyg is a great module and I am not knocking the design decisions - I just need a work around that maybe other people don't need.

omerida’s picture

In your own module, define a plugin like this and tinymce won't strip out seemingly empty divs as long as they have an id, class, or style.

/* Implementation of hook_wysiwyg_plugin(). */
function MYMODUKE_wysiwyg_plugin($editor) {
  switch ($editor) {
    case 'tinymce':
      return array(
          'divwa' => array(
              'extensions' => array('div' => t('DIVs with attributes')),
              'extended_valid_elements' => array('div[id|class|style]'),
              'load' => FALSE,
              'internal' => TRUE,
          ),
      );
  }
}
fuerst’s picture

Alternatively use hook_wysiwyg_editor_settings_alter() to change settings like this:

/**
 * Implementation of hook_wysiwyg_editor_settings_alter().
 * 
 */
function YOURMODULE_wysiwyg_editor_settings_alter(&$settings, $context) {
  if ($context['profile']->editor == 'tinymce') {
    if (strstr($settings['extended_valid_elements'], 'div[')) {
      // Add "align" attribute to an existing DIV tag setting
      $settings['extended_valid_elements'] .= preg_replace('/div\[([^\]]*)\]/', 'div[$1|align]', $settings['extended_valid_elements']);
    }
    else {
      // Add complete DIV Tag setting if not existing
      $settings['extended_valid_elements'] .= ',div[id|class|style|align]';
    }
  }
}

Replace YOURMODULE by the name of your custom module (see Module developer's guide).

niccottrell’s picture

Thanks fuerst! Works in D7 too :)

BenMirkhah’s picture

Thanks, just modified your code to allow inline SVG images inside TinyMCE WYSIWYG...

function inlinesvg_wysiwyg_editor_settings_alter(&$settings, $context) {
  if ($context['profile']->editor == 'tinymce') {
    $svgtags = 'svg[*],style[*],defs[*],pattern[*],desc[*],metadata[*],g[*],mask[*],path[*],line[*],marker[*],rect[*],circle[*],ellipse[*],polygon[*],polyline[*],linearGradient[*],radialGradient[*],stop[*],image[*],view[*],text[*],textPath[*],title[*],tspan[*],glyph[*],symbol[*],switch[*],use[*]';

    if ($settings['extended_valid_elements']) { //Add to the existing valid element list
      $settings['extended_valid_elements'] .= ','.$svgtags;
    } else { //Create a new valid elements list
      $settings['extended_valid_elements'] = $svgtags;
    }
  }
}