bengillies.net

a blog by Ben Gillies

tiddlywiki_validator.py

This is a Python plugin for TiddlyWeb that filters out specific tiddlers base on titles matched with a blacklist. It also removes the systemConfig tag, if present and is designed to be used speficially to validate TiddlyWebWiki. It is available on GitHub at tiddlywiki_validator.py.

The code is republished below for reference purposes (though any future updates will only appear on GitHub):

from tiddlyweb.web.validator import TIDDLER_VALIDATORS
from tiddlyweb.model.tiddler import Tiddler
 
"""
sanitise all tiddlywiki input by dissallowing reserved names, and clearing systemConfig tags.
 
Any tiddler in RESERVED_TITLES will be dissallowed.
"""
 
RESERVED_TITLES=[
    'MarkupPreHead',
    'MarkupPostBody'
]
 
def validate_tiddlywiki(tiddler,environ):
    if tiddler.title in RESERVED_TITLES:
        raise Exception('Reserved name')
    if 'systemConfig' in tiddler.tags:
        tiddler.tags.remove('systemConfig')
 
def init(config_in):
    """
init function
"""
    TIDDLER_VALIDATORS.append(validate_tiddlywiki)
 

Comments

name:
comment: