Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="columns">
  <div class="column full">
    <h1>Drag and Drop Markdown Images</h1>
    <p>You can drag an image onto the textarea to insert a markdown formatted image link like - <code>![alt text](link)</code>.</p>
    
    <p>By default the image gets dropped at the end of the text, but if you select the text to replace or click to set the insert position the markdown will appear exactly where you want it!</p>
  </div>
</div>

<hr />

<div class="columns"><div class="column one-quarter"><img src="http://placehold.it/300&text=1" alt="One" class="selectable"/></div>
  <div class="column one-quarter"><img src="http://placehold.it/300&text=2" alt="Two" class="selectable"/></div>
  <div class="column one-quarter"><img src="http://placehold.it/300&text=3" alt="Three" class="selectable"/></div>
  <div class="column one-quarter"><img src="http://placehold.it/300&text=4" alt="Four" class="selectable"/></div>
</div>

<div class="columns">
  <div class="column full">
    <textarea name="article[body]" id="article-body" cols="30" rows="10">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Animi dolorum maxime deserunt aliquam iste unde aperiam porro eum ipsum natus culpa numquam quidem itaque optio magni aliquid nihil. Quas neque.
    
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</textarea>
  </div>
</div>


              
            
!

CSS

              
                *{
  box-sizing: border-box;
}

hr{
  background: #ededed;
  border: none;
  height: 1px;
  margin-bottom: 18px;
  width: 100%;
}

.columns{
  padding: 18px;
  width: 100%;
  
  overflow: auto;
  clear: both;
}

.column{
  border-right: 1px solid #f3f3f3;
  float: left;
  
  &.one-quarter{
     width: 25%; 
    &:nth-of-type(4n){
      border-right: 1px solid #fff;
    }
  }
  
  &.full{
    border-right: none;
    width: 100%;
  }
}

.selectable{
  cursor: move;
}

img{
  display: block;
  width: 100%;
  height: auto;
  
  &.moving{
    opacity: 0.3;
  }
}

#article-body{
  border: 1px solid #dedede;
  border-radius: 6px;
  color: #5a5a5a;
  padding: 12px;
  width: 100%;
}

body{
  color: #7b7b7b; 
}
h1{
  color: #5a5a5a;
}
              
            
!

JS

              
                document.addEventListener('readystatechange', function(e){ 
  if(document.readyState == "interactive") {
    var form = document.getElementById('article-body')
      , imgs = document.getElementsByClassName('selectable');
    
    
    [].forEach.call(imgs, function(img){
      img.addEventListener('dragstart', function(e){
        this.classList.add('moving');
        e.dataTransfer.setData('src', this.getAttribute('src'));
        e.dataTransfer.setData('alt', this.getAttribute('alt'));
      });
      img.addEventListener('dragend', function(e){
        this.classList.remove('moving');
      });
    });
    
    form.addEventListener('drop', function(e){
      if(e.preventDefault) {
        e.preventDefault();
      }
      
      var oldText = this.value;
      var markdown = "![" + e.dataTransfer.getData('alt') + "](" + e.dataTransfer.getData('src') + ")";
      if(this.selectionStart) {
        this.value = oldText.substring(0, this.selectionStart) + markdown + oldText.substring(this.selectionEnd);
      } else {
        this.value += "\n\n" + markdown;
      }
      this.focus();
    });
    
    form.addEventListener('dragover', function(e){
      if(e.stopPropagation) {
        e.stopPropagation();
      }
      console.log(e);
      e.dataTransfer.dropEffect = 'copy';
    });
  }
});
              
            
!
999px

Console