Package: django-markdown-view
Serve .md pages as Django views.This package aims to make it easy to serve .md files on Django sites.ContentsInstallationUsageViewsSettingsExperimental SettingsImplementationRelease Notes and ContributorsContributingRequirementsNoteThis package needs tests, and to have Travis and Coveralls properly configured.InstallationInstall withpip installdjango-markdown-view.Add'markdown_view'to yourINSTALLED_APPSsettings.INSTALLED_APPS=[...,'markdown_view',...](OPTIONAL) AddMARKDOWN_VIEW_BASE_DIRorBASE_DIRto settingsThe dictionary of the application’s base. SeeSettingsbelowFor example, if settings are in config/settings/base.py, then:BASE_DIR=os.path.dirname(os.path.dirname(os.path.dirname(__file__)))UsageViewsUse one ofMarkdownView,LoggedInMarkdownView, orStaffMarkdownViewfrommarkdown_view.viewsto serve a .md filefrommarkdown_view.viewsimportStaffMarkdownViewpath('readme/',StaffMarkdownView.as_view(file_name='my_app/README.md'),name="readme"),SettingsAll settings are optional. Seemarkdown_view/constants.pyfor the defaults.MARKDOWN_VIEW_BASE_DIRandBASE_DIRWhen present, the value is taken as a location to append to the list of dirs that
Django’sdjango.template.utils.get_app_template_dirswill return when passeddirname=””. This is used to locate .md files in the root of the project, e.g.,
a README.md file. Looks forBASE_DIRifMARKDOWN_VIEW_BASE_DIRis not found.MARKDOWN_VIEW_LOADERSA list of loaders that locate .md files. The default list includes onlymarkdown_view.loaders.MarkdownLoaderwhich will by default try to load .md files
from root directories in INSTALLED_APPS packages much the same as Django’sdjango.template.loaders.app_directories.Loaderlooks to load from “templates”.MARKDOWN_VIEW_LOADER_TEMPLATES_DIRThe name of the directories in INSTALLED_APPS packages in which to locate .md
files. Defaults to “” in order to locate .md filed in the root directories.MARKDOWN_VIEW_EXTENSIONSThe extensions to enable. These extensions are enabled be default:toc:generates a Table of Contents. Iftocis removed from extensions, thenMARKDOWN_VIEW_TEMPLATE_USE_TOCmust be set to False.tables:enables tables.fenced_code:enables code blocks. Iffenced_codeis removed from extensions, thenMARKDOWN_VIEW_TEMPLATE_USE_HIGHLIGHT_JS, which provides the highlighting for
code blocks, can be disabled.markdown_view.markdown_extensions.ImageExtension:makes images responsive in bootstrap4.Seehttps://python-markdown.github.io/extensions/andhttps://github.com/Python-Markdown/markdown/wiki/Third-Party-Extensionsfor more
extensions.You can create your own extensions by followinghttps://github.com/Python-Markdown/markdown/wiki/Tutorial-1—Writing-Extensions-for-Python-MarkdownMARKDOWN_VIEW_TEMPLATEThe Django template that’ll be used to render the HTML that is generated from the
Markdown. Set your own template to style your pages. Context includes:markdown_content:The HTML produced from the Markdown.use_highlight_js:If highlight.js is enabled.use_toc:If the table of contents should be rendered.markdown_toc:A table of contents from the headers of the Markdown. Not set whenuse_tocis False.page_title:A guess at a page title, for now it’s the first row of the TOC. Not set whenuse_tocis False.MARKDOWN_VIEW_TEMPLATE_USE_TOCWhether to render the TOC. If false, in the template context,use_tocis False
andmarkdown_tocandpage_titleare not present.MARKDOWN_VIEW_TEMPLATE_USE_HIGHLIGHT_JSWhether to load and activate the highlight.js library in the template.Experimental SettingsMARKDOWN_VIEW_USE_REQUEST_CONTEXTIf the request context should be used as a base when creating the context with
which to render the Markdown internally. This is because the Markdown is rendered
once first in order to prepend it with{% load static %}.
This is not well tested; YMMV.MARKDOWN_VIEW_EXTRA_CONTEXTAny extra context to send to the internal render of the Markdown. Can be used
to expose context to template tags embedded in the Markdown.
This is not well tested; YMMV.ImplementationAt a high level,MarkdownViewwill:Use a template loader to locate.mdgiven asfile_nameRender as a template, the contents of the.mdfile prepended with{% load static %}, into several context variablesServe theMARKDOWN_VIEW_TEMPLATEwith the context variablesRelease Notes and ContributorsRelease notesOur wonderful contributorsContributingAll contributions are very welcomed. Propositions, problems, bugs, and
enhancement are tracked withGitHub issuesand patches are submitted
viapull requests.We useTraviscoupled withCoverallsas continious integration tools.RequirementsWe aspire to support the currently supported versions of Django.The Tested With section describes aspirational goals.Tested with:Python: 3.6, 3.7, 3.8, 3.9, 3.10Django: 2.2, 3.2, 4.0