scribe : documentation

Text-processor Plugins

This document is for Scribe's SVN release, which can be significantly different than previous releases. Get old docs here: 0.60.

Text-processor plugins exist to allow third party developers to easily extend Scribe and allow different ways to process text being posted to the weblog. Scribe also uses the plugin architecture to install some default text-processing functionality. The pre-packaged plugins is:

  • Markdown

Using Text-processor Plugins

To use a text-processor plugin, you simply need to set TEXTPROCESSOR to the name of the text-processor you want to use in your preferences.py file. Some text-processor (like the built-in Markdown) may have additional preferences. Consult the documentation for the plugins that you plan to use for information about what additional configuration may be done.

Installing plugins

If you obtain a plugin from a third party, you can simply put it into the plugins folder. The next time your code is reloaded, the plugin will be loaded.

Built-in Plugins

Markdown

The Markdown text-processor is a very widely used text-processor for weblogs. The Python implementation of Markdown allows for extensions as well. Scribe allows you to enable any extensions you have installed yourself. Simply set the MARKDOWN_EXTENSIONS to a list of strings naming the extensions you want to enable. By default we have enabled the codehilite extension which comes prepackaged with Scribe.

Markdown is enabled by default in Scribe.

Writing Custom Plugins

Base class

The base class object is scribe.core.plugins.base.TextprocessorPlugin. You should create a plugin object that inherits from this object.

Methods to override

The process_text method is the only method that must be overridden to create a text-processor. The method takes one argument, the text to convert and returns the converted text.

For example, the Markdown plugin looks something like this:

from scribe.core.plugins.base import TextprocessorPlugin
from markdown import markdown
class MarkdownPlugin(TextprocessorPlugin):
  def process_text(self, text):
    return markdown(text)

If you feel you need to, you can override the name method as well. By default this method simply takes the name of the class, strips off the Plugin part, and converts it to all lowercase. This should work fine for most plugin developers, and we encourage you do do this.

Defining custom preferences

You have the option of defining custom preferences for your plugin. Simply add a module called defaults to your module and define the default values for any preferences. When you want to use the preferences do the following:

from scribe.conf import settings
settings.MY_PREFERENCE

This will retrieve the value that the user defined in his/her preferences.py file if it exists, and if not, it will use the default value that you defined in the defaults module.

Using other Python libraries

You can include other python libraries by including a lib directory within your plugin. The lib directory will automatically be added to sys.path if it exists, so you can simply import modules from within lib. You should only use this if you’re using another author’s work that you don’t want to modify. Don’t put your own code in it.

Plugin module architecture

Each plugin must be a module contained within a directory. It cannot simply be a .py file. Here is a sample plugin architecture:

sidebar_coolfeature/
  __init__.py
  defaults.py
  lib/

Additional reference

Please don’t hesitate to use the built-in plugins as additional reference for creating new plugins.

Questions/Feedback

If you notice errors with this documentation, please open a ticket and let us know!