Skip to content
This repository was archived by the owner on Mar 26, 2022. It is now read-only.

Rename package name to commonmark #131

Merged
merged 2 commits into from
Sep 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CommonMark
8 changes: 0 additions & 8 deletions CommonMark/__init__.py

This file was deleted.

29 changes: 15 additions & 14 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ include README.rst
include LICENSE
include .gitignore
include spec.txt
include CommonMark/__init__.py
include CommonMark/blocks.py
include CommonMark/common.py
include CommonMark/dump.py
include CommonMark/entitytrans.py
include CommonMark/inlines.py
include CommonMark/main.py
include CommonMark/node.py
include CommonMark/utils.py
include CommonMark/render/__init__.py
include CommonMark/render/renderer.py
include CommonMark/render/html.py
include CommonMark/tests/run_spec_tests.py
include CommonMark/tests/unit_tests.py
include commonmark/__init__.py
include commonmark/blocks.py
include commonmark/common.py
include commonmark/dump.py
include commonmark/entitytrans.py
include commonmark/inlines.py
include commonmark/main.py
include commonmark/node.py
include commonmark/utils.py
include commonmark/render/__init__.py
include commonmark/render/renderer.py
include commonmark/render/html.py
include commonmark/tests/run_spec_tests.py
include commonmark/tests/unit_tests.py
include CommonMark
24 changes: 12 additions & 12 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,25 @@ Usage

::

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

Or, without the syntactic sugar:

.. code:: python

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

renderer = CommonMark.HtmlRenderer()
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
json = commonmark.dumpJSON(ast)
commonmark.dumpAST(ast) # pretty print generated AST structure

There is also a CLI:

Expand Down Expand Up @@ -92,7 +92,7 @@ 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
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
Expand All @@ -103,11 +103,11 @@ tracing.

::

$ ./venv/bin/python CommonMark/tests/run_spec_tests.py -h
$ ./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
script to run the CommonMark specification tests against the CommonMark-py
parser.

optional arguments:
-h, --help show this help message and exit
Expand All @@ -124,7 +124,7 @@ Authors

- `Bibek Kafle <https://github.com/kafle>`__
- `Roland Shoemaker <https://github.com/rolandshoemaker>`__
- `Nik Nyby <https://github.com/nikolas>`__
- `Nikolas Nyby <https://github.com/nikolas>`__

.. |Build Status| image:: https://travis-ci.org/rtfd/CommonMark-py.svg?branch=master
:target: https://travis-ci.org/rtfd/CommonMark-py
Expand Down
8 changes: 8 additions & 0 deletions commonmark/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# flake8: noqa
from __future__ import unicode_literals, absolute_import

from commonmark.main import commonmark
from commonmark.dump import dumpAST, dumpJSON
from commonmark.blocks import Parser
from commonmark.render.html import HtmlRenderer
from commonmark.render.rst import ReStructuredTextRenderer
22 changes: 11 additions & 11 deletions CommonMark/blocks.py → commonmark/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import re
from importlib import import_module
from CommonMark import common
from CommonMark.common import unescape_string
from CommonMark.inlines import InlineParser
from CommonMark.node import Node
from CommonMark.utils import to_camel_case
from commonmark import common
from commonmark.common import unescape_string
from commonmark.inlines import InlineParser
from commonmark.node import Node
from commonmark.utils import to_camel_case


CODE_INDENT = 4
Expand Down Expand Up @@ -610,12 +610,12 @@ def add_child(self, tag, offset):
""" Add block of type tag as a child of the tip. If the tip can't
accept children, close and finalize it and try its parent,
and so on til we find a block that can accept children."""
block_class = getattr(import_module('CommonMark.blocks'),
block_class = getattr(import_module('commonmark.blocks'),
to_camel_case(self.tip.t))
while not block_class.can_contain(tag):
self.finalize(self.tip, self.line_number - 1)
block_class = getattr(
import_module('CommonMark.blocks'),
import_module('commonmark.blocks'),
to_camel_case(self.tip.t))

column_number = offset + 1
Expand Down Expand Up @@ -731,7 +731,7 @@ def incorporate_line(self, ln):

self.find_next_nonspace()
block_class = getattr(
import_module('CommonMark.blocks'),
import_module('commonmark.blocks'),
to_camel_case(container.t))
rv = block_class.continue_(self, container)
if rv == 0:
Expand All @@ -757,7 +757,7 @@ def incorporate_line(self, ln):
self.all_closed = (container == self.oldtip)
self.last_matched_container = container

block_class = getattr(import_module('CommonMark.blocks'),
block_class = getattr(import_module('commonmark.blocks'),
to_camel_case(container.t))
matched_leaf = container.t != 'paragraph' and block_class.accepts_lines
starts = self.block_starts
Expand Down Expand Up @@ -824,7 +824,7 @@ def incorporate_line(self, ln):
cont.last_line_blank = last_line_blank
cont = cont.parent

block_class = getattr(import_module('CommonMark.blocks'),
block_class = getattr(import_module('commonmark.blocks'),
to_camel_case(t))
if block_class.accepts_lines:
self.add_line()
Expand Down Expand Up @@ -853,7 +853,7 @@ def finalize(self, block, line_number):
above = block.parent
block.is_open = False
block.sourcepos[1] = [line_number, self.last_line_length]
block_class = getattr(import_module('CommonMark.blocks'),
block_class = getattr(import_module('commonmark.blocks'),
to_camel_case(block.t))
block_class.finalize(self, block)

Expand Down
10 changes: 5 additions & 5 deletions CommonMark/cmark.py → commonmark/cmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import unicode_literals
import argparse
import sys
import CommonMark
import commonmark


def main():
Expand All @@ -27,7 +27,7 @@ def main():
parser.add_argument('-a', action="store_true", help="Print formatted AST")
parser.add_argument('-aj', action="store_true", help="Output JSON AST")
args = parser.parse_args()
parser = CommonMark.Parser()
parser = commonmark.Parser()
f = args.infile
o = args.o
lines = []
Expand All @@ -36,16 +36,16 @@ def main():
data = "".join(lines)
ast = parser.parse(data)
if not args.a and not args.aj:
renderer = CommonMark.HtmlRenderer()
renderer = commonmark.HtmlRenderer()
o.write(renderer.render(ast))
exit()
if args.a:
# print ast
CommonMark.dumpAST(ast)
commonmark.dumpAST(ast)
exit()

# o.write(ast.to_JSON())
o.write(CommonMark.dumpJSON(ast))
o.write(commonmark.dumpJSON(ast))
exit()


Expand Down
2 changes: 1 addition & 1 deletion CommonMark/common.py → commonmark/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from .entitytrans import _unescape
HTMLunescape = _unescape
else:
from CommonMark import entitytrans
from commonmark import entitytrans
HTMLunescape = entitytrans._unescape

ENTITY = '&(?:#x[a-f0-9]{1,8}|#[0-9]{1,8}|[a-z][a-z0-9]{1,31});'
Expand Down
2 changes: 1 addition & 1 deletion CommonMark/dump.py → commonmark/dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from builtins import str
import json
from CommonMark.node import is_container
from commonmark.node import is_container


def prepare(obj, topnode=False):
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions CommonMark/inlines.py → commonmark/inlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import re
import sys
from CommonMark import common
from CommonMark.common import normalize_uri, unescape_string
from CommonMark.node import Node
from commonmark import common
from commonmark.common import normalize_uri, unescape_string
from commonmark.node import Node

if sys.version_info >= (3, 0):
if sys.version_info >= (3, 4):
Expand All @@ -14,7 +14,7 @@
from .entitytrans import _unescape
HTMLunescape = _unescape
else:
from CommonMark import entitytrans
from commonmark import entitytrans
HTMLunescape = entitytrans._unescape

# Some regexps used in inline parser:
Expand Down
16 changes: 8 additions & 8 deletions CommonMark/main.py → commonmark/main.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# 2014 - Bibek Kafle & Roland Shoemaker
# 2015-2017 - Nik Nyby
# 2015-2017 - Nikolas Nyby
# Port of @jgm's commonmark.js implementation of the CommonMark spec.

# Basic usage:
#
# import CommonMark
# parser = CommonMark.Parser()
# renderer = CommonMark.HtmlRenderer()
# import commonmark
# parser = commonmark.Parser()
# renderer = commonmark.HtmlRenderer()
# print(renderer.render(parser.parse('Hello *world*')))

from __future__ import absolute_import, unicode_literals

from CommonMark.blocks import Parser
from CommonMark.dump import dumpAST, dumpJSON
from CommonMark.render.html import HtmlRenderer
from CommonMark.render.rst import ReStructuredTextRenderer
from commonmark.blocks import Parser
from commonmark.dump import dumpAST, dumpJSON
from commonmark.render.html import HtmlRenderer
from commonmark.render.rst import ReStructuredTextRenderer


def commonmark(text, format="html"):
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions CommonMark/render/html.py → commonmark/render/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import re
from builtins import str
from CommonMark.common import escape_xml
from CommonMark.render.renderer import Renderer
from commonmark.common import escape_xml
from commonmark.render.renderer import Renderer


reUnsafeProtocol = re.compile(
Expand Down
8 changes: 4 additions & 4 deletions CommonMark/render/rst.py → commonmark/render/rst.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import unicode_literals


from CommonMark.render.renderer import Renderer
from commonmark.render.renderer import Renderer


class ReStructuredTextRenderer(Renderer):
Expand All @@ -12,12 +12,12 @@ class ReStructuredTextRenderer(Renderer):

.. code:: python

import CommonMark
import commonmark

parser = CommonMark.Parser()
parser = commonmark.Parser()
ast = parser.parse('Hello `inline code` example')

renderer = CommonMark.ReStructuredTextRenderer()
renderer = commonmark.ReStructuredTextRenderer()
rst = renderer.render(ast)
print(rst) # Hello ``inline code`` example
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import unittest

import CommonMark
import commonmark


class TestCommonmark(unittest.TestCase):
def setUp(self):
self.parser = CommonMark.Parser()
self.renderer = CommonMark.ReStructuredTextRenderer()
self.parser = commonmark.Parser()
self.renderer = commonmark.ReStructuredTextRenderer()

def render_rst(self, test_str):
ast = self.parser.parse(test_str)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import argparse
import sys
from builtins import str
from CommonMark.render.html import HtmlRenderer
from CommonMark.main import Parser, dumpAST
from commonmark.render.html import HtmlRenderer
from commonmark.main import Parser, dumpAST


class colors(object):
Expand Down
10 changes: 5 additions & 5 deletions CommonMark/tests/test.md → commonmark/tests/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ Installation
Usage
-----

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

----- or -----
Expand Down
Loading