summaryrefslogtreecommitdiff
path: root/test/cmark.py
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2014-11-29 18:32:44 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2014-11-29 18:32:44 -0800
commit9fedb89af38b5a43eb0f7944e938dbbdb17a499d (patch)
tree6b69dd19edcd3abc5b0a673bcbb31e592262bdaa /test/cmark.py
parent2570a08178f95dc9340f13924d412169dd57fdbb (diff)
Factored out cmark.py from test programs.
Diffstat (limited to 'test/cmark.py')
-rw-r--r--test/cmark.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/test/cmark.py b/test/cmark.py
new file mode 100644
index 0000000..432a3e0
--- /dev/null
+++ b/test/cmark.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+from ctypes import CDLL, c_char_p, c_long
+from subprocess import *
+import platform
+
+def pipe_through_prog(prog, text):
+ p1 = Popen(prog.split(), stdout=PIPE, stdin=PIPE, stderr=PIPE)
+ [result, err] = p1.communicate(input=text)
+ return [p1.returncode, result, err]
+
+def use_library(lib, text):
+ return [0, lib(text, len(text)), '']
+
+class CMark:
+ def __init__(self, prog=None, library_dir=None):
+ self.prog = prog
+ if prog:
+ self.to_html = lambda x: pipe_through_prog(prog, x)
+ else:
+ sysname = platform.system()
+ libname = "libcmark"
+ if sysname == 'Darwin':
+ libname += ".dylib"
+ elif sysname == 'Windows':
+ libname += ".dll"
+ else:
+ libname += ".so"
+ if library_dir:
+ libpath = library_dir + "/" + libname
+ else:
+ libpath = "build/src/" + libname
+ cmark = CDLL(libpath)
+ markdown = cmark.cmark_markdown_to_html
+ markdown.restype = c_char_p
+ markdown.argtypes = [c_char_p, c_long]
+ self.to_html = lambda x: use_library(markdown, x)