mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 22:43:42 +00:00
postprocess: Move list-processing to the top.
This is the most simple loop, so sticking it at the top keeps it from getting lost among the more complex processing that follows.
This commit is contained in:
@@ -12,6 +12,20 @@ export function postprocess_content(html: string): string {
|
||||
const template = inertDocument.createElement("template");
|
||||
template.innerHTML = html;
|
||||
|
||||
for (const ol of template.content.querySelectorAll("ol")) {
|
||||
const list_start = Number(ol.getAttribute("start") ?? 1);
|
||||
// We don't count the first item in the list, as it
|
||||
// will be identical to the start value
|
||||
const list_length = ol.children.length - 1;
|
||||
const max_list_counter = list_start + list_length;
|
||||
// We count the characters in the longest list counter,
|
||||
// and use that to offset the list accordingly in CSS
|
||||
const max_list_counter_string_length = max_list_counter.toString().length;
|
||||
ol.classList.add(`counter-length-${max_list_counter_string_length}`);
|
||||
// We subtract 1 from list_start, as `count 0` displays 1.
|
||||
ol.style.setProperty("counter-reset", `count ${list_start - 1}`);
|
||||
}
|
||||
|
||||
for (const elt of template.content.querySelectorAll("a")) {
|
||||
// Ensure that all external links have target="_blank"
|
||||
// rel="opener noreferrer". This ensures that external links
|
||||
@@ -211,20 +225,6 @@ export function postprocess_content(html: string): string {
|
||||
}
|
||||
}
|
||||
|
||||
for (const ol of template.content.querySelectorAll("ol")) {
|
||||
const list_start = Number(ol.getAttribute("start") ?? 1);
|
||||
// We don't count the first item in the list, as it
|
||||
// will be identical to the start value
|
||||
const list_length = ol.children.length - 1;
|
||||
const max_list_counter = list_start + list_length;
|
||||
// We count the characters in the longest list counter,
|
||||
// and use that to offset the list accordingly in CSS
|
||||
const max_list_counter_string_length = max_list_counter.toString().length;
|
||||
ol.classList.add(`counter-length-${max_list_counter_string_length}`);
|
||||
// We subtract 1 from list_start, as `count 0` displays 1.
|
||||
ol.style.setProperty("counter-reset", `count ${list_start - 1}`);
|
||||
}
|
||||
|
||||
for (const inline_img of template.content.querySelectorAll<HTMLImageElement>(
|
||||
".message-media-preview-image img",
|
||||
)) {
|
||||
|
||||
Reference in New Issue
Block a user