refactor: Rename zerver.lib.bugdown to zerver.lib.markdown .

This commit is first of few commita which aim to change all the
bugdown references to markdown. This commits rename the files,
file path mentions and change the imports.
Variables and other references to bugdown will be renamed in susequent
commits.
This commit is contained in:
Mohit Gupta 2020-06-25 18:30:33 +05:30 committed by Tim Abbott
parent 7c2be24cf8
commit 3f5fc13491
35 changed files with 62 additions and 61 deletions

View File

@ -1,7 +1,7 @@
[settings]
src_paths = .
multi_line_output = 3
known_third_party = decorator, jinja2, stripe, tornado, zulip
known_third_party = decorator, jinja2, markdown, stripe, tornado, zulip
include_trailing_comma = True
use_parentheses = True
line_length = 100

View File

@ -117,7 +117,7 @@ Copyright: 2017 Fonticons, Inc.
License: CC-BY-4.0
Comment: This icon is picked from Version 5.13.0 of Fontawesome
Files: zerver/lib/bugdown/fenced_code.py
Files: zerver/lib/markdown/fenced_code.py
Copyright: 2006-2008 Waylan Limberg
License: BSD-3-Clause
Comment: https://pypi.python.org/pypi/Markdown

View File

@ -170,7 +170,7 @@ We have a separate Markdown extension to document the parameters that
an API endpoint supports. You'll see this in files like
`templates/zerver/api/render-message.md` via the following Markdown
directive (implemented in
`zerver/lib/bugdown/api_arguments_table_generator.py`):
`zerver/lib/markdown/api_arguments_table_generator.py`):
```
{generate_api_arguments_table|zulip.yaml|/messages/render:post}

View File

@ -248,9 +248,9 @@ languages in API docs, etc. To create a tab switcher, write:
The tab identifiers (e.g. `desktop-web` above) and their mappings to
the tabs' labels are declared in
[zerver/lib/bugdown/tabbed_sections.py][tabbed-sections-code].
[zerver/lib/markdown/tabbed_sections.py][tabbed-sections-code].
[tabbed-sections-code]: https://github.com/zulip/zulip/blob/master/zerver/lib/bugdown/tabbed_sections.py#L37
[tabbed-sections-code]: https://github.com/zulip/zulip/blob/master/zerver/lib/markdown/tabbed_sections.py#L37
This widget can also be used just to create a nice box around a set of
instructions

View File

@ -37,7 +37,7 @@ paths will be familiar to Django developers.
* `zerver/worker/queue_processors.py` [Queue workers](../subsystems/queuing.md).
* `zerver/lib/bugdown/` [Backend Markdown processor](../subsystems/markdown.md).
* `zerver/lib/markdown/` [Backend Markdown processor](../subsystems/markdown.md).
* `zproject/backends.py` [Authentication backends](https://docs.djangoproject.com/en/1.8/topics/auth/customizing/).

View File

@ -5,7 +5,7 @@ after Zulip's original name of "humbug". End users are using Bugdown
within the client, not original Markdown.
Zulip has two implementations of Bugdown. The backend implementation
at `zerver/lib/bugdown/` is based on
at `zerver/lib/markdown/` is based on
[Python-Markdown](https://pypi.python.org/pypi/Markdown) and is used to
authoritatively render messages to HTML (and implements
slow/expensive/complex features like querying the Twitter API to
@ -94,7 +94,7 @@ First, you will likely find these third-party resources helpful:
When changing Zulip's markdown syntax, you need to update several
places:
* The backend markdown processor (`zerver/lib/bugdown/__init__.py`).
* The backend markdown processor (`zerver/lib/markdown/__init__.py`).
* The frontend markdown processor (`static/js/markdown.js` and sometimes
`static/third/marked/lib/marked.js`), or `markdown.contains_backend_only_syntax` if
your changes won't be supported in the frontend processor.

View File

@ -110,7 +110,7 @@ strict_optional = False
strict_optional = False
[mypy-zerver.lib.outgoing_webhook]
strict_optional = False
[mypy-zerver.lib.bugdown] # for __init__.py
[mypy-zerver.lib.markdown] # for __init__.py
strict_optional = False
[mypy-zerver.lib.push_notifications]
strict_optional = False

View File

@ -62,7 +62,7 @@ not_yet_fully_covered = {path for target in [
'analytics/views.py',
# Major lib files should have 100% coverage
'zerver/lib/addressee.py',
'zerver/lib/bugdown/__init__.py',
'zerver/lib/markdown/__init__.py',
'zerver/lib/cache.py',
'zerver/lib/cache_helpers.py',
'zerver/lib/i18n.py',
@ -71,10 +71,10 @@ not_yet_fully_covered = {path for target in [
'zerver/lib/url_preview/preview.py',
'zerver/worker/queue_processors.py',
# Bugdown sub-libs should have full coverage too; a lot are really close
'zerver/lib/bugdown/api_arguments_table_generator.py',
'zerver/lib/bugdown/fenced_code.py',
'zerver/lib/bugdown/help_relative_links.py',
'zerver/lib/bugdown/nested_code_blocks.py',
'zerver/lib/markdown/api_arguments_table_generator.py',
'zerver/lib/markdown/fenced_code.py',
'zerver/lib/markdown/help_relative_links.py',
'zerver/lib/markdown/nested_code_blocks.py',
# Other lib files that ideally would coverage, but aren't sorted
'zerver/__init__.py',
'zerver/filters.py',

View File

@ -49,7 +49,7 @@ from confirmation.models import (
generate_key,
)
from zerver.decorator import statsd_increment
from zerver.lib import bugdown
from zerver.lib import markdown as bugdown
from zerver.lib import retention as retention
from zerver.lib.addressee import Addressee
from zerver.lib.alert_words import (
@ -59,7 +59,6 @@ from zerver.lib.alert_words import (
)
from zerver.lib.avatar import avatar_url, avatar_url_from_dict
from zerver.lib.bot_config import ConfigError, get_bot_config, get_bot_configs, set_bot_config
from zerver.lib.bugdown import version as bugdown_version
from zerver.lib.bulk_create import bulk_create_users
from zerver.lib.cache import (
bot_dict_fields,
@ -97,6 +96,7 @@ from zerver.lib.export import get_realm_exports_serialized
from zerver.lib.external_accounts import DEFAULT_EXTERNAL_ACCOUNTS
from zerver.lib.hotspots import get_next_hotspots
from zerver.lib.i18n import get_language_name
from zerver.lib.markdown import version as bugdown_version
from zerver.lib.message import (
MessageDict,
access_message,

View File

@ -15,7 +15,7 @@ from psycopg2.extras import execute_values
from psycopg2.sql import SQL, Identifier
from analytics.models import RealmCount, StreamCount, UserCount
from zerver.lib import bugdown
from zerver.lib import markdown as bugdown
from zerver.lib.actions import (
UserMessageLite,
bulk_insert_ums,
@ -23,9 +23,9 @@ from zerver.lib.actions import (
do_change_plan_type,
)
from zerver.lib.avatar_hash import user_avatar_path_from_ids
from zerver.lib.bugdown import version as bugdown_version
from zerver.lib.bulk_create import bulk_create_users, bulk_set_users_or_streams_recipient_fields
from zerver.lib.export import DATE_FIELDS, Field, Path, Record, TableData, TableName
from zerver.lib.markdown import version as bugdown_version
from zerver.lib.parallel import run_parallel
from zerver.lib.server_initialization import create_internal_realm, server_initialized
from zerver.lib.streams import render_stream_description

View File

@ -41,8 +41,6 @@ from markdown.extensions import codehilite, nl2br, sane_lists, tables
from typing_extensions import TypedDict
from zerver.lib import mention as mention
from zerver.lib.bugdown import fenced_code
from zerver.lib.bugdown.fenced_code import FENCE_RE
from zerver.lib.cache import NotFoundInCache, cache_with_key
from zerver.lib.camo import get_camo_url
from zerver.lib.emoji import (
@ -52,6 +50,8 @@ from zerver.lib.emoji import (
translate_emoticons,
)
from zerver.lib.exceptions import BugdownRenderingException
from zerver.lib.markdown import fenced_code
from zerver.lib.markdown.fenced_code import FENCE_RE
from zerver.lib.mention import extract_user_group, possible_mentions, possible_user_group_mentions
from zerver.lib.tex import render_tex
from zerver.lib.thumbnail import user_uploads_or_external

View File

@ -4,7 +4,7 @@ from xml.etree.ElementTree import Element, SubElement
import markdown
from markdown.extensions import Extension
from zerver.lib.bugdown import ResultWithFamily, walk_tree_with_family
from zerver.lib.markdown import ResultWithFamily, walk_tree_with_family
class NestedCodeBlocksRenderer(Extension):

View File

@ -13,7 +13,7 @@ from psycopg2.sql import SQL
from typing_extensions import TypedDict
from analytics.lib.counts import COUNT_STATS, RealmCount
from zerver.lib import bugdown as bugdown
from zerver.lib import markdown as bugdown
from zerver.lib.avatar import get_avatar_field
from zerver.lib.cache import (
cache_with_key,

View File

@ -1,10 +1,10 @@
from zerver.lib.bugdown import convert as bugdown_convert
from zerver.lib.cache import (
cache_with_key,
realm_rendered_description_cache_key,
realm_text_description_cache_key,
)
from zerver.lib.html_to_text import html_to_text
from zerver.lib.markdown import convert as bugdown_convert
from zerver.models import Realm

View File

@ -4,7 +4,7 @@ from django.conf import settings
from django.db.models.query import QuerySet
from django.utils.translation import ugettext as _
from zerver.lib.bugdown import convert as bugdown_convert
from zerver.lib.markdown import convert as bugdown_convert
from zerver.lib.request import JsonableError
from zerver.models import (
DefaultStreamGroup,

View File

@ -823,8 +823,8 @@ class ZulipTestCase(TestCase):
'''
with \
self.settings(ERROR_BOT=None), \
mock.patch('zerver.lib.bugdown.timeout', side_effect=KeyError('foo')), \
mock.patch('zerver.lib.bugdown.bugdown_logger'):
mock.patch('zerver.lib.markdown.timeout', side_effect=KeyError('foo')), \
mock.patch('zerver.lib.markdown.bugdown_logger'):
yield
def create_default_device(self, user_profile: UserProfile,

View File

@ -14,12 +14,12 @@ from django.utils.deprecation import MiddlewareMixin
from django.utils.translation import ugettext as _
from django.views.csrf import csrf_failure as html_csrf_failure
from zerver.lib.bugdown import get_bugdown_requests, get_bugdown_time
from zerver.lib.cache import get_remote_cache_requests, get_remote_cache_time
from zerver.lib.db import reset_queries
from zerver.lib.debug import maybe_tracemalloc_listen
from zerver.lib.exceptions import ErrorCode, JsonableError, RateLimited
from zerver.lib.html_to_text import get_content_description
from zerver.lib.markdown import get_bugdown_requests, get_bugdown_time
from zerver.lib.rate_limiter import RateLimitResult
from zerver.lib.response import json_error, json_response_from_error
from zerver.lib.subdomains import get_subdomain

View File

@ -9,15 +9,15 @@ from django.template import Library, engines
from django.utils.safestring import mark_safe
from jinja2.exceptions import TemplateNotFound
import zerver.lib.bugdown.api_arguments_table_generator
import zerver.lib.bugdown.api_return_values_table_generator
import zerver.lib.bugdown.fenced_code
import zerver.lib.bugdown.help_emoticon_translations_table
import zerver.lib.bugdown.help_relative_links
import zerver.lib.bugdown.help_settings_links
import zerver.lib.bugdown.include
import zerver.lib.bugdown.nested_code_blocks
import zerver.lib.bugdown.tabbed_sections
import zerver.lib.markdown.api_arguments_table_generator
import zerver.lib.markdown.api_return_values_table_generator
import zerver.lib.markdown.fenced_code
import zerver.lib.markdown.help_emoticon_translations_table
import zerver.lib.markdown.help_relative_links
import zerver.lib.markdown.help_settings_links
import zerver.lib.markdown.include
import zerver.lib.markdown.nested_code_blocks
import zerver.lib.markdown.tabbed_sections
import zerver.openapi.markdown_extension
from zerver.lib.cache import dict_to_items_tuple, ignore_unhashable_lru_cache, items_tuple_to_dict
@ -85,9 +85,9 @@ def render_markdown_path(markdown_file_path: str,
data."""
# We set this global hackishly
from zerver.lib.bugdown.help_settings_links import set_relative_settings_links
from zerver.lib.markdown.help_settings_links import set_relative_settings_links
set_relative_settings_links(bool(context.get('html_settings_links')))
from zerver.lib.bugdown.help_relative_links import set_relative_help_links
from zerver.lib.markdown.help_relative_links import set_relative_help_links
set_relative_help_links(bool(context.get('html_settings_links')))
global md_extensions
@ -101,21 +101,21 @@ def render_markdown_path(markdown_file_path: str,
linenums=False,
guess_lang=False,
),
zerver.lib.bugdown.fenced_code.makeExtension(
zerver.lib.markdown.fenced_code.makeExtension(
run_content_validators=context.get('run_content_validators', False),
),
zerver.lib.bugdown.api_arguments_table_generator.makeExtension(
zerver.lib.markdown.api_arguments_table_generator.makeExtension(
base_path='templates/zerver/api/'),
zerver.lib.bugdown.api_return_values_table_generator.makeExtension(
zerver.lib.markdown.api_return_values_table_generator.makeExtension(
base_path='templates/zerver/api/'),
zerver.lib.bugdown.nested_code_blocks.makeExtension(),
zerver.lib.bugdown.tabbed_sections.makeExtension(),
zerver.lib.bugdown.help_settings_links.makeExtension(),
zerver.lib.bugdown.help_relative_links.makeExtension(),
zerver.lib.bugdown.help_emoticon_translations_table.makeExtension(),
zerver.lib.markdown.nested_code_blocks.makeExtension(),
zerver.lib.markdown.tabbed_sections.makeExtension(),
zerver.lib.markdown.help_settings_links.makeExtension(),
zerver.lib.markdown.help_relative_links.makeExtension(),
zerver.lib.markdown.help_emoticon_translations_table.makeExtension(),
]
if md_macro_extension is None:
md_macro_extension = zerver.lib.bugdown.include.makeExtension(
md_macro_extension = zerver.lib.markdown.include.makeExtension(
base_path='templates/zerver/help/include/')
extensions = md_extensions
if 'api_url' in context:

View File

@ -9,7 +9,8 @@ import ujson
from django.conf import settings
from django.test import TestCase, override_settings
from zerver.lib import bugdown, mdiff
from zerver.lib import markdown as bugdown
from zerver.lib import mdiff
from zerver.lib.actions import (
do_add_alert_words,
do_remove_realm_emoji,
@ -657,14 +658,14 @@ class BugdownTest(ZulipTestCase):
def test_inline_dropbox(self) -> None:
msg = 'Look at how hilarious our old office was: https://www.dropbox.com/s/ymdijjcg67hv2ta/IMG_0923.JPG'
image_info = {'image': 'https://photos-4.dropbox.com/t/2/AABIre1oReJgPYuc_53iv0IHq1vUzRaDg2rrCfTpiWMccQ/12/129/jpeg/1024x1024/2/_/0/4/IMG_0923.JPG/CIEBIAEgAiAHKAIoBw/ymdijjcg67hv2ta/AABz2uuED1ox3vpWWvMpBxu6a/IMG_0923.JPG', 'desc': 'Shared with Dropbox', 'title': 'IMG_0923.JPG'}
with mock.patch('zerver.lib.bugdown.fetch_open_graph_image', return_value=image_info):
with mock.patch('zerver.lib.markdown.fetch_open_graph_image', return_value=image_info):
converted = bugdown_convert(msg)
self.assertEqual(converted, '<p>Look at how hilarious our old office was: <a href="https://www.dropbox.com/s/ymdijjcg67hv2ta/IMG_0923.JPG">https://www.dropbox.com/s/ymdijjcg67hv2ta/IMG_0923.JPG</a></p>\n<div class="message_inline_image"><a href="https://www.dropbox.com/s/ymdijjcg67hv2ta/IMG_0923.JPG" title="IMG_0923.JPG"><img src="https://www.dropbox.com/s/ymdijjcg67hv2ta/IMG_0923.JPG?dl=1"></a></div>')
msg = 'Look at my hilarious drawing folder: https://www.dropbox.com/sh/cm39k9e04z7fhim/AAAII5NK-9daee3FcF41anEua?dl='
image_info = {'image': 'https://cf.dropboxstatic.com/static/images/icons128/folder_dropbox.png', 'desc': 'Shared with Dropbox', 'title': 'Saves'}
with mock.patch('zerver.lib.bugdown.fetch_open_graph_image', return_value=image_info):
with mock.patch('zerver.lib.markdown.fetch_open_graph_image', return_value=image_info):
converted = bugdown_convert(msg)
self.assertEqual(converted, '<p>Look at my hilarious drawing folder: <a href="https://www.dropbox.com/sh/cm39k9e04z7fhim/AAAII5NK-9daee3FcF41anEua?dl=">https://www.dropbox.com/sh/cm39k9e04z7fhim/AAAII5NK-9daee3FcF41anEua?dl=</a></p>\n<div class="message_inline_ref"><a href="https://www.dropbox.com/sh/cm39k9e04z7fhim/AAAII5NK-9daee3FcF41anEua?dl=" title="Saves"><img src="https://cf.dropboxstatic.com/static/images/icons128/folder_dropbox.png"></a><div><div class="message_inline_image_title">Saves</div><desc class="message_inline_image_desc"></desc></div></div>')
@ -673,7 +674,7 @@ class BugdownTest(ZulipTestCase):
# Test photo album previews
msg = 'https://www.dropbox.com/sc/tditp9nitko60n5/03rEiZldy5'
image_info = {'image': 'https://photos-6.dropbox.com/t/2/AAAlawaeD61TyNewO5vVi-DGf2ZeuayfyHFdNTNzpGq-QA/12/271544745/jpeg/1024x1024/2/_/0/5/baby-piglet.jpg/CKnjvYEBIAIgBygCKAc/tditp9nitko60n5/AADX03VAIrQlTl28CtujDcMla/0', 'desc': 'Shared with Dropbox', 'title': '1 photo'}
with mock.patch('zerver.lib.bugdown.fetch_open_graph_image', return_value=image_info):
with mock.patch('zerver.lib.markdown.fetch_open_graph_image', return_value=image_info):
converted = bugdown_convert(msg)
self.assertEqual(converted, '<p><a href="https://www.dropbox.com/sc/tditp9nitko60n5/03rEiZldy5">https://www.dropbox.com/sc/tditp9nitko60n5/03rEiZldy5</a></p>\n<div class="message_inline_image"><a href="https://www.dropbox.com/sc/tditp9nitko60n5/03rEiZldy5" title="1 photo"><img src="https://photos-6.dropbox.com/t/2/AAAlawaeD61TyNewO5vVi-DGf2ZeuayfyHFdNTNzpGq-QA/12/271544745/jpeg/1024x1024/2/_/0/5/baby-piglet.jpg/CKnjvYEBIAIgBygCKAc/tditp9nitko60n5/AADX03VAIrQlTl28CtujDcMla/0"></a></div>')
@ -681,7 +682,7 @@ class BugdownTest(ZulipTestCase):
def test_inline_dropbox_negative(self) -> None:
# Make sure we're not overzealous in our conversion:
msg = 'Look at the new dropbox logo: https://www.dropbox.com/static/images/home_logo.png'
with mock.patch('zerver.lib.bugdown.fetch_open_graph_image', return_value=None):
with mock.patch('zerver.lib.markdown.fetch_open_graph_image', return_value=None):
converted = bugdown_convert(msg)
self.assertEqual(converted, '<p>Look at the new dropbox logo: <a href="https://www.dropbox.com/static/images/home_logo.png">https://www.dropbox.com/static/images/home_logo.png</a></p>\n<div class="message_inline_image"><a href="https://www.dropbox.com/static/images/home_logo.png"><img data-src-fullsize="/thumbnail?url=https%3A%2F%2Fwww.dropbox.com%2Fstatic%2Fimages%2Fhome_logo.png&amp;size=full" src="/thumbnail?url=https%3A%2F%2Fwww.dropbox.com%2Fstatic%2Fimages%2Fhome_logo.png&amp;size=thumbnail"></a></div>')
@ -689,7 +690,7 @@ class BugdownTest(ZulipTestCase):
def test_inline_dropbox_bad(self) -> None:
# Don't fail on bad dropbox links
msg = "https://zulip-test.dropbox.com/photos/cl/ROmr9K1XYtmpneM"
with mock.patch('zerver.lib.bugdown.fetch_open_graph_image', return_value=None):
with mock.patch('zerver.lib.markdown.fetch_open_graph_image', return_value=None):
converted = bugdown_convert(msg)
self.assertEqual(converted, '<p><a href="https://zulip-test.dropbox.com/photos/cl/ROmr9K1XYtmpneM">https://zulip-test.dropbox.com/photos/cl/ROmr9K1XYtmpneM</a></p>')
@ -2106,8 +2107,8 @@ class BugdownErrorTests(ZulipTestCase):
throws an exception"""
msg = 'mock rendered message\n' * MAX_MESSAGE_LENGTH
with mock.patch('zerver.lib.bugdown.timeout', return_value=msg), \
mock.patch('zerver.lib.bugdown.bugdown_logger'):
with mock.patch('zerver.lib.markdown.timeout', return_value=msg), \
mock.patch('zerver.lib.markdown.bugdown_logger'):
with self.assertRaises(BugdownRenderingException):
bugdown_convert(msg)

View File

@ -9,8 +9,8 @@ from zerver.lib.actions import (
try_add_realm_custom_profile_field,
try_reorder_realm_custom_profile_fields,
)
from zerver.lib.bugdown import convert as bugdown_convert
from zerver.lib.external_accounts import DEFAULT_EXTERNAL_ACCOUNTS
from zerver.lib.markdown import convert as bugdown_convert
from zerver.lib.test_classes import ZulipTestCase
from zerver.lib.test_helpers import queries_captured
from zerver.models import (

View File

@ -98,13 +98,13 @@ from zerver.lib.actions import (
remove_members_from_user_group,
try_update_realm_custom_profile_field,
)
from zerver.lib.bugdown import MentionData
from zerver.lib.events import (
apply_events,
fetch_initial_state_data,
get_raw_user_data,
post_process_state,
)
from zerver.lib.markdown import MentionData
from zerver.lib.message import (
MessageDict,
UnreadMessagesResult,

View File

@ -691,7 +691,7 @@ class PreviewTestCase(ZulipTestCase):
mocked_response = mock.Mock(side_effect=self.create_mock_response(url))
with self.settings(TEST_SUITE=False, CACHES=TEST_CACHES):
with mock.patch('requests.get', mocked_response):
with mock.patch('zerver.lib.bugdown.link_preview.link_embed_data_from_cache',
with mock.patch('zerver.lib.markdown.link_preview.link_embed_data_from_cache',
lambda *args, **kwargs: mocked_data):
FetchLinksEmbedData().consume(event)

View File

@ -16,7 +16,7 @@ from django.utils.timezone import now as timezone_now
from analytics.lib.counts import COUNT_STATS
from analytics.models import RealmCount
from zerver.decorator import JsonableError
from zerver.lib import bugdown
from zerver.lib import markdown as bugdown
from zerver.lib.actions import (
check_message,
check_send_stream_message,

View File

@ -8,7 +8,7 @@ from django.utils.timezone import now as timezone_now
from django.utils.translation import ugettext as _
from zerver.decorator import REQ, has_request_variables
from zerver.lib import bugdown
from zerver.lib import markdown as bugdown
from zerver.lib.actions import (
do_delete_messages,
do_update_message,

View File

@ -9,7 +9,7 @@ from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_POST
from zerver.decorator import human_users_only
from zerver.lib.bugdown import privacy_clean_markdown
from zerver.lib.markdown import privacy_clean_markdown
from zerver.lib.queue import queue_json_publish
from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_success