<commit_before>// EasyMDE - Markdown Editor
// https://github.com/Ionaru/easy-markdown-editor

(function() {
  var insertMediaItem = function(instance, changeObj, $textArea) {
    var $mediaItemChooser = $('#media-item-chooser');

    $mediaItemChooser.modal('show');

    var cursor = instance.doc.getCursor();
    var prevPos = {
      line: cursor.line,
      ch: cursor.ch - 1
    };

    $(document).on('click.markdownImageUpload', '#media-item-chooser .media-library-link', function(e) {
      e.preventDefault();
      var id = $(this).attr('data-media-item-id');
      instance.doc.replaceRange(id, prevPos);
      $mediaItemChooser.modal('hide');
      $(document).off('click.markdownImageUpload');
    });
  };

  App.MarkdownTextEditor = {
    instances: [],
    initialize: function($textAreas) {
      var that = this;

      $textAreas.each(function() {
        var $textArea = $(this);
        var placeholder = $textArea.attr('placeholder');

        if ( ( $textArea.data('forest') && $textArea.data('forest').markdownInitialized ) || $textArea.closest('.CodeMirror').length ) {
          return;
        }

        $textArea.data('forest') || $textArea.data('forest', {});
        $textArea.data('forest', { markdownInitialized: true });

        var imageUploadToolbarObj = {
          name: 'image',
          title: 'Insert media item shortcode',
          action: EasyMDE.drawImage,
          className: 'fa fa-image'
        };
        var imageUpload = $textArea.hasClass('markdown-editor--image-upload') ? imageUploadToolbarObj : undefined;
        var blockquote = $textArea.hasClass('markdown-editor--blockquote') ? 'quote' : undefined;
        var noToolbar = $textArea.hasClass('markdown-editor--no-toolbar') ? true : false;
        var toolbarOptions = [
          'bold',
          'italic',
          'heading',
          blockquote,
          '|',
          'unordered-list',
          'ordered-list',
          '|',
          'link',
          imageUpload,
          '|',
          {
            name: 'guide',
            action: 'https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet',
            className: 'fa fa-question-circle',
            title: 'Markdown Guide',
            default: true
          },
        ];

        toolbarOptions = toolbarOptions.filter(function(x) {
          return x !== undefined;
        });

        if ( noToolbar ) toolbarOptions = false;

        var editor = new EasyMDE({
          element: this,
          placeholder: placeholder,
          spellChecker: false,
          status: false,
          autoDownloadFontAwesome: false,
          minHeight: '150px',
          toolbar: toolbarOptions,
          shortcuts: {
            'drawImage': null,
            'drawLink': null,
            'cleanBlock': null,
            'toggleBlockquote': null,
            'toggleCodeBlock': null,
            'toggleFullScreen': null,
            'toggleHeadingBigger': null,
            'toggleHeadingSmaller': null,
            'toggleOrderedList': null,
            'togglePreview': null,
            'toggleSideBySide': null,
            'toggleUnorderedList': null,
          },
          insertTexts: {
            image: ["[MEDIA_ITEM=", "]"],
          }
        });

        editor.codemirror.options.extraKeys['Tab'] = false;
        editor.codemirror.options.extraKeys['Shift-Tab'] = false;

        editor.codemirror.on('change', function(instance, changeObj) {
          if ( changeObj.text && changeObj.text[0] == '[MEDIA_ITEM=]' ) {
            insertMediaItem(instance, changeObj, $textArea);
          }<commit_msg>Add ability to specify markdown editor min height via data attributes<commit_after>// EasyMDE - Markdown Editor
// https://github.com/Ionaru/easy-markdown-editor

(function() {
  var insertMediaItem = function(instance, changeObj, $textArea) {
    var $mediaItemChooser = $('#media-item-chooser');

    $mediaItemChooser.modal('show');

    var cursor = instance.doc.getCursor();
    var prevPos = {
      line: cursor.line,
      ch: cursor.ch - 1
    };

    $(document).on('click.markdownImageUpload', '#media-item-chooser .media-library-link', function(e) {
      e.preventDefault();
      var id = $(this).attr('data-media-item-id');
      instance.doc.replaceRange(id, prevPos);
      $mediaItemChooser.modal('hide');
      $(document).off('click.markdownImageUpload');
    });
  };

  App.MarkdownTextEditor = {
    instances: [],
    initialize: function($textAreas) {
      var that = this;

      $textAreas.each(function() {
        var $textArea = $(this);
        var placeholder = $textArea.attr('placeholder');

        if ( ( $textArea.data('forest') && $textArea.data('forest').markdownInitialized ) || $textArea.closest('.CodeMirror').length ) {
          return;
        }

        $textArea.data('forest') || $textArea.data('forest', {});
        $textArea.data('forest', { markdownInitialized: true });

        var imageUploadToolbarObj = {
          name: 'image',
          title: 'Insert media item shortcode',
          action: EasyMDE.drawImage,
          className: 'fa fa-image'
        };
        var imageUpload = $textArea.hasClass('markdown-editor--image-upload') ? imageUploadToolbarObj : undefined;
        var blockquote = $textArea.hasClass('markdown-editor--blockquote') ? 'quote' : undefined;
        var noToolbar = $textArea.hasClass('markdown-editor--no-toolbar') ? true : false;
        var minHeight = $textArea.attr('data-min-height') || '150px';
        var toolbarOptions = [
          'bold',
          'italic',
          'heading',
          blockquote,
          '|',
          'unordered-list',
          'ordered-list',
          '|',
          'link',
          imageUpload,
          '|',
          {
            name: 'guide',
            action: 'https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet',
            className: 'fa fa-question-circle',
            title: 'Markdown Guide',
            default: true
          },
        ];

        toolbarOptions = toolbarOptions.filter(function(x) {
          return x !== undefined;
        });

        if ( noToolbar ) toolbarOptions = false;

        var editor = new EasyMDE({
          element: this,
          placeholder: placeholder,
          spellChecker: false,
          status: false,
          autoDownloadFontAwesome: false,
          minHeight: minHeight,
          toolbar: toolbarOptions,
          shortcuts: {
            'drawImage': null,
            'drawLink': null,
            'cleanBlock': null,
            'toggleBlockquote': null,
            'toggleCodeBlock': null,
            'toggleFullScreen': null,
            'toggleHeadingBigger': null,
            'toggleHeadingSmaller': null,
            'toggleOrderedList': null,
            'togglePreview': null,
            'toggleSideBySide': null,
            'toggleUnorderedList': null,
          },
          insertTexts: {
            image: ["[MEDIA_ITEM=", "]"],
          }
        });

        editor.codemirror.options.extraKeys['Tab'] = false;
        editor.codemirror.options.extraKeys['Shift-Tab'] = false;

        editor.codemirror.on('change', function(instance, changeObj) {
          if ( changeObj.text && changeObj.text[0] == '[MEDIA_ITEM=]' ) {
            insertMediaItem(instance, changeObj, $textArea);
          }
{'fraction_non_alphanumeric': 0.1411860718171926, 'fraction_numerical': 0.0013601741022850925, 'mean_word_length': 2.092094196804037, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6647783', 'n_tokens_mistral': 2126, 'n_tokens_neox': 2054, 'n_words': 376}