Changed string conversion.
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
from os import path
|
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_NO_INTRA_EMPHASIS, EXT_TABLES, EXT_FENCED_CODE, EXT_AUTOLINK, \
|
||||||
EXT_STRIKETHROUGH, EXT_LAX_HTML_BLOCKS, EXT_SPACE_HEADERS, \
|
EXT_STRIKETHROUGH, EXT_LAX_HTML_BLOCKS, EXT_SPACE_HEADERS, \
|
||||||
EXT_SUPERSCRIPT, \
|
EXT_SUPERSCRIPT, \
|
||||||
@@ -70,12 +70,18 @@ if __name__ == '__main__':
|
|||||||
# then it must be a file, right?
|
# then it must be a file, right?
|
||||||
files.append(arg)
|
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:
|
for fn in files:
|
||||||
fn = path.abspath(fn)
|
fn = path.abspath(fn)
|
||||||
if not path.exists(fn):
|
if not path.exists(fn):
|
||||||
print('Does not exists: %s' % fn)
|
print('Does not exist: %s' % fn)
|
||||||
|
else:
|
||||||
with open(fn, 'r') as fd:
|
with open(fn, 'r') as fd:
|
||||||
source = fd.read()
|
source = fd.read()
|
||||||
|
print(to_html(source))
|
||||||
print(to_html(source, extensions, flags))
|
|
||||||
|
584
src/misaka.c
584
src/misaka.c
File diff suppressed because it is too large
Load Diff
@@ -40,12 +40,6 @@ TABLE_ALIGNMASK = 3 # MKD_TABLE_ALIGNMASK
|
|||||||
TABLE_HEADER = 4 # MKD_TABLE_HEADER
|
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):
|
def html(object text, unsigned int extensions=0, unsigned int render_flags=0):
|
||||||
"""Convert markdown text to (X)HTML.
|
"""Convert markdown text to (X)HTML.
|
||||||
|
|
||||||
@@ -102,11 +96,12 @@ cdef class SmartyPants:
|
|||||||
:param text: A byte or unicode string.
|
:param text: A byte or unicode string.
|
||||||
"""
|
"""
|
||||||
# Convert string
|
# Convert string
|
||||||
cdef char *c_string
|
cdef bytes py_string
|
||||||
if isinstance(text, unicode):
|
if hasattr(text, 'encode'):
|
||||||
c_string = _unicode_to_bytes(text)
|
py_string = text.encode('UTF-8', 'strict')
|
||||||
else:
|
else:
|
||||||
c_string = text
|
py_string = text
|
||||||
|
cdef char *c_string = py_string
|
||||||
|
|
||||||
cdef sundown.buf *ob = sundown.bufnew(128)
|
cdef sundown.buf *ob = sundown.bufnew(128)
|
||||||
sundown.sdhtml_smartypants(ob,
|
sundown.sdhtml_smartypants(ob,
|
||||||
@@ -218,11 +213,12 @@ cdef class Markdown:
|
|||||||
text = self.renderer.preprocess(text)
|
text = self.renderer.preprocess(text)
|
||||||
|
|
||||||
# Convert string
|
# Convert string
|
||||||
cdef char *c_string
|
cdef bytes py_string
|
||||||
if isinstance(text, unicode):
|
if hasattr(text, 'encode'):
|
||||||
c_string = _unicode_to_bytes(text)
|
py_string = text.encode('UTF-8', 'strict')
|
||||||
else:
|
else:
|
||||||
c_string = text
|
py_string = text
|
||||||
|
cdef char *c_string = py_string
|
||||||
|
|
||||||
# Buffers
|
# Buffers
|
||||||
cdef sundown.buf *ib = sundown.bufnew(128)
|
cdef sundown.buf *ib = sundown.bufnew(128)
|
||||||
|
Reference in New Issue
Block a user