aboutsummaryrefslogtreecommitdiff
path: root/wrapper3.py
blob: 7a777fa1ed8afeb4d6bdbbef025b45d9356eaeae (plain)
  1. #!/usr/bin/env python3
  2. # Example for using the shared library from python
  3. from ctypes import CDLL, c_char_p, c_long
  4. import sys
  5. import platform
  6. sysname = platform.system()
  7. if sysname == 'Darwin':
  8. cmark = CDLL("build/src/libcmark.dylib")
  9. else:
  10. cmark = CDLL("build/src/libcmark.so")
  11. markdown = cmark.cmark_markdown_to_html
  12. markdown.restype = c_char_p
  13. markdown.argtypes = [c_char_p, c_long]
  14. def md2html(text):
  15. textbytes = text.encode('utf-8')
  16. textlen = len(textbytes)
  17. return markdown(textbytes, textlen).decode('utf-8')
  18. sys.stdout.write(md2html(sys.stdin.read()))