mirror of https://github.com/zulip/zulip.git
markdown: Extract parse_non_message().
The zcommand code was calling directly into the "marked" library, which was extremely misleading, since you don't get a vanilla parse of the markdown due to the fact that markdown.js calls setOptions at initialize time. This commit shifts the responsibility to markdown.js as well as adding a bit of test coverage, but it is otherwise just a pure code-move refactoring. The next commit will tweak things further.
This commit is contained in:
parent
cf1149539e
commit
06ba05b44d
|
@ -819,6 +819,10 @@ test("translate_emoticons_to_names", () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("parse_non_message", () => {
|
||||||
|
assert.equal(markdown.parse_non_message("type `/day`"), "<p>type <code>/day</code></p>");
|
||||||
|
});
|
||||||
|
|
||||||
test("missing unicode emojis", ({override_rewire}) => {
|
test("missing unicode emojis", ({override_rewire}) => {
|
||||||
const message = {raw_content: "\u{1F6B2}"};
|
const message = {raw_content: "\u{1F6B2}"};
|
||||||
|
|
||||||
|
|
|
@ -564,3 +564,9 @@ export function apply_markdown(message) {
|
||||||
message.flags = flags;
|
message.flags = flags;
|
||||||
message.is_me_message = is_status_message(raw_content);
|
message.is_me_message = is_status_message(raw_content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function parse_non_message(raw_content) {
|
||||||
|
// Occasionally we get markdown from the server that is not technically
|
||||||
|
// a message, but we want to convert it to HTML.
|
||||||
|
return marked(raw_content).trim();
|
||||||
|
}
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
import $ from "jquery";
|
import $ from "jquery";
|
||||||
|
|
||||||
import marked from "../third/marked/lib/marked";
|
|
||||||
|
|
||||||
import * as channel from "./channel";
|
import * as channel from "./channel";
|
||||||
import * as common from "./common";
|
import * as common from "./common";
|
||||||
import * as dark_theme from "./dark_theme";
|
import * as dark_theme from "./dark_theme";
|
||||||
import * as feedback_widget from "./feedback_widget";
|
import * as feedback_widget from "./feedback_widget";
|
||||||
import {$t} from "./i18n";
|
import {$t} from "./i18n";
|
||||||
|
import * as markdown from "./markdown";
|
||||||
import * as scroll_bar from "./scroll_bar";
|
import * as scroll_bar from "./scroll_bar";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -66,7 +65,7 @@ export function switch_to_light_theme() {
|
||||||
dark_theme.disable();
|
dark_theme.disable();
|
||||||
feedback_widget.show({
|
feedback_widget.show({
|
||||||
populate($container) {
|
populate($container) {
|
||||||
const rendered_msg = marked(data.msg).trim();
|
const rendered_msg = markdown.parse_non_message(data.msg);
|
||||||
$container.html(rendered_msg);
|
$container.html(rendered_msg);
|
||||||
},
|
},
|
||||||
on_undo() {
|
on_undo() {
|
||||||
|
@ -88,7 +87,7 @@ export function switch_to_dark_theme() {
|
||||||
dark_theme.enable();
|
dark_theme.enable();
|
||||||
feedback_widget.show({
|
feedback_widget.show({
|
||||||
populate($container) {
|
populate($container) {
|
||||||
const rendered_msg = marked(data.msg).trim();
|
const rendered_msg = markdown.parse_non_message(data.msg);
|
||||||
$container.html(rendered_msg);
|
$container.html(rendered_msg);
|
||||||
},
|
},
|
||||||
on_undo() {
|
on_undo() {
|
||||||
|
@ -110,7 +109,7 @@ export function enter_fluid_mode() {
|
||||||
scroll_bar.set_layout_width();
|
scroll_bar.set_layout_width();
|
||||||
feedback_widget.show({
|
feedback_widget.show({
|
||||||
populate($container) {
|
populate($container) {
|
||||||
const rendered_msg = marked(data.msg).trim();
|
const rendered_msg = markdown.parse_non_message(data.msg);
|
||||||
$container.html(rendered_msg);
|
$container.html(rendered_msg);
|
||||||
},
|
},
|
||||||
on_undo() {
|
on_undo() {
|
||||||
|
@ -132,7 +131,7 @@ export function enter_fixed_mode() {
|
||||||
scroll_bar.set_layout_width();
|
scroll_bar.set_layout_width();
|
||||||
feedback_widget.show({
|
feedback_widget.show({
|
||||||
populate($container) {
|
populate($container) {
|
||||||
const rendered_msg = marked(data.msg).trim();
|
const rendered_msg = markdown.parse_non_message(data.msg);
|
||||||
$container.html(rendered_msg);
|
$container.html(rendered_msg);
|
||||||
},
|
},
|
||||||
on_undo() {
|
on_undo() {
|
||||||
|
|
Loading…
Reference in New Issue