-
-
Save n0ncetonic/aeb2029f20a265efaf0bd568d3ddcd11 to your computer and use it in GitHub Desktop.
Abuse Xcode's embedded CommonMark framework to generate HTML from markdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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