TextPress and other lost stuff…

Some time ago I wrote a blog engine in Python to replace this wordpress installation. As you can see that never really happened although the blog software is already in a usable state (at least the basic administration and plugin interface works). One of the reasons is that i would have to port over the theme which is one of those stupid tasks i just hate, another one is that i haven’t had time to improve it any further. Another piece of software I recently discovered again is a python powered wiki called ordo which I wrote one year ago i guess. It’s a shame that those applications never where released or properly licensed. ordo lingers around in my svn repository but textpress does not.

TextPress won’t for a few reasons. One is the name, it’s obviously taken from wordpress and want to rename it before I release it, the other reason is that i don’t have the time to maintain the code right now. There are already many other projects and I don’t feel like I want to maintain too much code at the same time.

But because TextPress has some really unique features I at least want to show what it does :)

screenshot of the textpress blog

The screenshot above shows the default theme, the admin panel looks like this and this. It has a pretty interesting plugin interface. The event system was inspired by dokuwiki, the way the syntax based plugins work is IMHO unique :)

Basically what it does is lexing the post sgml markup into a DOM like structure which you can query and transform. Here for example the complete sourcecode of the pygments plugin:

from textpress.api import *
from textpress.htmlprocessor import DataNode
try:
    from pygments import highlight
    from pygments.lexers import get_lexer_by_name
    from pygments.formatters import HtmlFormatter
    have_pygments = True
except ImportError:
    have_pygments = False

class PygmentsHighlighter(object):

    def __init__(self, style):
        self.formatter = HtmlFormatter(style=style)

    def process_doc_tree(self, event):
        for node in event.data['doctree'].query('pre[@tp:lang]'):
            lexer = get_lexer_by_name(node.attributes.pop('tp:lang'))
            output = highlight(node.text, lexer, self.formatter)
            node.parent.children.replace(node, DataNode(output))

    def get_style(self, req):
        return Response(self.formatter.get_style_defs(), mimetype='text/css')

    def inject_style(self, event):
        add_link('stylesheet', url_for('pygments_support/style'), 'text/css')

def setup(app, plugin):
    if not have_pygments:
        return
    app.add_config_var('pygments_support/style', unicode, u'default')
    app.add_url_rule('/_shared/pygments_support/style.css',
                     endpoint='pygments_support/style')

    c = PygmentsHighlighter(app.cfg['pygments_support/style'])
    app.connect_event('process-doc-tree', c.process_doc_tree)
    app.connect_event('after-request-setup', c.inject_style)
    app.add_view('pygments_support/style', c.get_style)

You can see the event and doc tree system in action in the snippet above. The way the DOM is queried is inspired by jQuery ;-)

7 Responses to “TextPress and other lost stuff…”

  1. Hi. I’m definitely interested in this piece of software - I’m writing my own blog software (really it is almost written - with django - but it is very simple and I don’t have inspiration to end it), but your are a lot much more interesting than my. :)

    So maybe you’ll release it? I’m interested into developing (and maintaining too) cool blog system and if you will accept my help, I’ll be glad to do that. :)

    P.S. TextPress is definitely not very good name. :) But my thought cannot move forward from just ‘byteflow’ or ‘wordflow’.

    Comment by Alexander Solovyov — Saturday, August 4th, 2007 @ 11:20 pm
  2. If there is enough interest in the project I guess I could probably speed up the open sourcing process. But I don’t want to lose control over TextPress too much, especially because much of the internal architecture — which once again is pretty complex — is undocumented and can be abused or misused easily.

    Regards,
    Armin

    Comment by Armin Ronacher — Sunday, August 5th, 2007 @ 3:45 pm
  3. Ah, I understand. :) So yes, I’m very interested by your description, so I’ll wait for this project. :)

    Comment by Alexander Solovyov — Sunday, August 5th, 2007 @ 6:52 pm
  4. I wonder whether TextPress 0.1 will be released in time ;)

    Comment by john — Friday, December 21st, 2007 @ 3:55 pm
  5. Probably not ;-) But I will work on it

    Comment by Armin Ronacher — Friday, December 21st, 2007 @ 4:55 pm
  6. So no christmas for me then this year :(

    Seriously: I wish you all the best for christmas and new year and such.

    And ohh: Will check-back soon *G

    Comment by john — Friday, December 21st, 2007 @ 5:09 pm
  7. Sorry for that :-) Well, but at least Werkzeug 0.1 was released. That’s a good start and maybe we can get a TextPress release this year :-)

    Comment by Armin Ronacher — Friday, December 21st, 2007 @ 7:23 pm

Leave a Reply

cogitations driven by wordpress