mirror of https://github.com/zulip/zulip.git
markdown: Rename markdown.contains_bugdown.
This name was confusing, since "bugdown" doesn't exactly suggest "backend markdown processor" to people.
This commit is contained in:
parent
f58c2b5a47
commit
4f4d28477d
|
@ -18,23 +18,23 @@ sender of a message, and they are (ideally) identical to the backend
|
||||||
rendering.
|
rendering.
|
||||||
|
|
||||||
The JavaScript markdown implementation has a function,
|
The JavaScript markdown implementation has a function,
|
||||||
`markdown.contains_bugdown`, that is used to check whether a message
|
`markdown.contains_backend_only_syntax`, that is used to check whether a message
|
||||||
contains any syntax that needs to be rendered to HTML on the backend.
|
contains any syntax that needs to be rendered to HTML on the backend.
|
||||||
If `markdown.contains_bugdown` returns true, the frontend simply won't
|
If `markdown.contains_backend_only_syntax` returns true, the frontend simply won't
|
||||||
echo the message for the sender until it receives the rendered HTML
|
echo the message for the sender until it receives the rendered HTML
|
||||||
from the backend. If there is a bug where `markdown.contains_bugdown`
|
from the backend. If there is a bug where `markdown.contains_backend_only_syntax`
|
||||||
returns false incorrectly, the frontend will discover this when the
|
returns false incorrectly, the frontend will discover this when the
|
||||||
backend returns the newly sent message, and will update the HTML based
|
backend returns the newly sent message, and will update the HTML based
|
||||||
on the authoritative backend rendering (which would cause a change in
|
on the authoritative backend rendering (which would cause a change in
|
||||||
the rendering that is visible only to the sender shortly after a
|
the rendering that is visible only to the sender shortly after a
|
||||||
message is sent). As a result, we try to make sure that
|
message is sent). As a result, we try to make sure that
|
||||||
`markdown.contains_bugdown` is always correct.
|
`markdown.contains_backend_only_syntax` is always correct.
|
||||||
|
|
||||||
## Testing
|
## Testing
|
||||||
|
|
||||||
The Python-Markdown implementation is tested by
|
The Python-Markdown implementation is tested by
|
||||||
`zerver/tests/test_bugdown.py`, and the marked.js implementation and
|
`zerver/tests/test_bugdown.py`, and the marked.js implementation and
|
||||||
`markdown.contains_bugdown` are tested by
|
`markdown.contains_backend_only_syntax` are tested by
|
||||||
`frontend_tests/node_tests/markdown.js`. A shared set of fixed test data
|
`frontend_tests/node_tests/markdown.js`. A shared set of fixed test data
|
||||||
("test fixtures") is present in `zerver/fixtures/bugdown-data.json`,
|
("test fixtures") is present in `zerver/fixtures/bugdown-data.json`,
|
||||||
and is automatically used by both test suites; as a result, it the
|
and is automatically used by both test suites; as a result, it the
|
||||||
|
@ -59,7 +59,7 @@ places:
|
||||||
|
|
||||||
* The backend markdown processor (`zerver/lib/bugdown/__init__.py`).
|
* The backend markdown processor (`zerver/lib/bugdown/__init__.py`).
|
||||||
* The frontend markdown processor (`static/js/markdown.js` and sometimes
|
* The frontend markdown processor (`static/js/markdown.js` and sometimes
|
||||||
`static/third/marked/lib/marked.js`), or `markdown.contains_bugdown` if
|
`static/third/marked/lib/marked.js`), or `markdown.contains_backend_only_syntax` if
|
||||||
your changes won't be supported in the frontend processor.
|
your changes won't be supported in the frontend processor.
|
||||||
* If desired, the typeahead logic in `static/js/composebox_typeahead.js`.
|
* If desired, the typeahead logic in `static/js/composebox_typeahead.js`.
|
||||||
* The test suite, probably via adding entries to `zerver/fixtures/bugdown-data.json`.
|
* The test suite, probably via adding entries to `zerver/fixtures/bugdown-data.json`.
|
||||||
|
|
|
@ -1149,8 +1149,8 @@ function test_with_mock_socket(test_params) {
|
||||||
assert($("#preview_message_area").visible());
|
assert($("#preview_message_area").visible());
|
||||||
}
|
}
|
||||||
|
|
||||||
function setup_mock_markdown_contains_bugdown(msg_content, return_val) {
|
function setup_mock_markdown_contains_backend_only_syntax(msg_content, return_val) {
|
||||||
markdown.contains_bugdown = function (msg) {
|
markdown.contains_backend_only_syntax = function (msg) {
|
||||||
assert.equal(msg, msg_content);
|
assert.equal(msg, msg_content);
|
||||||
return return_val;
|
return return_val;
|
||||||
};
|
};
|
||||||
|
@ -1183,7 +1183,7 @@ function test_with_mock_socket(test_params) {
|
||||||
assert.equal(spinner, $("#markdown_preview_spinner"));
|
assert.equal(spinner, $("#markdown_preview_spinner"));
|
||||||
destroy_indicator_called = true;
|
destroy_indicator_called = true;
|
||||||
};
|
};
|
||||||
setup_mock_markdown_contains_bugdown(msg, true);
|
setup_mock_markdown_contains_backend_only_syntax(msg, true);
|
||||||
|
|
||||||
func(param);
|
func(param);
|
||||||
|
|
||||||
|
@ -1212,7 +1212,7 @@ function test_with_mock_socket(test_params) {
|
||||||
var make_indicator_called = false;
|
var make_indicator_called = false;
|
||||||
$("#new_message_content").val('```foobarfoobar```');
|
$("#new_message_content").val('```foobarfoobar```');
|
||||||
setup_visibilities();
|
setup_visibilities();
|
||||||
setup_mock_markdown_contains_bugdown('```foobarfoobar```', true);
|
setup_mock_markdown_contains_backend_only_syntax('```foobarfoobar```', true);
|
||||||
loading.make_indicator = function (spinner) {
|
loading.make_indicator = function (spinner) {
|
||||||
assert.equal(spinner, $("#markdown_preview_spinner"));
|
assert.equal(spinner, $("#markdown_preview_spinner"));
|
||||||
make_indicator_called = true;
|
make_indicator_called = true;
|
||||||
|
@ -1227,7 +1227,7 @@ function test_with_mock_socket(test_params) {
|
||||||
var apply_markdown_called = false;
|
var apply_markdown_called = false;
|
||||||
$("#new_message_content").val('foobarfoobar');
|
$("#new_message_content").val('foobarfoobar');
|
||||||
setup_visibilities();
|
setup_visibilities();
|
||||||
setup_mock_markdown_contains_bugdown('foobarfoobar', false);
|
setup_mock_markdown_contains_backend_only_syntax('foobarfoobar', false);
|
||||||
mock_channel_post('foobarfoobar');
|
mock_channel_post('foobarfoobar');
|
||||||
markdown.apply_markdown = function (msg) {
|
markdown.apply_markdown = function (msg) {
|
||||||
assert.equal(msg, 'foobarfoobar');
|
assert.equal(msg, 'foobarfoobar');
|
||||||
|
|
|
@ -141,11 +141,11 @@ var bugdown_data = JSON.parse(fs.readFileSync(path.join(__dirname, '../../zerver
|
||||||
];
|
];
|
||||||
|
|
||||||
no_markup.forEach(function (content) {
|
no_markup.forEach(function (content) {
|
||||||
assert.equal(markdown.contains_bugdown(content), false);
|
assert.equal(markdown.contains_backend_only_syntax(content), false);
|
||||||
});
|
});
|
||||||
|
|
||||||
markup.forEach(function (content) {
|
markup.forEach(function (content) {
|
||||||
assert.equal(markdown.contains_bugdown(content), true);
|
assert.equal(markdown.contains_backend_only_syntax(content), true);
|
||||||
});
|
});
|
||||||
}());
|
}());
|
||||||
|
|
||||||
|
|
|
@ -723,7 +723,7 @@ exports.initialize = function () {
|
||||||
if (message.length === 0) {
|
if (message.length === 0) {
|
||||||
$("#preview_content").html(i18n.t("Nothing to preview"));
|
$("#preview_content").html(i18n.t("Nothing to preview"));
|
||||||
} else {
|
} else {
|
||||||
if (markdown.contains_bugdown(message)) {
|
if (markdown.contains_backend_only_syntax(message)) {
|
||||||
var spinner = $("#markdown_preview_spinner").expectOne();
|
var spinner = $("#markdown_preview_spinner").expectOne();
|
||||||
loading.make_indicator(spinner);
|
loading.make_indicator(spinner);
|
||||||
} else {
|
} else {
|
||||||
|
@ -732,7 +732,7 @@ exports.initialize = function () {
|
||||||
// marked.js frontend processor, we render using the
|
// marked.js frontend processor, we render using the
|
||||||
// frontend markdown processor message (but still
|
// frontend markdown processor message (but still
|
||||||
// render server-side to ensure the preview is
|
// render server-side to ensure the preview is
|
||||||
// accurate; if the `markdown.contains_bugdown` logic is
|
// accurate; if the `markdown.contains_backend_only_syntax` logic is
|
||||||
// incorrect wrong, users will see a brief flicker).
|
// incorrect wrong, users will see a brief flicker).
|
||||||
$("#preview_content").html(markdown.apply_markdown(message));
|
$("#preview_content").html(markdown.apply_markdown(message));
|
||||||
}
|
}
|
||||||
|
@ -741,13 +741,13 @@ exports.initialize = function () {
|
||||||
idempotent: true,
|
idempotent: true,
|
||||||
data: {content: message},
|
data: {content: message},
|
||||||
success: function (response_data) {
|
success: function (response_data) {
|
||||||
if (markdown.contains_bugdown(message)) {
|
if (markdown.contains_backend_only_syntax(message)) {
|
||||||
loading.destroy_indicator($("#markdown_preview_spinner"));
|
loading.destroy_indicator($("#markdown_preview_spinner"));
|
||||||
}
|
}
|
||||||
$("#preview_content").html(response_data.rendered);
|
$("#preview_content").html(response_data.rendered);
|
||||||
},
|
},
|
||||||
error: function () {
|
error: function () {
|
||||||
if (markdown.contains_bugdown(message)) {
|
if (markdown.contains_backend_only_syntax(message)) {
|
||||||
loading.destroy_indicator($("#markdown_preview_spinner"));
|
loading.destroy_indicator($("#markdown_preview_spinner"));
|
||||||
}
|
}
|
||||||
$("#preview_content").html(i18n.t("Failed to generate preview"));
|
$("#preview_content").html(i18n.t("Failed to generate preview"));
|
||||||
|
|
|
@ -131,7 +131,7 @@ function insert_local_message(message_request, local_id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.try_deliver_locally = function try_deliver_locally(message_request) {
|
exports.try_deliver_locally = function try_deliver_locally(message_request) {
|
||||||
if (markdown.contains_bugdown(message_request.content)) {
|
if (markdown.contains_backend_only_syntax(message_request.content)) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ var backend_only_markdown_re = [
|
||||||
/[^\s]*(?:twitter|youtube).com\/[^\s]*/,
|
/[^\s]*(?:twitter|youtube).com\/[^\s]*/,
|
||||||
];
|
];
|
||||||
|
|
||||||
exports.contains_bugdown = function (content) {
|
exports.contains_backend_only_syntax = function (content) {
|
||||||
// Try to guess whether or not a message has bugdown in it
|
// Try to guess whether or not a message has bugdown in it
|
||||||
// If it doesn't, we can immediately render it client-side
|
// If it doesn't, we can immediately render it client-side
|
||||||
var markedup = _.find(backend_only_markdown_re, function (re) {
|
var markedup = _.find(backend_only_markdown_re, function (re) {
|
||||||
|
|
Loading…
Reference in New Issue