In the media_wysiwyg.filter.js file, the create_element function assumes that the incoming html if an anchor tag must then be wrapping another HTML element.

For example, if you've changed the template for rendering file links out to not include a span or icon or anything, you cannot insert elements into the media wysiwyg.

The fix is pretty simple, just have the js check if the element has children before assigning element to its child value.

Old code

      // Parse out link wrappers. They will be re-applied when the image is
      // rendered on the front-end.
      if (element.is('a')) {
        element = element.children();
      }

New code

      // Parse out link wrappers. They will be re-applied when the image is
      // rendered on the front-end.
      if (element.is('a') && $(element).children().length > 0) {
        element = element.children();
      }

See http://cgit.drupalcode.org/media/tree/modules/media_wysiwyg/js/media_wys...

I can provide a patch if the code snippet above is acceptable.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dshields’s picture

Here's a patch for this.

Chris Matthews’s picture

Status: Needs review » Closed (outdated)

Closing this issue as outdated. However, if you think this issue is still important, please let us know and we will gladly re-open it for review.
sincerely,
- the Drupal Media Team