Changed string conversion.

This commit is contained in:
Frank Smit
2012-04-09 11:46:26 +02:00
parent a313cb3fc4
commit 01a95402b3
3 changed files with 310 additions and 318 deletions

View File

@@ -2,7 +2,7 @@
import sys
from os import path
from misaka import html as to_html, \
from misaka import Markdown, HtmlRenderer, SmartyPants, \
EXT_NO_INTRA_EMPHASIS, EXT_TABLES, EXT_FENCED_CODE, EXT_AUTOLINK, \
EXT_STRIKETHROUGH, EXT_LAX_HTML_BLOCKS, EXT_SPACE_HEADERS, \
EXT_SUPERSCRIPT, \
@@ -70,12 +70,18 @@ if __name__ == '__main__':
# then it must be a file, right?
files.append(arg)
if flags & HTML_SMARTYPANTS:
class HtmlRenderer(HtmlRenderer, SmartyPants):
pass
renderer = HtmlRenderer(flags)
to_html = Markdown(renderer, extensions).render
for fn in files:
fn = path.abspath(fn)
if not path.exists(fn):
print('Does not exists: %s' % fn)
with open(fn, 'r') as fd:
source = fd.read()
print(to_html(source, extensions, flags))
print('Does not exist: %s' % fn)
else:
with open(fn, 'r') as fd:
source = fd.read()
print(to_html(source))

File diff suppressed because it is too large Load Diff

View File

@@ -40,12 +40,6 @@ TABLE_ALIGNMASK = 3 # MKD_TABLE_ALIGNMASK
TABLE_HEADER = 4 # MKD_TABLE_HEADER
cdef char* _unicode_to_bytes(unicode text):
cdef bytes py_string = text.encode('UTF-8', 'strict')
cdef char *c_string = py_string
return c_string
def html(object text, unsigned int extensions=0, unsigned int render_flags=0):
"""Convert markdown text to (X)HTML.
@@ -102,11 +96,12 @@ cdef class SmartyPants:
:param text: A byte or unicode string.
"""
# Convert string
cdef char *c_string
if isinstance(text, unicode):
c_string = _unicode_to_bytes(text)
cdef bytes py_string
if hasattr(text, 'encode'):
py_string = text.encode('UTF-8', 'strict')
else:
c_string = text
py_string = text
cdef char *c_string = py_string
cdef sundown.buf *ob = sundown.bufnew(128)
sundown.sdhtml_smartypants(ob,
@@ -218,11 +213,12 @@ cdef class Markdown:
text = self.renderer.preprocess(text)
# Convert string
cdef char *c_string
if isinstance(text, unicode):
c_string = _unicode_to_bytes(text)
cdef bytes py_string
if hasattr(text, 'encode'):
py_string = text.encode('UTF-8', 'strict')
else:
c_string = text
py_string = text
cdef char *c_string = py_string
# Buffers
cdef sundown.buf *ib = sundown.bufnew(128)