• Stars
    star
    125
  • Rank 286,335 (Top 6 %)
  • Language
    Python
  • License
    Other
  • Created about 10 years ago
  • Updated about 3 years ago

Reviews

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

Repository Details

Depreciated in favor of rtfd/CommonMark-py

CommonMark-py

NOTE: This repo is no longer maintained and most likely contains numerous bugs, for the up to date and safe version you want rtfd/CommonMark-py.

Pure Python port of jgm's stmd.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 stmd.js.

We are currently at the same development stage (actually a bit ahead because we have implemented HTML entity conversion and href URL escaping) as stmd.js. Since Python versions pre-3.4 use outdated (i.e. not HTML5 spec) entity conversion, I've converted the 3.4 implementation into a single file, entitytrans.py which so far seems to work (all tests pass on 2.7, 3.3, 3.4, PyPy, and PyPy3).

Current version: 0.5.4

Build Status

Installation

rolands@kamaji:~$ pip install commonmark

Usage

import CommonMark
parser = CommonMark.DocParser()
renderer = CommonMark.HTMLRenderer()
ast = parser.parse("Hello *World*")
html = renderer.render(ast)
json = CommonMark.ASTtoJSON(ast)
CommonMark.dumpAST(ast) # pretty print generated AST structure
print(html) # <p>Hello <em>World</em><p/>

----- or -----

rolands@kamaji:~$ cmark.py README.md -o README.html
rolands@kamaji:~$ cmark.py README.md -o README.json -aj # output AST as JSON
rolands@kamaji:~$ cmark.py README.md -a # pretty print generated AST structure
rolands@kamaji:~$ cmark.py -h
usage: cmark.py [-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 stmd.js project a pull request adding your test to the existing test suite.

Tests

The tests script, CommonMark-tests.py, is pretty much a devtool. As well as running all the tests embeded 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 inputing a line with just end, to quit do the same but with quit). -d can be used to print call tracing.

rolands@kamaji:~/utils/CommonMark-py$ python CommonMark-tests.py -h
usage: CommonMark-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 seperated 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

theca

a simple, fully featured command line note taking tool written in Rust
Rust
357
star
2

solvere

A validating recursive DNS resolver library and standalone server with DNSSEC support
Go
33
star
3

docker-hsm

Run SoftHSM from a Docker container
20
star
4

dns-workbench

a simple authoritative DNS workbench server
Go
12
star
5

stapled

OCSP stapling daemon
Go
8
star
6

sesa

Go
5
star
7

d-AES

Python 3/2.7 module implementing the AES (Rijndael) cipher with key-dependent dynamic S-Boxes.
Python
4
star
8

gh-merge-bot

Go
4
star
9

postMonitor

cli tool to display all requests to a domain
Python
3
star
10

XORshift.js

A JS implementation of the XORshift PRNG
JavaScript
2
star
11

ctat

Certificate Transparency Analysis Toolchain
Go
2
star
12

zippy-cli

cli tool to download files from ZippyShare
Python
2
star
13

py-arc4random

python 2.7/3 implementation of OpenBSDs arc4random (RC4 based PRNG)
Python
2
star
14

nagios-plugins

various nagios plugins to monitor various strange things
Perl
2
star
15

caatest

A simple CLI tool to check for CAA record presence and validity for a specific issuer name
Go
2
star
16

funky-spider

a spider to trawl funkysouls threads for download links, download them, and manage the resulting content
Python
1
star
17

requestHook.js

hooks jQuery's $.ajax and by inheritence $.get and $.post
JavaScript
1
star
18

common-sh

a collection of semi-useful (bourne) shell functions
Shell
1
star
19

go-fuzzer-eval

Go
1
star
20

lxc-tools

a collection of tools written to help manage lxc containers
Python
1
star
21

quick-doc

quick python tool for documenting shell scripts
Python
1
star
22

cross-pollinator

Go
1
star
23

dotfiles

Python
1
star
24

gobservatory

Go
1
star
25

CommonMark-ASTcheck

tool to check validity of CommonMark spec AST structure.
Python
1
star
26

message-builder-js

JavaScript
1
star
27

luther

lightweight dynamic DNS web REST API in python
Python
1
star
28

acme-tls-alpn

Makefile
1
star
29

little-icinga

command-line direct push of icinga host/service status and scheduled daemon-pusher to a Little Printer
Perl
1
star