Sha256: 66ed023888a169c7fbfc2f473757ce75404c61dec17e56e0109935eb3a64703d

Contents?: true

Size: 921 Bytes

Versions: 13

Compression:

Stored size: 921 Bytes

Contents

#!/usr/bin/env python

# Example for using the shared library from python
# Will work with either python 2 or python 3
# Requires cmark library to be installed

from ctypes import CDLL, c_char_p, c_long
import sys
import platform

sysname = platform.system()

if sysname == 'Darwin':
    libname = "libcmark.dylib"
elif sysname == 'Windows':
    libname = "cmark.dll"
else:
    libname = "libcmark.so"
cmark = CDLL(libname)

markdown = cmark.cmark_markdown_to_html
markdown.restype = c_char_p
markdown.argtypes = [c_char_p, c_long, c_long]

opts = 8 # CMARK_OPT_PRETTY

def md2html(text):
    if sys.version_info >= (3,0):
        textbytes = text.encode('utf-8')
        textlen = len(textbytes)
        return markdown(textbytes, textlen, opts).decode('utf-8')
    else:
        textbytes = text
        textlen = len(text)
        return markdown(textbytes, textlen, opts)

sys.stdout.write(md2html(sys.stdin.read()))

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
commonmarker-0.6.0 ext/commonmarker/cmark/wrappers/wrapper.py
commonmarker-0.5.1 ext/commonmarker/cmark/wrappers/wrapper.py
commonmarker-0.5.0 ext/commonmarker/cmark/wrappers/wrapper.py
commonmarker-0.4.1 ext/commonmarker/cmark/wrappers/wrapper.py
commonmarker-0.4.0 ext/commonmarker/cmark/wrappers/wrapper.py
commonmarker-0.3.0 ext/commonmarker/cmark/wrappers/wrapper.py
commonmarker-0.2.1 ext/commonmarker/cmark/wrappers/wrapper.py
commonmarker-0.2.0 ext/commonmarker/cmark/wrappers/wrapper.py
commonmarker-0.1.3 ext/commonmarker/cmark/wrappers/wrapper.py
commonmarker-0.1.2 ext/commonmarker/cmark/wrappers/wrapper.py
commonmarker-0.1.1 ext/commonmarker/cmark/wrappers/wrapper.py
commonmarker-0.1.0 ext/commonmarker/cmark/wrappers/wrapper.py
commonmarker-0.0.1 ext/commonmarker/cmark/wrappers/wrapper.py