简体   繁体   中英

How to automatically put rel=“nofollow” for all the external links in SummerNote editor?

I just recently tried to implement the SummerNote editor in my project but then I realized that all the external links don't have the rel="nofollow" attribute.

How can I include this attribute automatically?

Thanks for the help. minedbp

The only way to do that is to: 1) Download the CDN Summernote JavaScript file and store within your application folders which is to be bound to your code as path instead of https url.

2) Open, Clean and Modify the code. Search for the line where the <a> element is being created and add the property you want.

Here are points where the HTML Anchor element is being created:

a)

 var anchors = [];
                if (isTextChanged) {
                    rng = rng.deleteContents();
                    var anchor = rng.insertNode($$1('<A>' + linkText + '</A>')[0]);
                    anchors.push(anchor);
                }

b)

AutoLink.prototype.replace = function () {
            if (!this.lastWordRange) {
                return;
            }
            var keyword = this.lastWordRange.toString();
            var match = keyword.match(linkPattern);
            if (match && (match[1] || match[2])) {
                var link = match[1] ? keyword : defaultScheme + keyword;
                var node = $$1('<a />').html(keyword).attr('href', link)[0];
                this.lastWordRange.insertNode(node);
                this.lastWordRange = null;
                this.context.invoke('editor.focus');
            }
        };

c)

 var anchors = [];
                if (isTextChanged) {
                    rng = rng.deleteContents();
                    var anchor = rng.insertNode($$1('<A>' + linkText + '</A>')[0]);
                    anchors.push(anchor);
                }

Simply search for <a on the document to see these methods. Edit as appropriately and you're good to go.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM