Skip to content

Commit 63778f5

Browse files
committed
Merge branch 'release/2.3.5'
2 parents 3324a12 + 494e6b6 commit 63778f5

File tree

15 files changed

+169
-21
lines changed

15 files changed

+169
-21
lines changed

CHANGELOG.textile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
h1. Textile Changelog
22

3+
h2. Version 2.3.5
4+
* Bugfix: Correctly handle unicode text in url query-strings. ("#36":https://github.com/textile/python-textile/issues/36)
5+
6+
h2. Version 2.3.4
7+
* Bugfix: fix an issue with extended block code
8+
* Remove misplaced shebang on non-callable files.
9+
* Packaging: Add test-command to setup.py directly.
10+
* Packaging: Included the tests/ directory for source-tarballs, useful for packaging checks. ("#33":https://github.com/textile/python-textile/issues/33)
11+
* Add a cli tool `pytextile` which takes textile input and prints html output. See `pytextile -h` for details.
12+
313
h2. Version 2.3.3
414
* Bugfix: Unicode in URL titles no longer break everything ("#30":https://github.com/textile/python-textile/issues/30)
515
* Display DeprecationWarning when using textile on Python 2.6.

MANIFEST.in

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
exclude .gitignore
2+
exclude TODO.textile
3+
exclude .travis.yml
4+
include CHANGELOG.textile
5+
include CONTRIBUTORS.txt
6+
include .coveragerc
7+
include LICENSE.txt
8+
include MANIFEST.in
9+
include pytest.ini
10+
include README.textile
11+
include requirements.txt

README.textile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ Optional dependencies include:
1414

1515
h2. Usage
1616

17-
<pre>
18-
<code>
19-
>>> import textile
17+
bc.. import textile
2018
>>> s = """
2119
... _This_ is a *test.*
2220
...
@@ -38,8 +36,6 @@ h2. Usage
3836

3937
<p>Link to <a href="http://slashdot.org/">Slashdot</a></p>
4038
>>>
41-
</code>
42-
</pre>
4339

4440
h3. Notes:
4541

setup.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from setuptools import setup, find_packages
22
import os
33
import sys
4+
import pytest
45

56
def get_version():
67
basedir = os.path.dirname(__file__)
@@ -13,6 +14,8 @@ def get_version():
1314
setup(
1415
name='textile',
1516
version=get_version(),
17+
author='Dennis Burke',
18+
author_email='ikirudennis@gmail.com',
1619
description='Textile processing for python.',
1720
url='http://github.com/textile/python-textile',
1821
packages=find_packages(),
@@ -40,8 +43,10 @@ def get_version():
4043
':python_version=="2.6"': ['ordereddict>=1.1'],
4144
'develop': ['regex', 'pytest', 'pytest-cov'],
4245
},
46+
entry_points={'console_scripts': ['pytextile=textile.__main__:main']},
4347
setup_requires=['pytest-runner'],
4448
tests_require=['pytest', 'pytest-cov'],
49+
cmdclass = {'test': pytest},
4550
include_package_data=True,
4651
zip_safe=False,
4752
)

tests/fixtures/README.txt

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<p><a href="https://travis-ci.org/textile/python-textile"><img alt="" src="https://travis-ci.org/textile/python-textile.svg" /></a> <a href="https://coveralls.io/github/textile/python-textile?branch=master"><img alt="" src="https://coveralls.io/repos/github/textile/python-textile/badge.svg" /></a> <a href="https://codecov.io/github/textile/python-textile"><img alt="" src="https://codecov.io/github/textile/python-textile/coverage.svg" /></a></p>
2+
3+
<h1>python-textile</h1>
4+
5+
<p>python-textile is a Python port of <a href="http://txstyle.org/">Textile</a>, Dean Allen&#8217;s humane web text generator.</p>
6+
7+
<h2>Installation</h2>
8+
9+
<p><code>pip install textile</code></p>
10+
11+
<p>Optional dependencies include:
12+
<ul>
13+
<li><a href="http://python-pillow.github.io/"><span class="caps">PIL</span>/Pillow</a> (for checking images size)</li>
14+
<li><a href="https://pypi.python.org/pypi/regex">regex</a> (for faster unicode-aware string matching).</li>
15+
</ul></p>
16+
17+
<h2>Usage</h2>
18+
19+
<pre><code>import textile
20+
&gt;&gt;&gt; s = &quot;&quot;&quot;
21+
... _This_ is a *test.*
22+
...
23+
... * One
24+
... * Two
25+
... * Three
26+
...
27+
... Link to &quot;Slashdot&quot;:http://slashdot.org/
28+
... &quot;&quot;&quot;
29+
&gt;&gt;&gt; html = textile.textile(s)
30+
&gt;&gt;&gt; print html
31+
&lt;p&gt;&lt;em&gt;This&lt;/em&gt; is a &lt;strong&gt;test.&lt;/strong&gt;&lt;/p&gt;
32+
33+
&lt;ul&gt;
34+
&lt;li&gt;One&lt;/li&gt;
35+
&lt;li&gt;Two&lt;/li&gt;
36+
&lt;li&gt;Three&lt;/li&gt;
37+
&lt;/ul&gt;
38+
39+
&lt;p&gt;Link to &lt;a href=&quot;http://slashdot.org/&quot;&gt;Slashdot&lt;/a&gt;&lt;/p&gt;
40+
&gt;&gt;&gt;</code></pre>
41+
42+
<h3>Notes:</h3>
43+
44+
<ul>
45+
<li>Active development supports Python 2.6 or later (including Python 3.2+).</li>
46+
</ul>

tests/test_block.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import unicode_literals
22

3-
from textile import Textile
3+
import textile
44
from textile.objects import Block
55

66
try:
@@ -9,7 +9,7 @@
99
from ordereddict import OrderedDict
1010

1111
def test_block():
12-
t = Textile()
12+
t = textile.Textile()
1313
result = t.block('h1. foobar baby')
1414
expect = '\t<h1>foobar baby</h1>'
1515
assert result == expect
@@ -41,9 +41,24 @@ def test_block():
4141
assert result == expect
4242

4343
def test_block_tags_false():
44-
t = Textile(block_tags=False)
44+
t = textile.Textile(block_tags=False)
4545
assert t.block_tags is False
4646

4747
result = t.parse('test')
4848
expect = 'test'
4949
assert result == expect
50+
51+
def test_blockcode_extended():
52+
input = 'bc.. text\nmoretext\n\nevenmoretext\n\nmoremoretext\n\np. test'
53+
expect = '<pre><code>text\nmoretext\n\nevenmoretext\n\nmoremoretext</code></pre>\n\n\t<p>test</p>'
54+
t = textile.Textile()
55+
result = t.parse(input)
56+
assert result == expect
57+
58+
def test_blockcode_in_README():
59+
with open('README.textile') as f:
60+
readme = ''.join(f.readlines())
61+
result = textile.textile(readme)
62+
with open('tests/fixtures/README.txt') as f:
63+
expect = ''.join(f.readlines())
64+
assert result == expect

tests/test_cli.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import six
2+
import subprocess
3+
4+
def test_console_script():
5+
command = ['python', '-m', 'textile', 'README.textile']
6+
try:
7+
result = subprocess.check_output(command)
8+
except AttributeError:
9+
command[2] = 'textile.__main__'
10+
result = subprocess.Popen(command,
11+
stdout=subprocess.PIPE).communicate()[0]
12+
with open('tests/fixtures/README.txt') as f:
13+
expect = ''.join(f.readlines())
14+
if type(result) == bytes:
15+
result = result.decode('utf-8')
16+
assert result == expect

tests/test_github_issues.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,9 @@ def test_github_issue_30():
8585
result = textile.textile(text)
8686
expect = '\t<p><a href="http://lala.com" title="Tëxtíle">Tëxtíle</a></p>'
8787
assert result == expect
88+
89+
def test_github_issue_36():
90+
text = '"Chögyam Trungpa":https://www.google.com/search?q=Chögyam+Trungpa'
91+
result = textile.textile(text)
92+
expect = '\t<p><a href="https://www.google.com/search?q=Chögyam+Trungpa">Chögyam Trungpa</a></p>'
93+
assert result == expect

tests/test_values.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@
150150

151151
('<script>alert("hello");</script>', '\t<p><script>alert(&#8220;hello&#8221;);</script></p>'),
152152

153-
('pre.. Hello\n\nHello Again\n\np. normal text', '<pre>Hello\n\nHello Again\n</pre>\n\n\t<p>normal text</p>'),
153+
('pre.. Hello\n\nHello Again\n\np. normal text', '<pre>Hello\n\nHello Again</pre>\n\n\t<p>normal text</p>'),
154154

155155
('<pre>this is in a pre tag</pre>', '<pre>this is in a pre tag</pre>'),
156156

@@ -180,7 +180,7 @@
180180

181181
('h2. A header\n\n\n\n\n\nsome text', '\t<h2>A header</h2>\n\n\t<p>some text</p>'),
182182

183-
('pre.. foo bar baz\nquux', '<pre>foo bar baz\nquux\n</pre>'),
183+
('pre.. foo bar baz\nquux', '<pre>foo bar baz\nquux</pre>'),
184184

185185
('line of text\n\n leading spaces',
186186
'\t<p>line of text</p>\n\n leading spaces'),
@@ -286,11 +286,11 @@
286286
# issue 2 escaping
287287
('"foo ==(bar)==":#foobar', '\t<p><a href="#foobar">foo (bar)</a></p>'),
288288
# issue 14 newlines in extended pre blocks
289-
("pre.. Hello\n\nAgain\n\np. normal text", '<pre>Hello\n\nAgain\n</pre>\n\n\t<p>normal text</p>'),
289+
("pre.. Hello\n\nAgain\n\np. normal text", '<pre>Hello\n\nAgain</pre>\n\n\t<p>normal text</p>'),
290290
# url with parentheses
291291
('"python":http://en.wikipedia.org/wiki/Python_(programming_language)', '\t<p><a href="http://en.wikipedia.org/wiki/Python_%28programming_language%29">python</a></p>'),
292292
# table with hyphen styles
293-
('table(linkblog-thumbnail).\n|(linkblog-thumbnail-cell). apple|bear|', '\t<table class="linkblog-thumbnail">\n\t\t<tr>\n\t\t\t<td class="linkblog-thumbnail-cell" style="vertical-align:middle;">apple</td>\n\t\t\t<td>bear</td>\n\t\t</tr>\n\t</table>'),
293+
('table(linkblog-thumbnail).\n|(linkblog-thumbnail-cell). apple|bear|', '\t<table class="linkblog-thumbnail">\n\t\t<tr>\n\t\t\t<td class="linkblog-thumbnail-cell">apple</td>\n\t\t\t<td>bear</td>\n\t\t</tr>\n\t</table>'),
294294
# issue 32 empty table cells
295295
("|thing|||otherthing|", "\t<table>\n\t\t<tr>\n\t\t\t<td>thing</td>\n\t\t\t<td></td>\n\t\t\t<td></td>\n\t\t\t<td>otherthing</td>\n\t\t</tr>\n\t</table>"),
296296
# issue 36 link reference names http and https

textile/__main__.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import argparse
2+
import sys
3+
import textile
4+
5+
6+
def main():
7+
"""A CLI tool in the style of python's json.tool. In fact, this is mostly
8+
copied directly from that module. This allows us to create a stand-alone
9+
tool as well as invoking it via `python -m textile`."""
10+
prog = 'textile'
11+
description = ('A simple command line interface for textile module '
12+
'to convert textile input to HTML output. This script '
13+
'accepts input as a file or stdin and can write out to '
14+
'a file or stdout.')
15+
parser = argparse.ArgumentParser(prog=prog, description=description)
16+
parser.add_argument('infile', nargs='?', type=argparse.FileType(),
17+
help='a textile file to be converted')
18+
parser.add_argument('outfile', nargs='?', type=argparse.FileType('w'),
19+
help='write the output of infile to outfile')
20+
options = parser.parse_args()
21+
22+
infile = options.infile or sys.stdin
23+
outfile = options.outfile or sys.stdout
24+
with infile:
25+
output = textile.textile(''.join(infile.readlines()))
26+
with outfile:
27+
outfile.write(output)
28+
29+
30+
if __name__ == '__main__': #pragma: no cover
31+
main()

0 commit comments

Comments
 (0)