• This repository has been archived on 26/Mar/2022
  • Stars
    star
    241
  • Rank 164,161 (Top 4 %)
  • Language
    Python
  • License
    Other
  • Created almost 10 years ago
  • Updated over 2 years ago

Reviews

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

Repository Details

DEPRECATED: Python CommonMark parser

commonmark.py

No Maintenance Intended

Warning: commonmark.py is now deprecated. We recommend using markdown-it-py for a commonmark parser going forward. See this issue for background and discussion.

commonmark.py is a pure Python port of jgm's commonmark.js, a Markdown parser and renderer for the CommonMark specification, using only native modules. Once both this project and the CommonMark specification are stable we will release the first 1.0 version and attempt to keep up to date with changes in commonmark.js.

commonmark.py is tested against the CommonMark spec with Python versions 2.7, 3.5, 3.6, 3.7, and 3.8.

Current version: 0.9.1

Pypi Link Build Status Documentation Status

Installation

$ pip install commonmark

Usage

>>> import commonmark
>>> commonmark.commonmark('*hello!*')
'<p><em>hello!</em></p>\n'

Or, without the syntactic sugar:

import commonmark
parser = commonmark.Parser()
ast = parser.parse("Hello *World*")

renderer = commonmark.HtmlRenderer()
html = renderer.render(ast)
print(html) # <p>Hello <em>World</em><p/>

# inspecting the abstract syntax tree
json = commonmark.dumpJSON(ast)
commonmark.dumpAST(ast) # pretty print generated AST structure

There is also a CLI:

$ cmark README.md -o README.html
$ cmark README.md -o README.json -aj # output AST as JSON
$ cmark README.md -a # pretty print generated AST structure
$ cmark -h
usage: cmark [-h] [-o [O]] [-a] [-aj] [infile]

Process Markdown according to the CommonMark specification.

positional arguments:
  infile      Input Markdown file to parse, defaults to stdin

optional arguments:
  -h, --help  show this help message and exit
  -o [O]      Output HTML/JSON file, defaults to stdout
  -a          Print formatted AST
  -aj         Output JSON AST

Contributing

If you would like to offer suggestions/optimizations/bugfixes through pull requests please do! Also if you find an error in the parser/renderer that isn't caught by the current test suite please open a new issue and I would also suggest you send the commonmark.js project a pull request adding your test to the existing test suite.

Tests

To work on commonmark.py, you will need to be able to run the test suite to make sure your changes don't break anything. To run the tests, you can do something like this:

$ pyvenv venv
$ ./venv/bin/python setup.py develop test

The tests script, commonmark/tests/run_spec_tests.py, is pretty much a devtool. As well as running all the tests embedded in spec.txt it also allows you to run specific tests using the -t argument, provide information about passed tests with -p, percentage passed by category of test with -s, and enter markdown interactively with -i (In interactive mode end a block by inputting a line with just end, to quit do the same but with quit). -d can be used to print call tracing.

$ ./venv/bin/python commonmark/tests/run_spec_tests.py -h
usage: run_spec_tests.py [-h] [-t T] [-p] [-f] [-i] [-d] [-np] [-s]

script to run the CommonMark specification tests against the commonmark.py
parser.

optional arguments:
  -h, --help  show this help message and exit
  -t T        Single test to run or comma separated list of tests (-t 10 or -t 10,11,12,13)
  -p          Print passed test information
  -f          Print failed tests (during -np...)
  -i          Interactive Markdown input mode
  -d          Debug, trace calls
  -np         Only print section header, tick, or cross
  -s          Print percent of tests passed by category

Authors

More Repositories

1

readthedocs.org

The source code that powers readthedocs.org
Python
7,860
star
2

sphinx_rtd_theme

Sphinx theme from Read the Docs
Sass
4,670
star
3

sphinx-autoapi

A new approach to API documentation in Sphinx.
Python
411
star
4

recommonmark

A markdown parser for docutils
Python
339
star
5

tutorial-template

Template for the Read the Docs tutorial
Python
303
star
6

ethical-ad-server

The ethical ad server - ads for developers without all the tracking
Python
180
star
7

template

A template Sphinx repo
116
star
8

readthedocs-docker-images

Docker image definitions used by Read the Docs
Dockerfile
113
star
9

sphinx-hoverxref

Sphinx extension to show tooltips with content embedded when hover a reference.
Python
93
star
10

ethical-ad-client

Ethical Ads JavaScript client
JavaScript
60
star
11

sphinx-notfound-page

Create a custom 404 page with absolute URLs hardcoded
Python
42
star
12

tutorial-sphinx-markdown

Jupyter Notebook
33
star
13

ethicalads.io

This repository contains the public marketing website for EthicalAds. The ad server is in the ethical-ad-server repository.
CSS
33
star
14

readthedocs-sphinx-search

Enable search-as-you-type feature for docs hosted by RTD.
Python
32
star
15

actions

GitHub Actions for Read the Docs
JavaScript
31
star
16

pydoc.io

A browser for Python project documentation
Python
25
star
17

ads-for-opensource

An Adblock/AdblockPlus/uBlock compatible filter list for allowing advertising that benefits open source
Python
21
star
18

readthedocs-build

Work in Progress builder
Python
19
star
19

common

Shared bits around multiple repositories
Python
19
star
20

blog

Read the Docs blog
CSS
18
star
21

readthedocs-sphinx-ext

[RTD Internal] This is an extension that we install on all Sphinx builds on Read the Docs
Python
17
star
22

sphinxcontrib-dotnetdomain

A Sphinx domain for .NET languages
Python
15
star
23

website

The Read the Docs community website
HTML
14
star
24

addons

JavaScript client to integrate with Read the Docs nicely
JavaScript
14
star
25

guidelines

Style, brand, and development guidelines
Makefile
13
star
26

livesphinx

A fork of rst.ninjs.org to support Sphinx
CSS
13
star
27

godocjson

Generate json from go.
Go
9
star
28

rtd-sphinx-themes-examples

A project illustrating different Sphinx themes locally and on Read the Docs
Python
7
star
29

tutorial-sphinx-markdown-library

Python
7
star
30

web

Different scenarios (one per branch) to test different build configs on production
7
star
31

apitheme

Sphinx API documentation theme
JavaScript
6
star
32

bot

Bot for Read the Docs monitoring
JavaScript
5
star
33

sphinx-multiproject

Share a single conf.py file between several Sphinx projects
Python
4
star
34

sphinxcontrib-multisrc

Sphinx multiple source path support
Python
2
star
35

time-test

A test repo for Read the Docs
Python
2
star
36

readthedocs-assistant

Python
2
star
37

site-community-images

Source images for our website graphics
Makefile
1
star
38

rtd-mkdocs-test

A Project for testing versions of MkDocs on Read the Docs
1
star
39

analytical

Analytics done server side
Python
1
star
40

validatehttp

HTTP response validation application
Python
1
star
41

test-sphinx-theme

JavaScript
1
star
42

rtd-git-stresstest

A stress test for git on Read the Docs
Python
1
star
43

sui-common-theme

Shared base SUI theme for our website and application
1
star
44

abandoned-project

A repo to build docs for abandoned projects
1
star
45

ext-theme

Read the Docs drop in replacement site templates
HTML
1
star