/usr/share/pyshared/rst2pdf/counter_role.py is in rst2pdf 0.93-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | # -*- coding: utf-8 -*-
from docutils.nodes import Text, target
values = {}
class CounterNode(Text):
children = ()
def __init__(self, data, rawsource=''):
if ':' in data:
self.name, value = [s.lower() for s in data.split(':')][:2]
self.value=int(value)
else:
self.name=data.lower()
self.value=values.get(self.name,1)
values[self.name]=self.value+1
def astext(self):
return unicode(self.value)
def counter_fn(name, rawtext, text, lineno, inliner, options={}, content=[]):
n=CounterNode(text)
s='%s-%s'%(n.name, n.value)
return [target(ids=[s]),n], []
counter_fn.content=True
from docutils.parsers.rst import roles
roles.register_canonical_role('counter', counter_fn)
|