mirror of https://github.com/zulip/zulip.git
bugdown: Simplify the "opts" parameter of `make_md_engine()`.
This commit is contained in:
parent
e3f2f67d0e
commit
e615a2ab4f
|
@ -1286,7 +1286,7 @@ ZEPHYR_MIRROR_BUGDOWN_KEY = -2
|
|||
|
||||
class Bugdown(markdown.Extension):
|
||||
def __init__(self, *args, **kwargs):
|
||||
# type: (*Any, **Union[bool, None, Text]) -> None
|
||||
# type: (*Any, **Union[bool, int, List[Any]]) -> None
|
||||
# define default configs
|
||||
self.config = {
|
||||
"realm_filters": [kwargs['realm_filters'], "Realm-specific filters for realm"],
|
||||
|
@ -1466,9 +1466,9 @@ def make_md_engine(key, opts):
|
|||
),
|
||||
fenced_code.makeExtension(),
|
||||
EscapeHtml(),
|
||||
Bugdown(realm_filters=opts["realm_filters"][0],
|
||||
realm=opts["realm"][0],
|
||||
code_block_processor_disabled=opts["code_block_processor_disabled"][0])])
|
||||
Bugdown(realm_filters=opts["realm_filters"],
|
||||
realm=opts["realm"],
|
||||
code_block_processor_disabled=opts["code_block_processor_disabled"])])
|
||||
|
||||
def subject_links(realm_filters_key, subject):
|
||||
# type: (int, Text) -> List[Text]
|
||||
|
@ -1490,13 +1490,10 @@ def make_realm_filters(realm_filters_key, filters, email_gateway):
|
|||
del md_engines[md_engine_key]
|
||||
realm_filter_data[realm_filters_key] = filters
|
||||
|
||||
# Because of how the Markdown config API works, this has confusing
|
||||
# large number of layers of dicts/arrays :(
|
||||
make_md_engine(md_engine_key,
|
||||
{"realm_filters": [
|
||||
filters, "Realm-specific filters for realm_filters_key %s" % (realm_filters_key,)],
|
||||
"realm": [realm_filters_key, "Realm name"],
|
||||
"code_block_processor_disabled": [email_gateway, 'Disabled for email mirror']})
|
||||
{"realm_filters": filters,
|
||||
"realm": realm_filters_key,
|
||||
"code_block_processor_disabled": email_gateway})
|
||||
|
||||
def maybe_update_markdown_engines(realm_filters_key, email_gateway):
|
||||
# type: (Optional[int], bool) -> None
|
||||
|
|
|
@ -274,9 +274,9 @@ class BugdownTest(ZulipTestCase):
|
|||
realm = Realm.objects.create(string_id='file_links_test')
|
||||
bugdown.make_md_engine(
|
||||
realm.id,
|
||||
{'realm_filters': [[], u'file_links_test.example.com'],
|
||||
'realm': [u'file_links_test.example.com', 'Realm name'],
|
||||
'code_block_processor_disabled': [False, 'Disabled for email gateway']})
|
||||
{'realm_filters': [],
|
||||
'realm': 'file_links_test.example.com',
|
||||
'code_block_processor_disabled': False})
|
||||
converted = bugdown.convert(msg, message_realm=realm)
|
||||
self.assertEqual(converted, '<p>Check out this file file:///Volumes/myserver/Users/Shared/pi.py</p>')
|
||||
|
||||
|
@ -1160,9 +1160,9 @@ class BugdownTest(ZulipTestCase):
|
|||
realm = Realm.objects.create(string_id='code_block_processor_test')
|
||||
bugdown.make_md_engine(
|
||||
realm.id,
|
||||
{'realm_filters': [[], u'file_links_test.example.com'],
|
||||
'realm': [u'file_links_test.example.com', 'Realm name'],
|
||||
'code_block_processor_disabled': [True, 'Disabled for email gateway']})
|
||||
{'realm_filters': [],
|
||||
'realm': 'file_links_test.example.com',
|
||||
'code_block_processor_disabled': True})
|
||||
converted = bugdown.convert(msg, message_realm=realm, email_gateway=True)
|
||||
expected_output = '<p>Hello,</p>\n' + \
|
||||
'<p>I am writing this message to test something. I am writing this message to test something.</p>'
|
||||
|
|
Loading…
Reference in New Issue