Inscryb / inscryb-markdown-editor

A simple, beautiful, and embeddable JavaScript Markdown editor. Based off SimpleMDE by Sparksuite.
MIT License
90 stars 16 forks source link

Text-Alignment Custom Functions #4

Closed catecomm closed 6 years ago

catecomm commented 6 years ago

[X] Feature Request / Code Assistance

I know Markdown doesn't have text alignment, but I did see this editor does allow custom functions. So in theory I could add 3 buttons, left/center/right align. But I have no idea what the function code would be to add a class to the end of the line that would support text alignment.

I know in Markdown by adding { .text-center} to the end of a line, it will add the class needed to center the text. The function would have to add this text when clicked/enabled, and remove it if disabled. And if possible, to have the icon selected and not selected appropriately.

Any help in the right direction would be appreciated.

CWharton commented 6 years ago

On the custom toolbar add a customFunction() like this

{
  name: 'image',
  action: function customFunction(editor) {
    editor.codemirror.execCommand('goLineEnd');
    editor.codemirror.replaceSelection('INPUT HERE');
  },
  className: 'fa fa-input',
  title: 'Insert Input',
},

This will add 'INPUT HERE' to the end of the line.

Depending on your implementation of markdown you choose will determine how to proceed.

It might help if you dig into the codemirror documentation to see its capabilities. This editor is build on top of codemirror.

CWharton commented 6 years ago

This is not in the scope of the markdown standard. If you with to implement this in the editor please use a custom function in the toolbar.