How can i edit external link format converter rule in wagtail cms draftail editor

When someone adds an external link in Wagtail CMS, they should have the option to choose whether to make the link 'nofollow' or 'noreferrer.' To achieve this, I have inherited the existing link form, and the code is provided here

class CustomExternalLinkChooserForm(ExternalLinkChooserForm):

rel = forms.ChoiceField(
    choices=[
        ("noreferrer", "Noreferrer"),
        ("nofollow", "Nofollow"),
    ],
    required=False,
    label=_("Rel Attribute"),
)

i have also inherited view

class CustomExternalLinkView(ExternalLinkView):

form_class = CustomExternalLinkChooserForm

i registered this in wagtail hooks so admin take this override core view

@hooks.register("register_admin_urls")
def register_custom_external_link_view():

return [
    path(
        "admin/choose-external-link/",
        CustomExternalLinkView.as_view(),
        name="wagtailadmin_choose_page_external_link",
    )
]

By using the above, it gives me an output like this, but the main issue is that when the Draftail rich text editor saves the link in the database, it does not add the rel attribute in href url. How can I solve this issue? enter image description here

You will also need to customize the LinkHandlers. There is an example in the docs for how to add nofollow to all links. You will need to modify it to accept your dynamic attribute. https://docs.wagtail.org/en/stable/extending/rich_text_internals.html#registering-rewrite-handlers

Back to Top