public function generateContent(TinyMCEConfig $config)
    {
        $tinymceDir = $config->getTinyMCEResource();

        // List of string / ModuleResource references to embed
        $files = [];

        // Add core languages
        $language = $config->getOption('language');
        if ($language) {
            $files[] = $this->resolveRelativeResource($tinymceDir, "langs/{$language}");
        }

        // Add plugins, along with any plugin specific lang files
        foreach ($config->getPlugins() as $plugin => $path) {
            // Add external plugin
            if ($path) {
                // Skip external urls
                if (is_string($path) && !Director::is_site_url($path)) {
                    continue;
                }
                // Convert URLS to relative paths
                if (is_string($path)) {
                    $path = Director::makeRelative($path);
                }
                // Ensure file exists
                if ($this->resourceExists($path)) {
                    $files[] = $path;
                }
                continue;
            }

            // Core tinymce plugin
            $files[] = $this->resolveRelativeResource($tinymceDir, "plugins/{$plugin}/plugin");
            if ($language) {
                $files[] = $this->resolveRelativeResource($tinymceDir, "plugins/{$plugin}/langs/{$language}");
            }
        }

        // Add themes
        $theme = $config->getTheme();
        if ($theme) {
            $files[] = $this->resolveRelativeResource($tinymceDir, "themes/{$theme}/theme");
            if ($language) {
                $files[] = $this->resolveRelativeResource($tinymceDir, "themes/{$theme}/langs/{$language}");
            }
        }

        // Process source files
        $files = array_filter($files);
        $libResource = $this->resolveRelativeResource($tinymceDir, 'tinymce');
        $libContent = $this->getFileContents($libResource);

        // Register vars for config
        $baseDirJS = Convert::raw2js(Director::absoluteBaseURL());
        $name = Convert::raw2js($this->checkName($config));
        $buffer = [];
        $buffer[] = <<<SCRIPT
(function() {
  var baseTag = window.document.getElementsByTagName('base');
  var baseURL = baseTag.length ? baseTag[0].baseURI : '$baseDirJS';
  var editorIdentifier = '$name';
SCRIPT;
        $buffer[] = <<<SCRIPT
(function() {
  // Avoid double-registration
  if (window.tinymce) {
    return;
  }

  var tinyMCEPreInit = {
    base: baseURL,
    suffix: '.min',
  };
  $libContent
})();
SCRIPT;

        // Load all tinymce script files into buffer
        foreach ($files as $path) {
            $buffer[] = $this->getFileContents($path);
        }

        // Generate urls for all files
        // Note all urls must be relative to base_dir
        $fileURLS = array_map(function ($path) {
            if ($path instanceof ModuleResource) {
                return Director::makeRelative($path->getURL());
            }
            return $path;
        }, $files);

        // Join list of paths
        $filesList = Convert::raw2js(implode(',', $fileURLS));
        // Mark all themes, plugins and languages as done
        $buffer[] = "window.tinymce.each('$filesList'.split(',')," . "function(f){tinymce.ScriptLoader.markDone(baseURL+f);});";

        $buffer[] = '})();';
        return implode("\n", $buffer) . "\n";
    }