torchbox / wagtail-footnotes

MIT License
20 stars 18 forks source link

Adding footnotes to existing RichTextField features #35

Closed benjaoming closed 4 months ago

benjaoming commented 2 years ago

The README implies to add features=["footnotes"] but doesn't give guidance on how to simply extend the list of already existing features.

Do I need to register a hook? Or do I write out the entire features list like:

RichTextField(features=["h1", "h2", "h3", "h4", "h5", "h6", "bold", "italic", "ol", "ul", "hr", "link", "document-link", "image", "embed", "footnotes"])
zerolab commented 2 years ago

it should be the full list of features one wants, as per https://docs.wagtail.org/en/stable/advanced_topics/customisation/page_editing_interface.html#rich-text-features

benjaoming commented 2 years ago

Thanks @zerolab ! Do you know if a variable or method exists such that it's possible at model-load time to instantiate with features=WAGTAIL_DEFAULT_RICHTEXT + ["footnotes"] ? I noticed that changing features doesn't cause any new migrations, so could be safe as a dynamic argument :+1:

zerolab commented 2 years ago

you could define this globally

# settings.py
WAGTAILADMIN_RICH_TEXT_EDITORS = {
    "default": {
        "WIDGET": "wagtail.admin.rich_text.DraftailRichTextArea",
        "OPTIONS": {"features": ["bold", "italic", "h3", "h4", "ol", "ul", "link", "footnotes"]},
    }
}

alternatively try adding your setting with default features, and do what you describe. It should work (note: haven't tried)

the DraftailRichTextArea widget does: https://cs.github.com/wagtail/wagtail/blob/12ba7d8161a0055211541402f759f92acfbd0ba3/wagtail/admin/rich_text/editors/draftail/__init__.py?q=DraftailRichTextArea#L9 and https://cs.github.com/wagtail/wagtail/blob/12ba7d8161a0055211541402f759f92acfbd0ba3/wagtail/admin/rich_text/editors/draftail/__init__.py?q=DraftailRichTextArea#L33

benjaoming commented 2 years ago

Thank you!! Exactly the advice I was looking for :heart:

I'll try to make a PR with some README updates, don't close the issue yet :)

benjaoming commented 2 years ago

I was just checking if I can use get_default_features for RichTextField(features=...) but I don't think there's an easy way since it cannot be imported at model load time.

django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.
zerolab commented 4 months ago

Fixed in #37