Factory function for dialect objects (for parameter defaults, see creole10_base())
| Parameters: |
|
|---|
Returns a base class for extending (for parameter descriptions, see create_dialect())
The returned class does not implement any of the proposed additions to to Creole 1.0 specification.
Returns a base class for extending (for parameter descriptions, see create_dialect())
The returned class implements most of the officially proposed additions to to Creole 1.0 specification:
- superscript, subscript, underline, and monospace
- definition lists
- macros
A Basic Extending Example
Here we create a dialect that alters the basic Creole inline syntax by removing underline and adding strike-though:
>>> Base = creole11_base()
>>> class MyDialect(Base):
... simple_element = SimpleElement(token_dict={'**':'strong',
... '//':'em',
... ',,':'sub',
... '^^':'sup',
... '--':'del',
... '##':'code'})
>>> from core import Parser
>>> parser = Parser(MyDialect) # for verion 6.0, use Parser(MyDialect())
>>> print parser.render("delete --this-- but don't underline __this__"),
<p>delete <del>this</del> but don't underline __this__</p>
For a more complex example, see the source code of this function. It extends the class created from creole10_base().
Note
It is generally safest to create only one dialect instance per base class. This is because WikiElement objects are bound as class attributes and would therefor be shared between multiple instances, which could lead to unexpected behaviour.
Returns a dialect object (a class) to be used by ArgParser
How it Works
The “Creepy” dialect uses a syntax that can look much like that of attribute definition in xml. The most important differences are that positional arguments are allowed and quoting is optional.
A Creepy dialect object is normally passed to ArgParser to create a new parser object. When called with a single argument, this outputs a two-tuple (a list of positional arguments and a dictionary of keyword arguments):
>>> from core import ArgParser
>>> my_parser = ArgParser(dialect=creepy10_base(), convert_implicit_lists=False)
>>> my_parser(" foo='one' ")
([], {'foo': 'one'})
>>> my_parser(" 'one' ")
(['one'], {})
>>> my_parser(" 'one' foo='two' ")
(['one'], {'foo': 'two'})
Positional arguments must come before keyword arguments. If they occur after a keyword argument, they will be combined with that value as a list:
>>> my_parser(" foo='one' 'two' ")
([], {'foo': ['one', 'two']})
Similarly, if two or more keywords are the same, the values will be combined into a list:
>>> my_parser(" foo='one' foo='two' ")
([], {'foo': ['one', 'two']})
The lists above are known as “Implicit” lists. They can automatically be converted to strings by setting convert_implicit_lists=True in the parser.
Quotes can be single or double:
>>> my_parser(''' foo="it's okay" ''')
([], {'foo': "it's okay"})
Tildes can be used for escaping:
>>> my_parser(''' foo='it~'s okay' ''')
([], {'foo': "it's okay"})
Quotes are optional if an argument value doesn’t contain spaces or unescaped special characters:
>>> my_parser(" one foo = two ")
(['one'], {'foo': 'two'})
Keyword arguments lacking a value will be interpreted as an empty string:
>>> my_parser(" '' foo= boo= '' ")
([''], {'foo': '', 'boo': ''})
Extends creepy10_base to support an explicit list argument syntax.
>>> from core import ArgParser
>>> my_parser = ArgParser(dialect=creepy20_base(),convert_implicit_lists=False)
>>> my_parser(" one [two three] foo=['four' 'five'] ")
(['one', ['two', 'three']], {'foo': ['four', 'five']})
You can test if a list is explicit by testing its class:
>>> from core import ImplicitList
>>> pos, kw = my_parser(" foo=['one' 'two'] boo = 'three' 'four'")
>>> print kw
{'foo': ['one', 'two'], 'boo': ['three', 'four']}
>>> isinstance(kw['foo'], ImplicitList)
False
>>> isinstance(kw['boo'], ImplicitList)
True
Lists of length zero or one are never of type ImplicitList.