61924

Misaka 1.0.0 Beta 1

— Frank — Share

It’s been a while. Like a few months. And I’ve been working on duplicating Redcarpet’s functionality. I think everything should work now, but I still need to test everything properly and that’s why I’m releasing a beta. And the API documentation is also lacking, but the the code itself is understandable enough.

My understanding of C is still limited, but thanks to Redcarpet’s source code I figured out how to implement everything. Not everything is in C. The largest part is actually done in Cython. Which is a great tool. I’ve also included the C code that’s generated by Cython, so you don’t have to install Cython to compile Misaka. Only when you want to regenerate the C code (in that case you use setup_cython.py).

Besides the big API change, Misaka now also accepts Unicode strings, but the side effect is that it’s faster in Python 3. And Python 2 is a lot slower in the benchmark, but you won’t really notice it (if you’re not parsing a large document 10,000 times).

Here’s a small example (the old API is also available).

from misaka import Markdown, HtmlRenderer, SmartyPants

class BleepRenderer(HtmlRenderer, SmartyPants):
    pass

md = Markdown(BleepRenderer())
print(md.render('Some "stuff" here'))
# <p>Some &ldquo;stuff&rdquo; here</p>

The classes are located in misaka.pyx and all the callbacks you can implement in your own renderer are listed in wrapper.c. That’s quite unfriendly documentation at the moment, but I’m planning to change that.

For now just fetch the code from the Github repository. If something is not working, please report it.

Have fun.

Tags: