diff --git a/discount/libmarkdown.py b/discount/libmarkdown.py index 19df766..432c030 100644 --- a/discount/libmarkdown.py +++ b/discount/libmarkdown.py @@ -26,19 +26,29 @@ import os -MKD_NOLINKS = 0x0001 -MKD_NOIMAGE = 0x0002 -MKD_NOPANTS = 0x0004 -MKD_NOHTML = 0x0008 -MKD_STRICT = 0x0010 -MKD_NO_EXT = 0x0040 -MKD_NOHEADER = 0x0100 -MKD_TABSTOP = 0x0200 -MKD_NOTABLES = 0x0400 -MKD_TOC = 0x1000 -MKD_1_COMPAT = 0x2000 -MKD_AUTOLINK = 0x4000 -MKD_SAFELINK = 0x8000 +MKD_NOLINKS = 0x00000001 +MKD_NOIMAGE = 0x00000002 +MKD_NOPANTS = 0x00000004 +MKD_NOHTML = 0x00000008 +MKD_STRICT = 0x00000010 +MKD_TAGTEXT = 0x00000020 +MKD_NO_EXT = 0x00000040 +MKD_CDATA = 0x00000080 +MKD_NOSUPERSCRIPT = 0x00000100 +MKD_NORELAXED = 0x00000200 +MKD_NOTABLES = 0x00000400 +MKD_NOSTRIKETHROUGH = 0x00000800 +MKD_TOC = 0x00001000 +MKD_1_COMPAT = 0x00002000 +MKD_AUTOLINK = 0x00004000 +MKD_SAFELINK = 0x00008000 +MKD_NOHEADER = 0x00010000 +MKD_TABSTOP = 0x00020000 +MKD_NODIVQUOTE = 0x00040000 +MKD_NOALPHALIST = 0x00080000 +MKD_NODLIST = 0x00100000 +MKD_EXTRA_FOOTNOTE = 0x00200000 +MKD_NOSTYLE = 0x00400000 _so = ctypes.CDLL( @@ -136,6 +146,16 @@ class Footnote_STRING(ctypes.Structure): ('alloc', ctypes.c_int), ] +# An empty class with _fields_ assigned later is done because of the +# circular reference in the C struct. +class Escaped(ctypes.Structure): + pass + +Escaped._fields_ = [ + ('text', ctypes.c_char_p), + ('up', ctypes.POINTER(Escaped)), + ] + class MMIOT(ctypes.Structure): _fields_ = [ @@ -143,6 +163,9 @@ class MMIOT(ctypes.Structure): ('in_', Cstring), ('Q', Qblock), ('isp', ctypes.c_int), + ('reference', ctypes.c_int), + ('esc', ctypes.POINTER(Escaped)), + ('ref_prefix', ctypes.c_char_p), ('footnotes', ctypes.POINTER(Footnote_STRING)), ('flags', ctypes.c_int), ('base', ctypes.c_char_p), @@ -152,12 +175,15 @@ class MMIOT(ctypes.Structure): class Document(ctypes.Structure): _fields_ = [ ('magic', ctypes.c_int), - ('headers', ctypes.POINTER(Line)), + ('title', ctypes.POINTER(Line)), + ('author', ctypes.POINTER(Line)), + ('date', ctypes.POINTER(Line)), ('content', Line_ANCHOR), ('code', ctypes.POINTER(Paragraph)), ('compiled', ctypes.c_int), ('html', ctypes.c_int), ('tabstop', ctypes.c_int), + ('ref_prefix', ctypes.c_char_p), ('ctx', ctypes.POINTER(MMIOT)), ('cb', ctypes.c_void_p), # TODO: bind related structures ] diff --git a/setup.py b/setup.py index 93311bd..5b4890b 100644 --- a/setup.py +++ b/setup.py @@ -8,11 +8,11 @@ from distutils.core import setup, Extension -DEFAULT_DISCOUNT_VERSION = '1.6.6' +DEFAULT_DISCOUNT_VERSION = 'v2.1.7' DEFAULT_DISCOUNT_DOWNLOAD_URL = ( - 'http://github.com/Orc/discount/tarball/v%s' + 'http://github.com/Orc/discount/tarball/%s' ) % DEFAULT_DISCOUNT_VERSION @@ -20,15 +20,6 @@ # DL tag extension '--enable-dl-tag ' - # Use pandoc-style header blocks - '--enable-pandoc-header ' - - # A^B becomes AB - '--enable-superscript ' - - # underscores aren'\''t special in the middle of words - '--relaxed-emphasis ' - # Set tabstops to N characters (default is 4) '--with-tabstops=4 ' @@ -104,6 +95,28 @@ def build_extension(self, ext): ) os.chdir(current_dir) + if not os.path.exists( + os.path.join(discount_src_path, 'mktags')): + current_dir = os.getcwd() + os.chdir(discount_src_path) + subprocess.call( + ['make', 'blocktags'], + env=os.environ + ) + os.chdir(current_dir) + + # if not os.path.exists( + # os.path.join(discount_src_path, 'blocktags')): + # current_dir = os.getcwd() + # os.chdir(discount_src_path) + # with open(os.path.join(discount_src_path, 'blocktags'), 'w') as f: + # subprocess.call( + # ['mktags'], + # stdout=f, + # env=os.environ + # ) + # os.chdir(current_dir) + ext.sources = [ os.path.join(discount_src_path, s) for s in ext.sources ] @@ -158,7 +171,7 @@ def build_extension(self, ext): 'amalloc.c', 'Csio.c', 'css.c', 'docheader.c', 'dumptree.c', 'generate.c', 'markdown.c', 'mkdio.c', 'resource.c', 'toc.c', 'version.c', 'xml.c', 'xmlpage.c', - 'basename.c', 'emmatch.c', 'tags.c', 'html5.c', + 'basename.c', 'emmatch.c', 'tags.c', 'html5.c', 'setup.c', ], ) ], diff --git a/tests.py b/tests.py index 0ee73b1..e482169 100644 --- a/tests.py +++ b/tests.py @@ -240,7 +240,7 @@ def test_mkd_css(self): self.assertNotEqual(ret, -1) self.assertEqual( sb.value[:ret], - '\n' + '\n' ) def test_mkd_generatecss(self): @@ -274,7 +274,7 @@ def test_mkd_generatecss(self): html = out.read() self.assertEqual( - html, '\n' + html, '\n' ) out.close() @@ -305,11 +305,10 @@ def test_mkd_toc(self): self.assertNotEqual(ret, -1) self.assertEqual( sb.value[:ret], ( - '\n ' - '\n' + '\n' ) ) @@ -345,11 +344,10 @@ def test_mkd_generatetoc(self): self.assertEqual( html, ( - '\n ' - '\n' + '\n' ) ) @@ -393,8 +391,8 @@ def test_mkd_dump(self): self.assertEqual( dump, ( - 'title-----[source]--+--[header,

, 1 line]\n' - ' `--[markup,

, 1 line]\n' + 'title-----[source]--+--[header, 1 line]\n' + ' `--[markup, 1 line]\n' ) ) @@ -700,8 +698,8 @@ def test_MKD_NOPANTS(self): 'a --- b\n' 'a ... b\n' ), - '

“test”\n``test\na — b\n' - 'a —– b\na … b

', + '

“test”\n``test\na – b\n' + 'a — b\na … b

', 0 ) @@ -787,7 +785,7 @@ def test_MKD_NOTABLES(self): 'a | b\n' '-- | -\n' '1 | 2\n', - '

a | b\n— | –\n1 | 2

', + '

a | b\n– | -\n1 | 2

', libmarkdown.MKD_NOTABLES ) @@ -828,8 +826,8 @@ def test_MKD_TOC(self): self._test_flag( '# header-1\n' '## header-2\n', - '

header-1

\n\n' - '

header-2

', + '\n

header-1

\n\n' + '\n

header-2

', libmarkdown.MKD_TOC ) @@ -978,7 +976,7 @@ def test_input_string_get_html_css(self): style = md.get_html_css() - self.assertEqual(style, '\n') + self.assertEqual(style, '\n') def test_input_string_get_html_toc(self): md = Markdown('# header-1\n## header-2\n### header-3') @@ -986,11 +984,10 @@ def test_input_string_get_html_toc(self): self.assertEqual( html, ( - '\n ' - '\n' + '\n' ) ) @@ -1011,7 +1008,7 @@ def test_input_string_write_html_css(self): style = o.read() o.close() - self.assertEqual(style, '\n') + self.assertEqual(style, '\n') def test_input_string_write_html_toc(self): o = tempfile.TemporaryFile('r+w') @@ -1024,11 +1021,10 @@ def test_input_string_write_html_toc(self): self.assertEqual( html, ( - '\n ' - '\n' + '\n' ) ) @@ -1138,7 +1134,7 @@ def test_input_file_get_html_css(self): style = md.get_html_css() - self.assertEqual(style, '\n') + self.assertEqual(style, '\n') def test_input_file_get_html_toc(self): i = tempfile.TemporaryFile('r+w') @@ -1150,11 +1146,10 @@ def test_input_file_get_html_toc(self): self.assertEqual( html, ( - '\n ' - '\n' + '\n' ) ) @@ -1182,7 +1177,7 @@ def test_input_file_write_html_css(self): o.close() i.close() - self.assertEqual(style, '\n') + self.assertEqual(style, '\n') def test_input_file_write_html_toc(self): i = tempfile.TemporaryFile('r+w') @@ -1200,11 +1195,10 @@ def test_input_file_write_html_toc(self): self.assertEqual( html, ( - '\n ' - '\n' + '\n' ) )