All wagtatail-markdown settings are defined in a single WAGTAILMARKDOWN dictionary in your settings file:
# settings.pyWAGTAILMARKDOWN= {
"autodownload_fontawesome": False,
"allowed_tags": [], # optional. a list of HTML tags. e.g. ['div', 'p', 'a']"allowed_styles": [], # optional. a list of styles"allowed_attributes": {}, # optional. a dict with HTML tag as key and a list of attributes as value"extensions": [], # optional. a list of python-markdown supported extensions"extension_configs": {}, # optional. a dictionary with the extension name as key, and its configuration as value
}
Note: allowed_tags, allowed_styles, allowed_attributes, extensions and extension_configs are added to the
default wagtail-markdown settings.
then add the following to a wagtail_hooks module in a registered app in your application:
# Content of app_name/wagtail_hooks.pyfromwagtail.coreimporthooksfromdjango.confimportsettingsfromdjango.utils.htmlimportformat_html@hooks.register("insert_global_admin_css")defimport_fontawesome_stylesheet():
elem='<link rel="stylesheet" href="{}path/to/font-awesome.min.css">'.format(
settings.STATIC_URL
)
returnformat_html(elem)
Note that due to the way EasyMDE defines the toolbar icons it is not compatible with
Wagtail FontAwesome
Using with django-compressor
You may have your own SCSS sources that you want to precompile on the fly.
We can invoke django-compressor to fetch our Font Awesome SCSS sources like this:
Allowed HTML - allowed_styles / allowed_attributes / allowed_tags
wagtail-markdown uses bleach to sanitise the input. To extend the default
bleach configurations, you can add your own allowed tags, styles or attributes:
Syntax highlighting using codehilite is an optional feature, which works by
adding CSS classes to the generated HTML. To use these classes, you will need
to install Pygments (pip install Pygments), and to generate an appropriate
stylesheet. You can generate one as per the Pygments documentation, with:
Note that this project uses pre-commit. To set up locally:
# if you don't have it yet
$ pip install pre-commit
# go to the project directory
$ cd wagtail-markdown
# initialize pre-commit
$ pre-commit install
# Optional, run all checks once for this, then the checks will run only on the changed files
$ pre-commit run --all-files
How to run tests
Now you can run tests as shown below:
tox -p
or, you can run them for a specific environment tox -e py39-django3.2-wagtail2.15 or specific test
tox -e py39-django3.2-wagtail2.15 tests.testapp.tests.test_admin.TestFieldsAdmin
请发表评论