How to add a custom paragraph format in CKEditor

后端 未结 2 553
野的像风
野的像风 2021-01-18 01:56

In my project I have a requirement to remove the paragraph format like \"Address\" and \"Formatted\" from the drop down and to add a new custom format called \"Links\" which

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-18 02:05

    Since you're working with Drupal, ckeditor.styles.js is the file you're looking for, this will allow you to add/edit/remove entries in the Styles menu.

    Comment out any entries you don't want, and use something like this to add a new paragraph format:

    { name : 'Links', element : 'p', attributes : { 'class' : 'links' } },
    

    This will add the CSS class links to whatever paragraph you want, and you can define the class in your theme stylesheet. Make sure to define the class in ckeditor.css if you don't see the changes applied in the CKEditor instance.

    Alternatively, you could also apply the inline styles directly:

    { name : 'Links', element : 'p', attributes : { 'style' : 'font: bold 14px Arial, sans-serif; color: red;' } },
    

    But the first method is clearly more flexible/clean.

    Make sure to clear your Drupal and/or browser cache if you don't see your changes show up immediately.

提交回复
热议问题