60 |
60 |
|
61 |
61 |
|
62 |
62 |
if docutils:
|
63 |
|
# custom parser to only allow arabic sequences, this prevents the rst
|
64 |
|
# parser to consider M. as starting a (upper alpha / roman) sequence.
|
|
63 |
from docutils import statemachine
|
|
64 |
|
65 |
65 |
class Body(docutils.parsers.rst.states.Body):
|
66 |
66 |
def is_enumerated_list_item(self, ordinal, sequence, format):
|
|
67 |
# customised to only allow arabic sequences, this prevents the rst
|
|
68 |
# parser to consider M. as starting a (upper alpha / roman) sequence.
|
67 |
69 |
if format == 'period' and sequence != 'arabic':
|
68 |
70 |
return False
|
69 |
71 |
return docutils.parsers.rst.states.Body.is_enumerated_list_item(
|
70 |
72 |
self, ordinal, sequence, format)
|
71 |
73 |
|
|
74 |
def line(self, match, context, next_state):
|
|
75 |
# customised to ignore unexpected overlines or transitions (due
|
|
76 |
# for example by a field filled by question marks.
|
|
77 |
if self.state_machine.match_titles:
|
|
78 |
return [match.string], 'Line', []
|
|
79 |
elif match.string.strip() == '::':
|
|
80 |
raise statemachine.TransitionCorrection('text')
|
|
81 |
else:
|
|
82 |
# Unexpected possible title overline or transition.
|
|
83 |
# Treating it as ordinary text.
|
|
84 |
raise statemachine.TransitionCorrection('text')
|
|
85 |
|
72 |
86 |
class CustomRstParser(docutils.parsers.rst.Parser):
|
73 |
87 |
def __init__(self, *args, **kwargs):
|
74 |
88 |
docutils.parsers.rst.Parser.__init__(self, *args, **kwargs)
|
75 |
89 |
self.state_classes = tuple([Body] + list(self.state_classes[1:]))
|
|
90 |
docutils.parsers.rst.states.state_classes = self.state_classes
|
|
91 |
|
|
92 |
def custom_rststate_init(self, state_machine, debug=False):
|
|
93 |
state_classes = tuple([Body] + list(docutils.parsers.rst.states.state_classes[1:]))
|
|
94 |
self.nested_sm_kwargs = {'state_classes': state_classes,
|
|
95 |
'initial_state': 'Body'}
|
|
96 |
docutils.parsers.rst.states.StateWS.__init__(self, state_machine, debug)
|
|
97 |
|
|
98 |
docutils.parsers.rst.states.RSTState.__init__ = custom_rststate_init
|
76 |
99 |
|
77 |
100 |
|
78 |
101 |
def custom_template_email(key, mail_body_data, email_rcpt, **kwargs):
|
79 |
|
-
|