match custom_markup before elements.py members

16 views
Skip to first unread message

kswtch

unread,
Jan 22, 2011, 7:05:08 AM1/22/11
to creoleparser
I want to extend creoleparser with some custom markup to support
creation of anchors on a page. I created a regular expression to match
something like [[@anchorname]] to create an anchor and [[#anchorname|
linktext]] to link to this anchor.
Unfortunately my custom_markup is never matched because the WikiLink
element in elements.py is matched first. Is there a smart way to match
my expressions first?
I could use a different style to create those links (not using
brackets) but you know the average user. "[[ is everything with links
and dare you implement another thing I have to remember"

Stephen Day

unread,
Jan 22, 2011, 9:20:41 AM1/22/11
to creoleparser
Hi kswtch,

You can change the parsing order by overriding the inline_elements()
method
of your custom dialect (untested):

@property
def inline_elements(self):
return [(self.no_wiki,self.bodiedmacro,self.macro), self.img ] + \
self.custom_elements + [self.link, self.br, self.raw_link,
self.simple_element]

For further help, look at the "Basic Extending Example":

http://creoleparser.googlecode.com/svn/docs/modules/dialects.html#creoleparser.dialects.creole11_base

Alternatively, you could work on the LinkElement class of the library
itself,
as I'd be open to a patch regarding this. There is an open issue that
covers part of your case:

http://code.google.com/p/creoleparser/issues/detail?id=36

Cheers,

Stephen Day
Reply all
Reply to author
Forward
0 new messages