misc: only let rst consider arabic sequences (#29183)
This commit is contained in:
parent
14e543ccce
commit
bb926723c9
|
@ -418,3 +418,30 @@ def test_normalize_geolocation():
|
|||
assert normalize_geolocation({'lat': 0.0, 'lon': -360.0}) == {'lat': 0.0, 'lon': 0.0}
|
||||
assert normalize_geolocation({'lat': 0.0, 'lon': 400.0}) == {'lat': 0.0, 'lon': 40.0}
|
||||
assert normalize_geolocation({'lat': 0.0, 'lon': -400.0}) == {'lat': 0.0, 'lon': -40.0}
|
||||
|
||||
@pytest.mark.skipif('docutils is None')
|
||||
def test_email_with_enumeration(emails):
|
||||
pub = create_temporary_pub()
|
||||
pub.cfg['emails'] = {'footer': 'Footer\nText'}
|
||||
mail_body = '''
|
||||
A. FooAlpha1
|
||||
B. FooAlpha2
|
||||
|
||||
1. Num1
|
||||
2. Num2
|
||||
|
||||
M. Francis Kuntz
|
||||
|
||||
'''
|
||||
send_email('test', mail_body=mail_body, email_rcpt='test@localhost')
|
||||
assert emails.count() == 1
|
||||
assert emails.emails['test']['msg'].is_multipart()
|
||||
assert emails.emails['test']['msg'].get_content_subtype() == 'alternative'
|
||||
assert emails.emails['test']['msg'].get_payload()[0].get_content_type() == 'text/plain'
|
||||
assert emails.emails['test']['msg'].get_payload()[1].get_content_type() == 'text/html'
|
||||
text = emails.emails['test']['msg'].get_payload()[0].get_payload()
|
||||
html = emails.emails['test']['msg'].get_payload()[1].get_payload()
|
||||
assert html.count('<ol') == 1
|
||||
assert not '<ul' in html
|
||||
assert 'arabic simple' in html
|
||||
assert 'M. Francis Kuntz' in html
|
||||
|
|
|
@ -36,6 +36,8 @@ try:
|
|||
import docutils
|
||||
import docutils.core
|
||||
import docutils.io
|
||||
import docutils.parsers.rst
|
||||
import docutils.parsers.rst.states
|
||||
except ImportError:
|
||||
docutils = None
|
||||
|
||||
|
@ -53,6 +55,22 @@ from template import Template
|
|||
Charset.add_charset('utf-8', Charset.QP, Charset.QP, 'utf-8')
|
||||
|
||||
|
||||
if docutils:
|
||||
# custom parser to only allow arabic sequences, this prevents the rst
|
||||
# parser to consider M. as starting a (upper alpha / roman) sequence.
|
||||
class Body(docutils.parsers.rst.states.Body):
|
||||
def is_enumerated_list_item(self, ordinal, sequence, format):
|
||||
if format == 'period' and sequence != 'arabic':
|
||||
return False
|
||||
return docutils.parsers.rst.states.Body.is_enumerated_list_item(
|
||||
self, ordinal, sequence, format)
|
||||
|
||||
class CustomRstParser(docutils.parsers.rst.Parser):
|
||||
def __init__(self, *args, **kwargs):
|
||||
docutils.parsers.rst.Parser.__init__(self, *args, **kwargs)
|
||||
self.state_classes = tuple([Body] + list(self.state_classes[1:]))
|
||||
|
||||
|
||||
def custom_template_email(key, mail_body_data, email_rcpt, **kwargs):
|
||||
if not EmailsDirectory.is_enabled(key):
|
||||
return
|
||||
|
@ -146,7 +164,7 @@ def email(subject, mail_body, email_rcpt, replyto = None, bcc = None,
|
|||
destination = None,
|
||||
destination_path = None,
|
||||
reader = None, reader_name = 'standalone',
|
||||
parser = None, parser_name = 'restructuredtext',
|
||||
parser=CustomRstParser(), parser_name=None,
|
||||
writer = None, writer_name = 'html',
|
||||
settings = None, settings_spec = None,
|
||||
settings_overrides = {'input_encoding': encoding,
|
||||
|
|
Loading…
Reference in New Issue