diff --git a/readme_renderer/clean.py b/readme_renderer/clean.py index 74f6a93..76bf02c 100644 --- a/readme_renderer/clean.py +++ b/readme_renderer/clean.py @@ -27,9 +27,9 @@ "strong", "ul", # Custom Additions - "br", "cite", "col", "colgroup", "dd", "div", "dl", "dt", "h1", "h2", "h3", - "h4", "h5", "h6", "hr", "img", "p", "pre", "span", "sub", "sup", "table", - "tbody", "td", "th", "thead", "tr", "tt", "kbd", "var", + "br", "cite", "col", "colgroup", "dd", "del", "div", "dl", "dt", "h1", + "h2", "h3", "h4", "h5", "h6", "hr", "img", "p", "pre", "span", "sub", + "sup", "table", "tbody", "td", "th", "thead", "tr", "tt", "kbd", "var", ] ALLOWED_ATTRIBUTES = { @@ -43,6 +43,8 @@ "hr": ["class"], "img": ["src"], "span": ["class"], + "th": ["align"], + "td": ["align"], } ALLOWED_STYLES = [] diff --git a/readme_renderer/markdown.py b/readme_renderer/markdown.py index dae389e..cfdec80 100644 --- a/readme_renderer/markdown.py +++ b/readme_renderer/markdown.py @@ -18,9 +18,20 @@ from .clean import clean -variants = { - "CommonMark": commonmark, -} +try: + import cmarkgfm +except ImportError: + cmarkgfm = None + + +variants = {} + +if cmarkgfm is not None: + variants["gfm"] = cmarkgfm.github_flavored_markdown_to_html + # Preferentially use cmarkgfm for CommonMark. + variants["CommonMark"] = cmarkgfm.markdown_to_html +else: + variants["CommonMark"] = commonmark def render(raw, variant="CommonMark", **kwargs): diff --git a/setup.py b/setup.py index 08697e0..08ff708 100644 --- a/setup.py +++ b/setup.py @@ -67,6 +67,10 @@ "six", ], + extras_require={ + "gfm": "cmarkgfm>=0.1.0" + }, + entry_points={ "distutils.commands": [ "check = readme_renderer.integration.distutils:Check", diff --git a/tests/fixtures/test_gfm_001.html b/tests/fixtures/test_gfm_001.html new file mode 100644 index 0000000..822a121 --- /dev/null +++ b/tests/fixtures/test_gfm_001.html @@ -0,0 +1,12 @@ +
foo | +bar | +
---|---|
baz | +bim | +
abc | +defghi | +
---|---|
bar | +baz | +
f|oo | +
---|
b | az |
+
b | im | +
abc | +def | +
---|---|
bar | +baz | +
+diff --git a/tests/fixtures/test_gfm_004.md b/tests/fixtures/test_gfm_004.md new file mode 100644 index 0000000..5862dd6 --- /dev/null +++ b/tests/fixtures/test_gfm_004.md @@ -0,0 +1,4 @@ +| abc | def | +| --- | --- | +| bar | baz | +> bar diff --git a/tests/fixtures/test_gfm_005.html b/tests/fixtures/test_gfm_005.html new file mode 100644 index 0000000..9428d7d --- /dev/null +++ b/tests/fixtures/test_gfm_005.html @@ -0,0 +1,17 @@ +bar
+
abc | +def | +
---|---|
bar | +baz | +
bar | ++ |
bar
diff --git a/tests/fixtures/test_gfm_005.md b/tests/fixtures/test_gfm_005.md new file mode 100644 index 0000000..3a131f1 --- /dev/null +++ b/tests/fixtures/test_gfm_005.md @@ -0,0 +1,6 @@ +| abc | def | +| --- | --- | +| bar | baz | +bar + +bar diff --git a/tests/fixtures/test_gfm_006.html b/tests/fixtures/test_gfm_006.html new file mode 100644 index 0000000..e767cc3 --- /dev/null +++ b/tests/fixtures/test_gfm_006.html @@ -0,0 +1,3 @@ +| abc | def | +| --- | +| bar |
diff --git a/tests/fixtures/test_gfm_006.md b/tests/fixtures/test_gfm_006.md new file mode 100644 index 0000000..66abc49 --- /dev/null +++ b/tests/fixtures/test_gfm_006.md @@ -0,0 +1,3 @@ +| abc | def | +| --- | +| bar | diff --git a/tests/fixtures/test_gfm_007.html b/tests/fixtures/test_gfm_007.html new file mode 100644 index 0000000..60c90d4 --- /dev/null +++ b/tests/fixtures/test_gfm_007.html @@ -0,0 +1,16 @@ +abc | +def | +
---|---|
bar | ++ |
bar | +baz | +
abc | +def | +
---|
Hi Hello, world!
This text is curious.
This ~~has a
+new paragraph~~.
diff --git a/tests/fixtures/test_gfm_011.md b/tests/fixtures/test_gfm_011.md new file mode 100644 index 0000000..001c5f0 --- /dev/null +++ b/tests/fixtures/test_gfm_011.md @@ -0,0 +1,3 @@ +This ~~has a + +new paragraph~~. diff --git a/tests/fixtures/test_gfm_012.html b/tests/fixtures/test_gfm_012.html new file mode 100644 index 0000000..61a6ddc --- /dev/null +++ b/tests/fixtures/test_gfm_012.html @@ -0,0 +1 @@ + diff --git a/tests/fixtures/test_gfm_012.md b/tests/fixtures/test_gfm_012.md new file mode 100644 index 0000000..9456ada --- /dev/null +++ b/tests/fixtures/test_gfm_012.md @@ -0,0 +1 @@ +www.commonmark.org diff --git a/tests/fixtures/test_gfm_013.html b/tests/fixtures/test_gfm_013.html new file mode 100644 index 0000000..04753e9 --- /dev/null +++ b/tests/fixtures/test_gfm_013.html @@ -0,0 +1 @@ +Visit www.commonmark.org/help for more information.
diff --git a/tests/fixtures/test_gfm_013.md b/tests/fixtures/test_gfm_013.md new file mode 100644 index 0000000..aaf18ce --- /dev/null +++ b/tests/fixtures/test_gfm_013.md @@ -0,0 +1 @@ +Visit www.commonmark.org/help for more information. diff --git a/tests/fixtures/test_gfm_014.html b/tests/fixtures/test_gfm_014.html new file mode 100644 index 0000000..6bac270 --- /dev/null +++ b/tests/fixtures/test_gfm_014.html @@ -0,0 +1,2 @@ +Visit www.commonmark.org.
+Visit www.commonmark.org/a.b.
diff --git a/tests/fixtures/test_gfm_014.md b/tests/fixtures/test_gfm_014.md new file mode 100644 index 0000000..ebac363 --- /dev/null +++ b/tests/fixtures/test_gfm_014.md @@ -0,0 +1,3 @@ +Visit www.commonmark.org. + +Visit www.commonmark.org/a.b. diff --git a/tests/fixtures/test_gfm_015.html b/tests/fixtures/test_gfm_015.html new file mode 100644 index 0000000..6534f61 --- /dev/null +++ b/tests/fixtures/test_gfm_015.html @@ -0,0 +1,2 @@ +www.google.com/search?q=Markup+(business)
+(www.google.com/search?q=Markup+(business))
diff --git a/tests/fixtures/test_gfm_015.md b/tests/fixtures/test_gfm_015.md new file mode 100644 index 0000000..7a4cad1 --- /dev/null +++ b/tests/fixtures/test_gfm_015.md @@ -0,0 +1,3 @@ +www.google.com/search?q=Markup+(business) + +(www.google.com/search?q=Markup+(business)) diff --git a/tests/fixtures/test_gfm_016.html b/tests/fixtures/test_gfm_016.html new file mode 100644 index 0000000..d76c1b1 --- /dev/null +++ b/tests/fixtures/test_gfm_016.html @@ -0,0 +1 @@ +www.google.com/search?q=(business))+ok
diff --git a/tests/fixtures/test_gfm_016.md b/tests/fixtures/test_gfm_016.md new file mode 100644 index 0000000..d5509ce --- /dev/null +++ b/tests/fixtures/test_gfm_016.md @@ -0,0 +1 @@ +www.google.com/search?q=(business))+ok diff --git a/tests/fixtures/test_gfm_017.html b/tests/fixtures/test_gfm_017.html new file mode 100644 index 0000000..9e00a95 --- /dev/null +++ b/tests/fixtures/test_gfm_017.html @@ -0,0 +1,2 @@ +www.google.com/search?q=commonmark&hl=en
+www.google.com/search?q=commonmark&hl;
diff --git a/tests/fixtures/test_gfm_017.md b/tests/fixtures/test_gfm_017.md new file mode 100644 index 0000000..ff996c0 --- /dev/null +++ b/tests/fixtures/test_gfm_017.md @@ -0,0 +1,3 @@ +www.google.com/search?q=commonmark&hl=en + +www.google.com/search?q=commonmark&hl; diff --git a/tests/fixtures/test_gfm_018.html b/tests/fixtures/test_gfm_018.html new file mode 100644 index 0000000..a12ebb9 --- /dev/null +++ b/tests/fixtures/test_gfm_018.html @@ -0,0 +1 @@ + diff --git a/tests/fixtures/test_gfm_018.md b/tests/fixtures/test_gfm_018.md new file mode 100644 index 0000000..2c63794 --- /dev/null +++ b/tests/fixtures/test_gfm_018.md @@ -0,0 +1 @@ +www.commonmark.org/he(Visit https://encrypted.google.com/search?q=Markup+(business))
+Anonymous FTP is available at ftp://foo.bar.baz.
diff --git a/tests/fixtures/test_gfm_019.md b/tests/fixtures/test_gfm_019.md new file mode 100644 index 0000000..b6f1242 --- /dev/null +++ b/tests/fixtures/test_gfm_019.md @@ -0,0 +1,5 @@ +http://commonmark.org + +(Visit https://encrypted.google.com/search?q=Markup+(business)) + +Anonymous FTP is available at ftp://foo.bar.baz. diff --git a/tests/fixtures/test_gfm_020.html b/tests/fixtures/test_gfm_020.html new file mode 100644 index 0000000..5904880 --- /dev/null +++ b/tests/fixtures/test_gfm_020.html @@ -0,0 +1 @@ + diff --git a/tests/fixtures/test_gfm_020.md b/tests/fixtures/test_gfm_020.md new file mode 100644 index 0000000..df200e5 --- /dev/null +++ b/tests/fixtures/test_gfm_020.md @@ -0,0 +1 @@ +foo@bar.baz diff --git a/tests/fixtures/test_gfm_021.html b/tests/fixtures/test_gfm_021.html new file mode 100644 index 0000000..85ecf64 --- /dev/null +++ b/tests/fixtures/test_gfm_021.html @@ -0,0 +1 @@ +hello@mail+xyz.example isn't valid, but hello+xyz@mail.example is.
diff --git a/tests/fixtures/test_gfm_021.md b/tests/fixtures/test_gfm_021.md new file mode 100644 index 0000000..50923a1 --- /dev/null +++ b/tests/fixtures/test_gfm_021.md @@ -0,0 +1 @@ +hello@mail+xyz.example isn't valid, but hello+xyz@mail.example is. diff --git a/tests/fixtures/test_gfm_022.html b/tests/fixtures/test_gfm_022.html new file mode 100644 index 0000000..470265d --- /dev/null +++ b/tests/fixtures/test_gfm_022.html @@ -0,0 +1,4 @@ + + +a.b-c_d@a.b-
+a.b-c_d@a.b_
diff --git a/tests/fixtures/test_gfm_022.md b/tests/fixtures/test_gfm_022.md new file mode 100644 index 0000000..b3bbdd0 --- /dev/null +++ b/tests/fixtures/test_gfm_022.md @@ -0,0 +1,7 @@ +a.b-c_d@a.b + +a.b-c_d@a.b. + +a.b-c_d@a.b- + +a.b-c_d@a.b_ diff --git a/tests/fixtures/test_gfm_023.html b/tests/fixtures/test_gfm_023.html new file mode 100644 index 0000000..21f976a --- /dev/null +++ b/tests/fixtures/test_gfm_023.html @@ -0,0 +1,5 @@ +<title> <style>
++ <xmp> is disallowed. <XMP> is also disallowed. ++ \ No newline at end of file diff --git a/tests/fixtures/test_gfm_023.md b/tests/fixtures/test_gfm_023.md new file mode 100644 index 0000000..7d53b14 --- /dev/null +++ b/tests/fixtures/test_gfm_023.md @@ -0,0 +1,5 @@ +