Menu

#17 allow custom interpreted text roles resolver

None
closed-out-of-date
None
5
2021-09-11
2005-02-21
No

I need to replace the default intepreted text roles
resolver roles.role() with a custom one. Actually there
is no easy way to do that. I have cooked the small
patch attached to do that. In this way i can do
something like:

class Roles:
def __init__(self):
self.resolvers = [ ]

def register(self, resolver):
self.resolvers.append(resolver)

def role(self, *args, **kwargs):
function, messages = roles.role(*args, **kwargs)
if function is None:
for resolver in self.resolvers:
handler = resolver(*args, **kwargs)
if callable(handler):
return handler, []
return function, messages

class Inliner(rst.states.Inliner):
def __init__(self):
roles = Roles()
rst.states.Inliner.__init__(self, roles=roles)

class Parser(rst.Parser):
def __init__(self):
inliner = Inliner()
rst.Parser.__init__(self, inliner=inliner)

class Reader(standalone.Reader):
def __init__(self, obj, hub):
parser = Parser()
standalone.Reader.__init__(self, parser=parser)

reader = Reader(obj, hub)
reader.parser.inliner.roles.register(CustomRolesResolver(params))
writer = Writer()
parts = publish_parts(source=src,
reader=reader,
writer=writer,
settings_overrides=settings,
config_section='my application')

where CustomRoleResolver() is a class that has a
__call__ method that implements the interface of
roles.role() function.

Related

Patches: #156

Discussion

  • Daniele Nicolodi

    patch

     
  • Felix Wiemann

    Felix Wiemann - 2005-06-27

    Logged In: YES
    user_id=1014490

    I couldn't apply that patch, so I manually changed the code.
    A unified
    diff against current code is attached. The test suite still
    passes.

    I'm not sure if we want to check it in, though. David, any
    comments?

     
  • Felix Wiemann

    Felix Wiemann - 2005-06-27
    • assigned_to: nobody --> goodger
     
  • Felix Wiemann

    Felix Wiemann - 2005-06-27

    New patch against current code.

     
  • Günter Milde

    Günter Milde - 2021-09-11
    • status: open --> closed-out-of-date
    • Group: --> None
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.