Skip to main content

Django Markdown View

https://travis-ci.org/rgs258/django-markdown-view.svg?branch=master https://coveralls.io/repos/github/rgs258/django-markdown-view/badge.svg?branch=master

Serve .md pages as Django views.

This package aims to make it easy to serve .md files on Django sites.

Requirements

Tested with:

The Tested With section describes aspirational goals.

  • Python: 3.5, 3.6, 3.7, 3.8

  • Django: 2.2, 3.0

Installation

  1. Install with pip install django-markdown-view.

  2. Add 'markdown_view' to your INSTALLED_APPS settings.

    INSTALLED_APPS = [
        ...,
        'markdown_view',
        ...
    ]
  3. (OPTIONAL) Add MARKDOWN_VIEW_BASE_DIR or BASE_DIR to settings

    The dictionary of the application’s base. See Settings below

    For example, if settings are in config/settings/base.py, then:

    BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))

Usage

Views

Use one of MarkdownView, LoggedInMarkdownView, or StaffMarkdownView from markdown_view.views to serve a .md file

from markdown_view.views import StaffMarkdownView

path('readme/',
    StaffMarkdownView.as_view(file_name='my_app/README.md'),
    name="readme"),

Settings

All settings are optional. See markdown_view/constants.py for the defaults.

  • MARKDOWN_VIEW_BASE_DIR and BASE_DIR

    When present, the value is taken as a location to append to the list of dirs that Django’s django.template.utils.get_app_template_dirs will return when passed dirname=””. This is used to locate .md files in the root of the project, e.g., a README.md file. Looks for BASE_DIR if MARKDOWN_VIEW_BASE_DIR is not found.

  • MARKDOWN_VIEW_LOADERS

    A list of loaders that locate .md files. The default list includes only markdown_view.loaders.MarkdownLoader which will by default try to load .md files from root directories in INSTALLED_APPS packages much the same as Django’s django.template.loaders.app_directories.Loader looks to load from “templates”.

  • MARKDOWN_VIEW_LOADER_TEMPLATES_DIR

    The 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_EXTENSIONS

    The extensions to enable. These extensions are enabled be default:

    • toc:

      generates a Table of Contents. If toc is removed from extensions, then MARKDOWN_VIEW_TEMPLATE_USE_TOC must be set to False.

    • tables:

      enables tables.

    • fenced_code:

      enables code blocks. If fenced_code is removed from extensions, then MARKDOWN_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.

    See https://python-markdown.github.io/extensions/ and https://github.com/Python-Markdown/markdown/wiki/Third-Party-Extensions for more extensions.

    You can create your own extensions by following https://github.com/Python-Markdown/markdown/wiki/Tutorial-1—Writing-Extensions-for-Python-Markdown

  • MARKDOWN_VIEW_TEMPLATE

    The 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 when use_toc is False.

    • page_title:

      A guess at a page title, for now it’s the first row of the TOC. Not set when use_toc is False.

  • MARKDOWN_VIEW_TEMPLATE_USE_TOC

    Whether to render the TOC. If false, in the template context, use_toc is False and markdown_toc and page_title are not present.

  • MARKDOWN_VIEW_TEMPLATE_USE_HIGHLIGHT_JS

    Whether to load and activate the highlight.js library in the template.

Experimental Settings

  • MARKDOWN_VIEW_USE_REQUEST_CONTEXT

    If 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_CONTEXT

    Any 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.

Implementation

At a high level, MarkdownView will:

  1. Use a template loader to locate .md given as file_name

  2. Render as a template, the contents of the .md file prepended with {{% load static %}}, into several context variables

  3. Serve the MARKDOWN_VIEW_TEMPLATE with the context variables

Contributing

All contributions are very welcomed. Propositions, problems, bugs, and enhancement are tracked with GitHub issues and patches are submitted via pull requests.

We use Travis coupled with Coveralls as continious integration tools.

Authors

Wharton Computing

  • Ryan J. Sullivan

Other

Changelog

0.0.4 (2020-07-09)

  1. Some documentation that didn’t make it into 0.0.3

0.0.3 (2020-07-09)

  1. Correct a typo the README.rst

  2. Add ids to the sections in the template

  3. Make more settings configurable

  4. Provide settings to disable optional functionality

  5. Add settings to, and generally improve, the README.rst

  6. Changed the project description to say “views” instead of “templates”

0.0.2 (2020-07-06)

  1. Remove support for Django pre-2.2

  2. Adds missing file markdown_view/markdown_extensions.py

0.0.1 (2020-06-16)

  1. Initial release.

Metadata

Release files for django-markdown-view 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-markdown-view 0.0.4
File Size Uploaded Provenance Actions
django-markdown-view-0.0.4.tar.gz 8.8 kB Without provenance Details for django-markdown-view-0.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-markdown-view 0.0.4
File Interpreter ABI Platform Actions
django_markdown_view-0.0.4-py2.py3-none-any.whl Python 3, Python 2 none any Details for django_markdown_view-0.0.4-py2.py3-none-any.whl

Total release size: 19.3 kB

Release files / django-markdown-view-0.0.4.tar.gz

Download URL django-markdown-view-0.0.4.tar.gz
Size 8.8 kB
Tags Source
SHA-256 checksum
How to use checksums
1c34b7ac214bf9e1899e7165d7831f284cd976e4f509640e4347d1e0c8c6a983
BLAKE2b-256 checksum
How to use checksums
75d1f8fe96fb324cdb9c3bb44d5a9ba935fd52bd6963933a971c12a50190a675
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.7.2

Release files / django_markdown_view-0.0.4-py2.py3-none-any.whl

Download URL django_markdown_view-0.0.4-py2.py3-none-any.whl
Size 10.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
dba29b010ca24642775c854243052446c438f5d642121eebe962c9ff2a617a90
BLAKE2b-256 checksum
How to use checksums
75ae0d2d0d8c6ae01b7121467f5898caebe0e2b3e1fc04c6254cd74a499224e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.7.2

Security for django-markdown-view 0.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page