Code Monkey home page Code Monkey logo

wagtail-markdown's Introduction

wagtail-markdown: Markdown fields and blocks for Wagtail

Tired of annoying rich text editors getting in the way of your content input? Wish Wagtail worked more like a wiki? Well, now it can.

wagtail-markdown provides Markdown field support for Wagtail. Specifically, it provides:

  • A wagtailmarkdown.blocks.MarkdownBlock for use in streamfields.
  • A wagtailmarkdown.fields.MarkdownField for use in page models.
  • A wagtailmarkdown.edit_handlers.MarkdownPanel for use in the editor interface.
  • A markdown template tag.

The markdown rendered is based on python-markdown, but with several extensions to make it actually useful in Wagtail:

  • Tables.
  • Code highlighting.
  • Inline links to pages (<:My page name|link title>) and documents (<:doc:My fancy document.pdf>), and inline images (<:image:My pretty image.jpeg>).
  • Inline Markdown preview using SimpleMDE

These are implemented using the python-markdown extension interface.

Installation

Alpha release is available on Pypi - https://pypi.org/project/wagtail-markdown/ - installable via pip install wagtail-markdown. It's not a production ready release.

Using it

Add it to INSTALLED_APPS:

INSTALLED_APPS += [
    'wagtailmarkdown',
]

Use it as a StreamField block:

from wagtailmarkdown.blocks import MarkdownBlock

class MyStreamBlock(StreamBlock):
    markdown = MarkdownBlock(icon="code")

Or use as a page field:

from wagtailmarkdown.edit_handlers import MarkdownPanel
from wagtailmarkdown.fields import MarkdownField

class MyPage(Page):
    body = MarkdownField()

    content_panels = [
        FieldPanel("title", classname="full title"),
        MarkdownPanel("body"),
    ]

And render the content in a template:

{% load wagtailmarkdown %}
<article>
{{ self.body|markdown }}
</article>

You can pass extensions by name to the filter:

{% load wagtailmarkdown %}
<article>
{{ self.body|markdown:"my_extension_package.my_extension_module" }}
</article>

The markdown filter sanitizes the output of the underlying markdown processor, to prevent an untrusted user from passing malicious markup. This may conflict with some extensions. When additional extensions are specified, it is possible to specify what additional HTML must be allowed through. This is done by defining a module variable allowed_markup for extensions specified as "module name", or a class variable allowed_markup for extensions specified as "module_name:class_name". In either case it is possible to recursively add to the bleach white list for tags, attributes, and styles. For example, adding

allowed_markup = {
  tags : ["sub"],
  attributes : { img : ["srcset"] },
  styles : [ "text-decoration-line" ]
}

to the extension module allows subscripts, image source sets, and text decoration (such as underline or strike through) in addition to the HTML permitted by default.

To enable syntax highlighting please use the Pygments (pip install Pygments) library.

NB: The current version was written in about an hour and is probably completely unsuitable for production use. Testing, comments and feedback are welcome: [email protected] (or open a Github issue).

Roadmap for 0.5

wagtail-markdown's People

Contributors

abrunyate avatar bashu avatar benjaoming avatar drockolla avatar johnfraney avatar juyrjola avatar kevinhowbrook avatar rspeed avatar stuaxo avatar thorin-schiffer avatar tm-kn avatar unixwitch avatar

Stargazers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.