torchbox / wagtail-markdown

Markdown support for Wagtail
zlib License
198 stars 66 forks source link

Add `allowed_*` and `extension*` settings control mode #108

Closed zerolab closed 2 years ago

zerolab commented 2 years ago

Defaults to extend, but can also replace.

allowed_*

allowed_settings_mode: "extend" or "replace". default: "replace"

Previously allowed_tags and allowed_styles would get extended, and allowed_attributes would extend where new keys were added, and replace where keys existed. Now they all extend by default, and in replace mode everything gets replaced by what is provided in settings.

e.g.

WAGTAILMARKDOWN = {
   "allowed_tags": ["code"],
   "allowed_styles": ["something"],
   "allowed_attributes": {"*": ["data-toggle"], "code": ["data-lang"]},
   "allowed_settings_mode": "extend",  # optional. Possible values: "extend" or "replace". Defaults to "extend".
}

would result in default tags + "code", default styles + "something". Default allowed attributes would have {"": ["data-toggle"], "code": ["data-lang"], ...}added, but now they are{"": ["class", "style", "id", "data-toggle"], "code": ["data-lang"], ...}as expected from extend. With replace: allowed tags:["code"], styles:["something"], and attributes: {"*": ["data-toggle"], "code": ["data-lang"]}

extension*

extensions_settings_mode: "extend" or "replace". default: "replace"

e.g. with:

WAGTAILMARKDOWN = {
    "extensions": ["pymdownx.arithmatex"],  
    "extension_configs": {
        "pymdownx.arithmatex": {"generic": True}
    },
    "extensions_settings_mode": "extend",  # optional. Possible values: "extend" or "replace". Defaults to "extend".
}
extend replace
pymdownx.arithmatex gets added to the list of default extensions pymdownx.arithmatex is the only extension
extension_configs get the additional configuration for pymdownx.arithmatex extension_configs only has the configuration for pymdownx.arithmatex