Skip to content

Instantly share code, notes, and snippets.

@erikng
Forked from pudquick/xcode_markdown.py
Created May 30, 2018 16:25
Show Gist options
  • Save erikng/fd0cf401aa56b03bc2b5b421e7720443 to your computer and use it in GitHub Desktop.
Save erikng/fd0cf401aa56b03bc2b5b421e7720443 to your computer and use it in GitHub Desktop.
Abuse Xcode's embedded CommonMark framework to generate HTML from markdown
# hax hax hax hax hax
import ctypes, os, sys
newstderr = os.dup(2) # This is to mute dyld LC_RPATH warnings
os.dup2(os.open('/dev/null', os.O_WRONLY), 2) # because we're loading Xcode frameworks from python
CM = ctypes.CDLL('/Applications/Xcode.app/Contents/SharedFrameworks/DVTMarkup.framework/Versions/A/Frameworks/CommonMark.framework/CommonMark')
sys.stderr = os.fdopen(newstderr, 'w') # This restores stderr
cmark_markdown_to_html = CM.cmark_markdown_to_html
cmark_markdown_to_html.restype = ctypes.c_char_p
def markdown_to_html(markdown):
mc = ctypes.create_string_buffer(markdown)
return cmark_markdown_to_html(mc, len(mc)-1, 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment