I have question why is the media module using tokens (json [[]]) and media wrappers (<!--MEDIA-WRAPPER-START etc)? why not a simple img element?

First the media wrappers are sometimes generating a mess. This can deleting part of the text when the wrapper are converted to tokens. I fixed this with:

    /**
     * Replaces the placeholders for html editing with the media tokens to store.
     * @param {string} content
     */
    replacePlaceholderWithToken: function(content) {
      var tagmap = Drupal.media.filter.ensure_tagmap();
      var i = 1,
          expression,
          result;
      for (var macro in tagmap) {

        var startTag = Drupal.media.filter.getWrapperStart(i), endTag = Drupal.media.filter.getWrapperEnd(i);
        var startPos = content.indexOf(startTag), endPos = content.indexOf(endTag);
        if (startPos !== -1 && endPos !== -1) {
          // If the placeholder wrappers are empty, remove the macro too.
          if (endPos - startPos - startTag.length === 0) {
            macro = '';
          }

          // Check if there are placeholders inside this wrapped html, replace those first
          var html = content.substring(startPos + startTag.length, endPos);
          if (html.indexOf('<--MEDIA-WRAPPER-START') > 0) {
              html = this.replacePlaceholderWithToken(html);
              content = content.substr(0, startPos + startTag.length) + html + content.substr(endPos);
              return this.replacePlaceholderWithToken(content);
          }

          // Restore everything that is typed before the img tag or after the img tag
          expression = RegExp(startTag + '(.*)<img[^>]*>(.*)' + endTag);
          result = expression.exec(content);
          if (result && result.length === 3) {
              macro = result[1]  + macro + result[2];
          }
          content = content.substr(0, startPos) + macro + content.substr(endPos + (new String(endTag)).length);
        }
        i++;
      }

      // Don't let media placeholders bungle around, remove them.
      content = content.replace(/<!--MEDIA-WRAPPER-(START|END)-\d*-->/g, '');
      return content;
    },

but when i turned on the module 'htmltidy' the token ([[]]) get scrambled by entitlements, so the filter from the media module cannot convert it back to a <img> element.

I fixed this to remove the token/placeholders functionality code like this:

    /**
     * Replaces media tokens with the placeholders for html editing.
     * @param content
     */
    replaceTokenWithPlaceholder: function(content) {
      return content;
    },

    /**
     * Replaces the placeholders for html editing with the media tokens to store.
     * @param content
     */
    replacePlaceholderWithToken: function(content) {
      return content;
    },

Is there any other solution out there? because my solution feels bad. And why are the tokens saved in the database and not the wrapped html?

Comments

skwashd’s picture

I am not exactly sure of the problem you're trying to solve, but it seems to me that you need to tweak your filter order. htmltidy should be the last filter you apply.

ericpinxteren’s picture

My problem is that the token's are encoded with html entities before the media module can convert them to markup.

I have my filter order configured like that.

Weight table:

  1. Convert Media tags to markup
  2. HTML Tidy

What i can see in code is that the implementation of the hook node_prepare of html tidy is messing things up. (htmltidy_node_prepare) I think this has no order of what filters first?

('m using the 7.x-1.0-beta2 of html tidy)

ericpinxteren’s picture

Issue summary: View changes
Chris Matthews’s picture

Version: 7.x-2.0-alpha3 » 7.x-2.x-dev
Status: Active » 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