Skip to content

Commit 49995ac

Browse files
author
Kenneth Reitz
committed
wow, it works.
1 parent b877424 commit 49995ac

1 file changed

Lines changed: 30 additions & 11 deletions

File tree

pyandoc/core.py

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import subprocess
22

3-
PANDOC_PATH = '/Users/kreitz/.cabal/bin/pandoc'
3+
PANDOC_PATH = '/Users/kreitz/.cabal/bin//pandoc'
4+
45

56
class Document(object):
6-
"""A generic formatted document"""
7+
"""A formatted document."""
78

89
INPUT_FORMATS = (
910
'native', 'markdown', 'markdown+lhs', 'rst',
@@ -23,28 +24,33 @@ class Document(object):
2324

2425

2526
def __init__(self):
26-
self.content = None
27+
self._content = None
28+
self._format = None
2729
self._register_formats()
2830

2931
@classmethod
3032
def _register_formats(cls):
3133
"""Adds format properties."""
3234
for fmt in cls.OUTPUT_FORMATS:
3335
clean_fmt = fmt.replace('+', '_')
34-
setattr(cls, clean_fmt, property(lambda x, fmt=fmt: cls._output(x, fmt)))
35-
36+
setattr(cls, clean_fmt, property(
37+
(lambda x, fmt=fmt: cls._output(x, fmt)), # fget
38+
(lambda x, y, fmt=fmt: cls._input(x, y, fmt)))) # fset
39+
40+
def _input(self, value, format=None):
41+
# format = format.replace('_', '+')
42+
self._content = value
43+
self._format = format
3644

3745
def _output(self, format):
3846
# print format
3947
p = subprocess.Popen(
40-
[PANDOC_PATH, '--from=html', '--to=%s' % format],
48+
[PANDOC_PATH, '--from=%s' % self._format, '--to=%s' % format],
4149
stdin=subprocess.PIPE,
4250
stdout=subprocess.PIPE
4351
)
4452

45-
return p.communicate(self.content)[0]
46-
#
47-
# return format
53+
return p.communicate(self._content)[0]
4854

4955

5056
test = """
@@ -56,9 +62,22 @@ def _output(self, format):
5662
</ul>
5763
"""
5864

65+
test = """
66+
# dude this is awesome
67+
68+
* test
69+
* testing
70+
* 124
71+
72+
<script>
73+
var hi = 'no'.
74+
</script>
75+
76+
"""
77+
5978

6079
doc = Document()
61-
doc.content = test
62-
print doc.rtf
80+
doc.markdown = test
81+
print doc.rst
6382

6483
# print html2rst(test)

0 commit comments

Comments
 (0)