• Stars
    star
    287
  • Rank 144,232 (Top 3 %)
  • Language
    Python
  • License
    Other
  • Created over 14 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A django app that provides Markdown-related template tags using the python-markdown2 library.

A small Django app that provides template tags for using Markdown using the python-markdown2 library.

What's with the "deux" in the name?

The obvious name for this project is django-markdown2. However, there already is one! and name confusion doesn't help anybody. Plus, I took French immersion in school for 12 years: might as well put it to use.

So why another project then?

Because I wanted to do something slightly different. Django-markdown2's markdown filter takes "extras" as arguments -- with the one exception that "safe" is transformed to python-markdown2's safe_mode argument. This is handy for quick usage. My use case is more commonly: lots of markdown filter and block usage in my Django templates with the same set of python-markdown2 options.

Installation

Choose the one of the following that works best for you:

  • Install the latest release from PyPI:

      pip install django-markdown-deux
    

    or, if you use ActivePython:

      pypm install django-markdown-deux
    

    These should install the dependent python-markdown2 package.

  • Get a git clone of the source tree:

      git clone git://github.com/trentm/django-markdown-deux.git
    

    You might want a particular tag:

      cd django-markdown-deux
      git tag -l   # list available tags
      git checkout $tagname
    

    Then you'll need the "lib" subdir on your PYTHONPATH:

      python setup.py install # or 'export PYTHONPATH=`pwd`/lib:$PYTHONPATH'
    

    You'll also need the python-markdown2 library:

      git clone [email protected]:trentm/python-markdown2.git
      cd python-markdown2
      python setup.py install   # or 'export PYTHONPATH=`pwd`/python-markdown2/lib'
    

Django project setup

  1. Add markdown_deux to INSTALLED_APPS in your project's "settings.py".

  2. Optionally set some of the MARKDOWN_DEUX_* settings. See the "Settings" section below.

Usage

The markdown_deux facilities typically take an optional "style" argument. This is a name for a set of options to the python-markdown2 processor. There is a "default" style that is used if no argument is given. See the MARKDOWN_DEUX_STYLES setting below for more.

markdown template filter

{% load markdown_deux_tags %}
...
{{ myvar|markdown:"STYLE" }}      {# convert `myvar` to HTML using the "STYLE" style #}
{{ myvar|markdown }}              {# same as `{{ myvar|markdown:"default"}}` #}

markdown template block tag

{% load markdown_deux_tags %}
...
{% markdown STYLE %}        {# can omit "STYLE" to use the "default" style #}
This is some **cool**
[Markdown](http://daringfireball.net/projects/markdown/)
text here.
{% endmarkdown %}

markdown_allowed template tag

In a template:

{% markdown_allowed %}

will emit a short HTML blurb that says Markdown syntax is allowed. This can be handy for placing under form elements that accept markdown syntax. You can also use it as the help_text for a form field something like:

# myapp/forms.py
from markdown_deux.templatetags.markdown_deux_tags import markdown_allowed
class MyForm(forms.Form):
    #...
    description = forms.CharField(
        label="Description (required)",
        widget=forms.Textarea(attrs={"rows": 5}),
        help_text=_secondary_span("A brief description of your thing.<br/> "
            + markdown_allowed()),
        required=True)

markdown_cheatsheet tag

{% markdown_cheatsheet %}

This outputs HTML giving a narrow (appropriate for, e.g., a sidebar) listing of some of the more common Markdown features.

markdown_deux.markdown(TEXT, STYLE) in your Python code

The markdown filter and block tags above ultimately use this markdown_deux.markdown(...) function. You might find it useful to do Markdown processing in your Python code (e.g. in a view, in a model .save() method).

Settings

All settings for this app are optional.

MARKDOWN_DEUX_STYLES setting

A mapping of style name to a dict of keyword arguments for python-markdown2's markdown2.markdown(text, **kwargs). For example the default setting is effectively:

MARKDOWN_DEUX_STYLES = {
    "default": {
        "extras": {
            "code-friendly": None,
        },
        "safe_mode": "escape",
    },
}

I.e. only the "default" style is defined and it just uses the code-friendly extra and escapes raw HTML in the given Markdown (for safety).

Here is how you might add styles of your own, and preserve the default style:

# settings.py
from markdown_deux.conf.settings import MARKDOWN_DEUX_DEFAULT_STYLE

MARKDOWN_DEUX_STYLES = {
    "default": MARKDOWN_DEUX_DEFAULT_STYLE,
    "trusted": {
        "extras": {
            "code-friendly": None,
        },
        # Allow raw HTML (WARNING: don't use this for user-generated
        # Markdown for your site!).
        "safe_mode": False,
    },
    # Here is what http://code.activestate.com/recipes/ currently uses.
    "recipe": {
        "extras": {
            "code-friendly": None,
        },
        "safe_mode": "escape",
        "link_patterns": [
            # Transform "Recipe 123" in a link.
            (re.compile(r"recipe\s+#?(\d+)\b", re.I),
             r"http://code.activestate.com/recipes/\1/"),
        ],
        "extras": {
            "code-friendly": None,
            "pyshell": None,
            "demote-headers": 3,
            "link-patterns": None,
            # `class` attribute put on `pre` tags to enable using
            # <http://code.google.com/p/google-code-prettify/> for syntax
            # highlighting.
            "html-classes": {"pre": "prettyprint"},
            "cuddled-lists": None,
            "footnotes": None,
            "header-ids": None,
        },
        "safe_mode": "escape",
    }
}

MARKDOWN_DEUX_HELP_URL setting

A URL for to which to link for full markdown syntax default. This link is only in the output of the markdown_allowed and markdown_cheatsheet template tags.

The default is http://daringfireball.net/projects/markdown/syntax, the canonical Markdown syntax reference. However, if your site uses Markdown with specific tweaks, you may prefer to have your own override. For example, ActiveState Code uses:

MARKDOWN_DEUX_HELP_URL = "/help/markdown/"

To link to its own Markdown syntax notes URL.

More Repositories

1

node-bunyan

a simple and fast JSON logging module for node.js services
JavaScript
7,175
star
2

python-markdown2

markdown2: A fast and complete implementation of Markdown in Python
Python
2,636
star
3

json

A "json" command for massaging JSON on your Unix command line.
JavaScript
1,544
star
4

node-dashdash

A light, featureful and explicit option parsing library for node.js.
JavaScript
176
star
5

node-ldapauth

**UNMAINTAINED.** Simple node.js module to authenticate against an LDAP server
Perl
126
star
6

jirash

CLI and (light) shell for Jira
JavaScript
79
star
7

cmdln

**UNMAINTAINED** a Python module for easily building good multi-command scripts
Python
49
star
8

node-cmdln

node.js helper lib for creating CLI tools with subcommands; think `git`, `svn`, `zfs`
JavaScript
31
star
9

googlecode2github

Helper scripts and docs for moving a project from Google Code project hosting to Github
Python
24
star
10

nodedoc

a fledgling `perldoc` for node.js
Python
18
star
11

python-jira-cli

(my fork of) the Python JIRA command line interface (to add some conveniences)
Python
17
star
12

node-bunyan-winston

demo showing how to use a winston logger with a bunyan-using library (e.g. restify)
JavaScript
17
star
13

node-ansidiff

a small node.js library for ANSI colored text diffs
JavaScript
17
star
14

eol

a command-line script and Python module for working with text file end-of-line (EOL) characters
Python
17
star
15

preprocess

Automatically exported from code.google.com/p/preprocess
Python
15
star
16

node-csvrow

parse a CSV row string (in node.js)
JavaScript
13
star
17

hello-json-logging

An introduction to restify + bunyan for JSON logging in node.js API services.
JavaScript
13
star
18

sources

a command-line script to help get/clone/checkout and update source repos
Python
13
star
19

molybdenum

A git repo browser (for when your git repos aren't on GitHub)
JavaScript
12
star
20

node-expiring-lru-cache

An expiring LRU cache object for node.js
JavaScript
12
star
21

go-tool

Automatically exported from code.google.com/p/go-tool
Python
10
star
22

which

A portal Python GNU which replacement
Python
9
star
23

cutarelease

A script to help cutting releases of your projects in a single step (following some conventions).
Python
8
star
24

dotfiles

Trent's dotfiles
Python
8
star
25

go-ecslog

`ecslog` CLI to pretty-print and filter log files in ecs-logging format
Go
7
star
26

minimalist-python-module

How small can a project be to support a single module Python project.
Python
7
star
27

ircgrep

a command-line tool for grepping through IRC channel logs
Python
6
star
28

mdocml

A mirror/fork of mdocml from <http://mdocml.bsd.lv/>. I'm adding an "html5" output mode.
C
4
star
29

node-kthxbai

Kill Those Huge eXtra (node_module) Bits Absentmindedly Installed
JavaScript
4
star
30

talk-bunyan-in-prod

Slides for a talk called "Bunyan logging in production at Joyent"
JavaScript
3
star
31

otellogsplay

/me playing with OTel logging
JavaScript
2
star
32

python-process

an obsolete Python module for process control (currently unmaintained)
Python
2
star
33

listadmin

Fork of Kjetil Torgrim Homme's "listadmin" script for processing Mailman admin db. I have some minor changes for my personal usage.
Perl
2
star
34

node-ruhroh

helper lib to create the Error classes for restify-based API services
JavaScript
2
star
35

node-tabula

a light function for printing a text table to stdout
JavaScript
2
star
36

testlib

A micro unittest suite harness for Python
Python
1
star
37

trentm.github.com

CSS
1
star
38

lambdock

an example Node.js AWS Lambda Docker container with Elastic APM instrumentation
Dockerfile
1
star
39

npm-registry-proxy

a simple and *limited* proxy for registry.npmjs.org for testing npm
JavaScript
1
star
40

template-node-package

Trent's template for node package (for use with https://help.github.com/en/articles/creating-a-repository-from-a-template)
Makefile
1
star