Forum

Thread tagged as: Problem

Removing default editor options

I'm trying to get my head around the new default editor configuration but failing… I used to comment out lines in the perch/addons/plugins/editors/markitup/config.js file if I didn't want that particular button/functionality to appear in the editor bar, but with Markitup now being built into core, if I do that in /perch/core/editors/markitup/config.js it'll be overwritten when I upgrade perch.

I'm guessing there's something in configuration sets or Custom configurations that I can do to disable buttons, but I'm having trouble working out what.

I guess I'd start by adding define('PERCH_CUSTOM_EDITOR_CONFIGS', true); to my perch/config/config.php file, and creating a perch/addons/plugins/editors/config.js file. Is it easy to disable name: 'File' in markdownSettings's markupSet from within this file?

Martin Underhill

Martin Underhill 5 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You need to write your Perch.UserConfig.markitup.get() function to return the MarkItUp configuration you want to use.

That defines a markupSet property which you can configure however you wish.

I think I've got there :)

I'm setting a new set of defaults (without h1s and without title attributes on links). Then if a type="textarea" has `editor-config="blog" it gets rid of links from the wee menu bar too.

Does this code look sensible or could it be more efficient?:

Perch.UserConfig.markitup = function(){

  var get = function(profile, config, field) {

    var markdownSettings = {
      nameSpace: 'markdown',
      previewParserPath:  '',
      onTab: {keepDefault:false, openWith:'    '},
      onShiftEnter:   {keepDefault:false, openWith:'\n\n'},
      markupSet: [
        {name:'Heading', key:'1', className:'fa fa-header', dropMenu: [
                // {name:'Heading 1', className:'fa fa-header', openWith:'# ',    placeHolder:'Your title here...' },
                {name:'Heading 2', className:'fa fa-header', openWith:'## ',   placeHolder:'Your title here...' },
                {name:'Heading 3', className:'fa fa-header', openWith:'### ',    placeHolder:'Your title here...' },
                {name:'Heading 4', className:'fa fa-header', openWith:'#### ',   placeHolder:'Your title here...' },
                {name:'Heading 5', className:'fa fa-header', openWith:'##### ',  placeHolder:'Your title here...' },
                {name:'Heading 6', className:'fa fa-header', openWith:'###### ', placeHolder:'Your title here...' }
                ]},
        {name:'Bold', className:'fa fa-bold', key:'B', openWith:'**', closeWith:'**'},
        {name:'Italic', className:'fa fa-italic', key:'I', openWith:'_', closeWith:'_'},
        {name:'Quotes', className:'fa fa-quote-left', openWith:'> '},
        {name:'Bulleted List', className:'fa fa-list-ul', openWith:'- ' },
        {name:'Numeric List', className:'fa fa-list-ol', openWith:function(markItUp) {
          return markItUp.line+'. ';
        }},
        {name:'Picture', className:'image-upload fa fa-picture-o', openWith:function(markItUp){miu.PerchAssets.upload(markItUp,'markdown');}},
        /{name:'File', className:'file-upload fa fa-file-o', openWith:function(markItUp){miu.PerchAssets.upload(markItUp,'markdown',true);}},
        // {name:'Link', className:'fa fa-link', key:'L', openWith:'[', closeWith:']([![URL:!:https://]!] "[![Title]!]")', placeHolder:'Your text to link here...' }
        {name:'Link', className:'fa fa-link', key:'L', openWith:'[', closeWith:']([![URL:!:https://]!])', placeHolder:'Your text to link here...' }
      ]
    };

    if (profile == 'blog') {
      markdownSettings.markupSet = [
        {name:'Heading', key:'1', className:'fa fa-header', dropMenu: [
                {name:'Heading 2', className:'fa fa-header', openWith:'## ',   placeHolder:'Your title here...' },
                {name:'Heading 3', className:'fa fa-header', openWith:'### ',    placeHolder:'Your title here...' },
                ]},
        {name:'Bold', className:'fa fa-bold', key:'B', openWith:'**', closeWith:'**'},
        {name:'Italic', className:'fa fa-italic', key:'I', openWith:'_', closeWith:'_'},
        {name:'Quotes', className:'fa fa-quote-left', openWith:'> '},
        {name:'Bulleted List', className:'fa fa-list-ul', openWith:'- ' },
        {name:'Numeric List', className:'fa fa-list-ol', openWith:function(markItUp) {
          return markItUp.line+'. ';
        }},
        {name:'Picture', className:'image-upload fa fa-picture-o', openWith:function(markItUp){miu.PerchAssets.upload(markItUp,'markdown');}},
        {name:'Link', className:'fa fa-link', key:'L', openWith:'[', closeWith:']([![URL:!:https://]!])', placeHolder:'Your text to link here...' }
      ];
    }

    return markdownSettings;
  };

  var load = function(cb) {
    cb();
  };

  return  {
    'get': get,
    'load': load
  }
}();

Thanks for steering me in the right direction!

Martin.

Drew McLellan

Drew McLellan 2638 points
Perch Support

If it's working then that's fine.