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:
Karl Stolley
2025-09-24 12:23:34 -04:00
committed by Tim Abbott
parent e217340b23
commit 716333c6be
2 changed files with 21 additions and 21 deletions

View File

@@ -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",
)) {