• Stars
    star
    2,636
  • Rank 17,359 (Top 0.4 %)
  • Language
    Python
  • License
    Other
  • Created almost 14 years ago
  • Updated 3 months ago

Reviews

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

Repository Details

markdown2: A fast and complete implementation of Markdown in Python

Markdown is a light text markup format and a processor to convert that to HTML. The originator describes it as follows:

Markdown is a text-to-HTML conversion tool for web writers. Markdown allows you to write using an easy-to-read, easy-to-write plain text format, then convert it to structurally valid XHTML (or HTML).

-- http://daringfireball.net/projects/markdown/

This (markdown2) is a fast and complete Python implementation of Markdown. It was written to closely match the behaviour of the original Perl-implemented Markdown.pl. Markdown2 also comes with a number of extensions (called "extras") for things like syntax coloring, tables, header-ids. See the "Extra Syntax" section below. "markdown2" supports all Python versions 3.5+ (and pypy and jython, though I don't frequently test those).

There is another Python markdown.py. However, at least at the time this project was started, markdown2.py was faster (see the Performance Notes) and, to my knowledge, more correct (see Testing Notes). That was a while ago though, so you shouldn't discount Python-markdown from your consideration.

Follow @trentmick for updates to python-markdown2.

Install

To install it in your Python installation run one of the following:

pip install markdown2
pip install markdown2[all]  # to install all optional dependencies (eg: Pygments for code syntax highlighting)
pypm install markdown2      # if you use ActivePython (activestate.com/activepython)
easy_install markdown2      # if this is the best you have
python setup.py install

However, everything you need to run this is in "lib/markdown2.py". If it is easier for you, you can just copy that file to somewhere on your PythonPath (to use as a module) or executable path (to use as a script).

Quick Usage

As a module:

>>> import markdown2
>>> markdown2.markdown("*boo!*")  # or use `html = markdown_path(PATH)`
'<p><em>boo!</em></p>\n'

>>> from markdown2 import Markdown
>>> markdowner = Markdown()
>>> markdowner.convert("*boo!*")
'<p><em>boo!</em></p>\n'
>>> markdowner.convert("**boom!**")
'<p><strong>boom!</strong></p>\n'

As a script (CLI):

$ python markdown2.py foo.md > foo.html

or

$ python -m markdown2 foo.md > foo.html

I think pip-based installation will enable this as well:

$ markdown2 foo.md > foo.html

See the project wiki, lib/markdown2.py docstrings and/or python markdown2.py --help for more details.

Extra Syntax (aka extensions)

Many Markdown processors include support for additional optional syntax (often called "extensions") and markdown2 is no exception. With markdown2 these are called "extras". Using the "footnotes" extra as an example, here is how you use an extra ... as a module:

$ python markdown2.py --extras footnotes foo.md > foo.html

as a script:

>>> import markdown2
>>> markdown2.markdown("*boo!*", extras=["footnotes"])
'<p><em>boo!</em></p>\n'

There are a number of currently implemented extras for tables, footnotes, syntax coloring of <pre>-blocks, auto-linking patterns, table of contents, Smarty Pants (for fancy quotes, dashes, etc.) and more. See the Extras wiki page for full details.

Project

The python-markdown2 project lives at https://github.com/trentm/python-markdown2/. (Note: On Mar 6, 2011 this project was moved from Google Code to here on Github.) See also, markdown2 on the Python Package Index (PyPI).

The change log: https://github.com/trentm/python-markdown2/blob/master/CHANGES.md

To report a bug: https://github.com/trentm/python-markdown2/issues

Contributing

We welcome pull requests from the community. Please take a look at the TODO for opportunities to help this project. For those wishing to submit a pull request to python-markdown2 please ensure it fulfills the following requirements:

  • It must pass PEP8.
  • It must include relevant test coverage.
  • Bug fixes must include a regression test that exercises the bug.
  • The entire test suite must pass.
  • The README and/or docs are updated accordingly.

Test Suite

This markdown implementation passes a fairly extensive test suite. To run it:

make test

The crux of the test suite is a number of "cases" directories -- each with a set of matching .text (input) and .html (expected output) files. These are:

tm-cases/                   Tests authored for python-markdown2 (tm=="Trent Mick")
markdowntest-cases/         Tests from the 3rd-party MarkdownTest package
php-markdown-cases/         Tests from the 3rd-party MDTest package
php-markdown-extra-cases/   Tests also from MDTest package

See the Testing Notes wiki page for full details.

More Repositories

1

node-bunyan

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

json

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

django-markdown-deux

A django app that provides Markdown-related template tags using the python-markdown2 library.
Python
287
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