Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is There a Way To Limit The Available Paragraph Styles in Summernote?

I'm using summernote for editing in a basic CMS. Here is the code I am using:

$(document).ready(function() {

        $("#summernote").summernote({
            height: 600,
                styleWithSpan: false,
                toolbar: [
                    ['style', ['bold', 'italic', 'underline']],
                    ['para', ['ul', 'ol', 'paragraph','style']],
                    ['view', ['codeview']],
                    ['insert', ['mypicture','link','table','hr']]
                        ],
                        buttons: {
                            mypicture: PictureButton
                          },
                          disableDragAndDrop: true
                });

                $('#save').click(function(){
                    var mysave = $('#summernote').summernote('code');
                    $('#content').val(mysave);
                });
    });

In the toolbar I use ['para',['style']] to allow the user to choose heading/paragraph styles like H1 and P.
Is there any way to limit the dropdown to only allowing them to use H1, H2, and P?

like image 455
jcmiller11 Avatar asked Oct 20 '25 00:10

jcmiller11


1 Answers

You can easily achieve it by changing your code this way

$(document).ready(function() {

        $("#summernote").summernote({
            height: 600,
                styleWithSpan: false,
                toolbar: [
                      ['style', ['bold', 'italic', 'underline']],
                      ['para', ['ul', 'ol', 'paragraph','style']],
                    ['view', ['codeview']],
                    ['insert', ['mypicture','link','table','hr']]
                ],
                styleTags: ['p', 'h1', 'h2'],
                buttons: {
                    mypicture: PictureButton
                },
                disableDragAndDrop: true

                });

                $('#save').click(function(){
                    var mysave = $('#summernote').summernote('code');
                    $('#content').val(mysave);
                });
    });

where the relevant line is styleTags: ['p', 'h1', 'h2'].

like image 77
Eddie C. Avatar answered Oct 21 '25 13:10

Eddie C.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!