js: Remove some pointless IIFEs.

Some of these were there because they predate block-scoped const/let.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2021-05-06 12:49:45 -07:00
committed by Tim Abbott
parent 707d23d1e8
commit fc9481a24e
9 changed files with 159 additions and 178 deletions

View File

@@ -106,81 +106,79 @@ export function process_fenced_code(content) {
function handler_for_fence(output_lines, fence, lang, header) {
// lang is ignored except for 'quote', as we
// don't do syntax highlighting yet
return (function () {
const lines = [];
if (lang === "quote") {
return {
handle_line(line) {
if (line === fence) {
this.done();
} else {
consume_line(lines, line);
}
},
done() {
const text = wrap_quote(lines.join("\n"));
output_lines.push("", text, "");
handler_stack.pop();
},
};
}
if (lang === "math") {
return {
handle_line(line) {
if (line === fence) {
this.done();
} else {
lines.push(line);
}
},
done() {
const text = wrap_tex(lines.join("\n"));
const placeholder = stash_func(text, true);
output_lines.push("", placeholder, "");
handler_stack.pop();
},
};
}
if (lang === "spoiler") {
return {
handle_line(line) {
if (line === fence) {
this.done();
} else {
lines.push(line);
}
},
done() {
const text = wrap_spoiler(header, lines.join("\n"), stash_func);
output_lines.push("", text, "");
handler_stack.pop();
},
};
}
const lines = [];
if (lang === "quote") {
return {
handle_line(line) {
if (line === fence) {
this.done();
} else {
lines.push(line.trimEnd());
consume_line(lines, line);
}
},
done() {
const text = wrap_code(lines.join("\n"), lang);
// insert safe HTML that is passed through the parsing
const text = wrap_quote(lines.join("\n"));
output_lines.push("", text, "");
handler_stack.pop();
},
};
}
if (lang === "math") {
return {
handle_line(line) {
if (line === fence) {
this.done();
} else {
lines.push(line);
}
},
done() {
const text = wrap_tex(lines.join("\n"));
const placeholder = stash_func(text, true);
output_lines.push("", placeholder, "");
handler_stack.pop();
},
};
})();
}
if (lang === "spoiler") {
return {
handle_line(line) {
if (line === fence) {
this.done();
} else {
lines.push(line);
}
},
done() {
const text = wrap_spoiler(header, lines.join("\n"), stash_func);
output_lines.push("", text, "");
handler_stack.pop();
},
};
}
return {
handle_line(line) {
if (line === fence) {
this.done();
} else {
lines.push(line.trimEnd());
}
},
done() {
const text = wrap_code(lines.join("\n"), lang);
// insert safe HTML that is passed through the parsing
const placeholder = stash_func(text, true);
output_lines.push("", placeholder, "");
handler_stack.pop();
},
};
}
function default_hander() {